errmsg

decompiled_code:
void __fastcall errmsg(char *src)
{
size_t v1; // rax
char v2[1032]; // [rsp+0h] [rbp-408h] BYREF

strcpy(v2, progname);
v1 = strlen(v2);
strcpy(&v2[v1], ": ");
strncat(v2, src, 1022 - v1);
perror(v2);
}

canonical_decompiled_code:
void __fastcall func9(char *src)
{
size_t v1; // rax
char v2[1032]; // [rsp+0h] [rbp-408h] BYREF

strcpy(v2, progname);
v1 = strlen(v2);
strcpy(&v2[v1], ": ");
strncat(v2, src, 1022 - v1);
perror(v2);
}

original_code:
void errmsg(const char* str) {
    char buffer[1024];
    strcpy(buffer,progname);
    strcat(buffer, ": ");
    strncat(buffer, str, 1024-strlen(buffer));
    perror(buffer);
}

canonical_original_code:
void errmsg(char *str) {
    char buffer[1024];
    strcpy(buffer,progname);
    strcat(buffer, ": ");
    strncat(buffer, str, 1024-strlen(buffer));
    perror(buffer);
}

variable_types:
buffer
char [1024]


getDistance

variable_types: struct GpsPoint { double latitude; double longitude; }

variable_types: dLat double

variable_types: dLon double

variable_types: a double

variable_types: c double

return_type: double


getBearing

decompiled_code:
double __fastcall getBearing(double a1, double a2, double a3, double a4)
{
double result; // xmm0_8
double v5; // [rsp+8h] [rbp-40h]
double v6; // [rsp+10h] [rbp-38h]
double v7; // [rsp+18h] [rbp-30h]
double v8; // [rsp+20h] [rbp-28h]
double cosx; // [rsp+30h] [rbp-18h] BYREF
double sinx[2]; // [rsp+38h] [rbp-10h] BYREF

sincos(3.141592653589793 * (a4 - a2) / 180.0, sinx, &cosx);
v5 = cosx;
v6 = sinx[0];
sincos(a1 * 3.141592653589793 / 180.0, sinx, &cosx);
v8 = cosx;
v7 = sinx[0];
sincos(a3 * 3.141592653589793 / 180.0, sinx, &cosx);
result = atan2(cosx * v6, v8 * sinx[0] - v5 * (v7 * cosx)) * 180.0 / 3.141592653589793;
if ( result < 0.0 )
result = result + 360.0;
return result;
}

canonical_decompiled_code:
double __fastcall func1(double a1, double a2, double a3, double a4)
{
double result; // xmm0_8
double v5; // [rsp+8h] [rbp-40h]
double v6; // [rsp+10h] [rbp-38h]
double v7; // [rsp+18h] [rbp-30h]
double v8; // [rsp+20h] [rbp-28h]
double cosx; // [rsp+30h] [rbp-18h] BYREF
double sinx[2]; // [rsp+38h] [rbp-10h] BYREF

sincos(3.141592653589793 * (a4 - a2) / 180.0, sinx, &cosx);
v5 = cosx;
v6 = sinx[0];
sincos(a1 * 3.141592653589793 / 180.0, sinx, &cosx);
v8 = cosx;
v7 = sinx[0];
sincos(a3 * 3.141592653589793 / 180.0, sinx, &cosx);
result = atan2(cosx * v6, v8 * sinx[0] - v5 * (v7 * cosx)) * 180.0 / 3.141592653589793;
if ( result < 0.0 )
result = result + 360.0;
return result;
}

variable_types: x double

variable_types: y double

variable_types: bearing double

user_defined_types: struct GpsPoint { double latitude; double longitude; }


getHeading

decompiled_code:
double __fastcall getHeading(double a1, double a2, double a3, double a4)
{
return getBearing(a3, a4, a1, a2);
}

canonical_decompiled_code:
double __fastcall func2(double a1, double a2, double a3, double a4)
{
return func1(a3, a4, a1, a2);
}

original_code:
double getHeading( GpsPoint curr, GpsPoint prev )
{
 return getBearing( prev, curr );
}

canonical_original_code:
double getHeading(struct GpsPoint curr, struct GpsPoint prev)
{
 return getBearing( prev, curr );
}

variable_types:
prev
struct GpsPoint


destroyWaypointList

decompiled_code:
void __fastcall destroyWaypointList(void *ptr)
{
void *v1; // rbx
void *v2; // rdi

if ( ptr )
{
v1 = ptr;
do
{
v2 = v1;
v1 = (void *)*((_QWORD *)v1 + 2);
free(v2);
}
while ( v1 );
}
}

canonical_decompiled_code:
void __fastcall func4(void *ptr)
{
void *v1; // rbx
void *v2; // rdi

if ( ptr )
{
v1 = ptr;
do
{
v2 = v1;
v1 = (void *)*((_QWORD *)v1 + 2);
free(v2);
}
while ( v1 );
}
}

original_code:
void destroyWaypointList( WaypointListNode *head )
{
 while( head != ((void *)0) )
 {
  WaypointListNode *temp = head;
  head = head->next;
  free( temp );
 }
}

canonical_original_code:
void destroyWaypointList(struct WaypointListNode *head)
{
 while( head != ((void *)0) )
 {
  struct WaypointListNode *temp = head;
  head = head->next;
  free( temp );
 }
}

variable_types: struct WaypointListNode { struct GpsPoint { double latitude; double longitude; } waypoint; struct WaypointListNode *next; } *

return_type: void

user_defined_types: struct WaypointListNode { struct GpsPoint waypoint; struct WaypointListNode *next; }


createTcpClientConnection

decompiled_code:
__int64 __fastcall createTcpClientConnection(const char *a1, const char *a2)
{
struct addrinfo *v2; // rbx
int v3; // eax
unsigned int v4; // er12
struct addrinfo *pai; // [rsp+0h] [rbp-50h] BYREF
struct addrinfo req; // [rsp+8h] [rbp-48h] BYREF

*(_OWORD *)&req.ai_flags = 0LL;
*(_OWORD *)&req.ai_addrlen = 0LL;
req.ai_socktype = 1;
*(_OWORD *)&req.ai_canonname = 0LL;
if ( getaddrinfo(a1, a2, &req, &pai) )
{
v4 = -1;
fwrite("getaddrinfo() failure.\n", 1uLL, 0x17uLL, stderr);
}
else
{
v2 = pai;
if ( pai )
{
while ( 1 )
{
v3 = socket(v2->ai_family, v2->ai_socktype, v2->ai_protocol);
v4 = v3;
if ( v3 != -1 && connect(v3, v2->ai_addr, v2->ai_addrlen) != -1 )
break;
v2 = v2->ai_next;
if ( !v2 )
goto LABEL_8;
}
freeaddrinfo(pai);
}
else
{
LABEL_8:
v4 = -1;
fwrite("connect() failure.\n", 1uLL, 0x13uLL, stderr);
}
}
return v4;
}

canonical_decompiled_code:
__int64 __fastcall func1(const char *a1, const char *a2)
{
struct addrinfo *v2; // rbx
int v3; // eax
unsigned int v4; // er12
struct addrinfo *pai; // [rsp+0h] [rbp-50h] BYREF
struct addrinfo req; // [rsp+8h] [rbp-48h] BYREF

*(_OWORD *)&req.ai_flags = 0LL;
*(_OWORD *)&req.ai_addrlen = 0LL;
req.ai_socktype = 1;
*(_OWORD *)&req.ai_canonname = 0LL;
if ( getaddrinfo(a1, a2, &req, &pai) )
{
v4 = -1;
fwrite("getaddrinfo() failure.\n", 1uLL, 0x17uLL, stderr);
}
else
{
v2 = pai;
if ( pai )
{
while ( 1 )
{
v3 = socket(v2->ai_family, v2->ai_socktype, v2->ai_protocol);
v4 = v3;
if ( v3 != -1 && connect(v3, v2->ai_addr, v2->ai_addrlen) != -1 )
break;
v2 = v2->ai_next;
if ( !v2 )
goto LABEL_8;
}
freeaddrinfo(pai);
}
else
{
LABEL_8:
v4 = -1;
fwrite("connect() failure.\n", 1uLL, 0x13uLL, stderr);
}
}
return v4;
}

original_code:
int createTcpClientConnection( const char *hostname, const char *port )
{
 int sockfd;
 struct addrinfo hints;
 struct addrinfo *servinfo;
 memset( &hints, 0, sizeof( hints ) );
 hints.ai_family = 0;
 hints.ai_socktype = SOCK_STREAM;
 if( getaddrinfo( hostname, port, &hints, &servinfo ) != 0 )
 {
  fprintf( stderr, "getaddrinfo() failure.\n" );
  return -1;
 }
 struct addrinfo *p = ((void *)0);
 for( p = servinfo; p != ((void *)0); p = p->ai_next )
 {
  sockfd = socket( p->ai_family, p->ai_socktype, p->ai_protocol );
  if( sockfd == -1 )
  {
   continue;
  }
  if( connect( sockfd, p->ai_addr, p->ai_addrlen ) == -1 )
  {
   continue;
  }
  break;
 }
 if( p == ((void *)0) )
 {
  fprintf( stderr, "connect() failure.\n" );
  return -1;
 }
 freeaddrinfo( servinfo );
 return sockfd;
}

canonical_original_code:
int createTcpClientConnection(char *hostname, char *port)
{
 int sockfd;
 struct addrinfo hints;
 struct addrinfo *servinfo;
 memset( &hints, 0, sizeof( hints ) );
 hints.ai_family = 0;
 hints.ai_socktype = SOCK_STREAM;
 if( getaddrinfo( hostname, port, &hints, &servinfo ) != 0 )
 {
  fprintf( stderr, "getaddrinfo() failure.\n" );
  return -1;
 }
 struct addrinfo *p = ((void *)0);
 for( p = servinfo; p != ((void *)0); p = p->ai_next )
 {
  sockfd = socket( p->ai_family, p->ai_socktype, p->ai_protocol );
  if( sockfd == -1 )
  {
   continue;
  }
  if( connect( sockfd, p->ai_addr, p->ai_addrlen ) == -1 )
  {
   continue;
  }
  break;
 }
 if( p == ((void *)0) )
 {
  fprintf( stderr, "connect() failure.\n" );
  return -1;
 }
 freeaddrinfo( servinfo );
 return sockfd;
}

variable_types:
hostname
char *

variable_types:
port
char *

variable_types: sockfd int

variable_types: struct addrinfo { int ai_flags; int ai_family; int ai_socktype; int ai_protocol; unsigned int ai_addrlen; struct sockaddr { unsigned short sa_family; char sa_data[14]; } *ai_addr; char *ai_canonname; struct addrinfo *ai_next; } *

return_type: int

user_defined_types: struct addrinfo { int ai_flags; int ai_family; int ai_socktype; int ai_protocol; unsigned int ai_addrlen; struct sockaddr *ai_addr; char *ai_canonname; struct addrinfo *ai_next; }


createUdpClientConnection

decompiled_code:
__int64 __fastcall createUdpClientConnection(char *cp, char *nptr, __int64 a3)
{
unsigned int v4; // er12
__int16 v5; // ax
int *v7; // rax
int *v8; // rax

v4 = socket(2, 2, 17);
if ( v4 == -1 )
{
v7 = _errno_location();
fprintf(stderr, "socket() failure, errno = %d.\n", (unsigned int)*v7);
}
else
{
*(_OWORD *)a3 = 0LL;
*(_WORD *)a3 = 2;
v5 = atoi(nptr);
*(_WORD *)(a3 + 2) = _bswap_16(v5);
if ( !inet_aton(cp, (struct in_addr *)(a3 + 4)) )
{
v8 = _errno_location();
v4 = -1;
fprintf(stderr, "inet_aton() failure, errno = %d.\n", (unsigned int)*v8);
}
}
return v4;
}

canonical_decompiled_code:
__int64 __fastcall func2(char *cp, char *nptr, __int64 a3)
{
unsigned int v4; // er12
__int16 v5; // ax
int *v7; // rax
int *v8; // rax

v4 = socket(2, 2, 17);
if ( v4 == -1 )
{
v7 = _errno_location();
fprintf(stderr, "socket() failure, errno = %d.\n", (unsigned int)*v7);
}
else
{
*(_OWORD *)a3 = 0LL;
*(_WORD *)a3 = 2;
v5 = atoi(nptr);
*(_WORD *)(a3 + 2) = func0(v5);
if ( !inet_aton(cp, (struct in_addr *)(a3 + 4)) )
{
v8 = _errno_location();
v4 = -1;
fprintf(stderr, "inet_aton() failure, errno = %d.\n", (unsigned int)*v8);
}
}
return v4;
}

original_code:
int createUdpClientConnection( const char *hostname, const char *port, struct sockaddr_in *theiraddr )
{
 int sockfd = socket( 2, SOCK_DGRAM, IPPROTO_UDP );
 if( sockfd == -1 )
 {
  fprintf( stderr, "socket() failure, errno = %d.\n", (*__errno_location ()) );
  return -1;
 }
 memset( (char *)theiraddr, 0, sizeof( *theiraddr ) );
 theiraddr->sin_family = 2;
 theiraddr->sin_port = htons( atoi( port ) );
 if( inet_aton( hostname, &theiraddr->sin_addr ) == 0 )
 {
  fprintf( stderr, "inet_aton() failure, errno = %d.\n", (*__errno_location ()) );
  return -1;
 }
 return sockfd;
}

canonical_original_code:
int createUdpClientConnection(char *hostname, char *port, struct sockaddr_in *theiraddr)
{
 int sockfd = socket( 2, SOCK_DGRAM, IPPROTO_UDP );
 if( sockfd == -1 )
 {
  fprintf( stderr, "socket() failure, errno = %d.\n", (*__errno_location ()) );
  return -1;
 }
 memset( (char *)theiraddr, 0, sizeof( *theiraddr ) );
 theiraddr->sin_family = 2;
 theiraddr->sin_port = htons( atoi( port ) );
 if( inet_aton( hostname, &theiraddr->sin_addr ) == 0 )
 {
  fprintf( stderr, "inet_aton() failure, errno = %d.\n", (*__errno_location ()) );
  return -1;
 }
 return sockfd;
}

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]; }


sendCommand

decompiled_code:
ssize_t __fastcall sendCommand(void *buf)
{
ssize_t result; // rax

result = sendto(droneCmdSock, buf, 0x50uLL, 0, &droneCmdAddr, 0x10u);
if ( result < 0 )
{
fwrite("Error sending command to drone.\n", 1uLL, 0x20uLL, stderr);
exit(1);
}
return result;
}

canonical_decompiled_code:
ssize_t __fastcall func0(void *buf)
{
ssize_t result; // rax

result = sendto(droneCmdSock, buf, 0x50uLL, 0, &droneCmdAddr, 0x10u);
if ( result < 0 )
{
fwrite("Error sending command to drone.\n", 1uLL, 0x20uLL, stderr);
exit(1);
}
return result;
}

original_code:
void sendCommand( const char *cmd )
{
 if( sendto( droneCmdSock, cmd, 80, 0, (struct sockaddr *)&droneCmdAddr, sizeof( droneCmdAddr ) ) < 0 )
 {
  fprintf( stderr, "Error sending command to drone.\n" );
  exit( 1 );
 }
}

canonical_original_code:
void sendCommand(char *cmd)
{
 if( sendto( droneCmdSock, cmd, 80, 0, (struct sockaddr *)&droneCmdAddr, sizeof( droneCmdAddr ) ) < 0 )
 {
  fprintf( stderr, "Error sending command to drone.\n" );
  exit( 1 );
 }
}

variable_types:
cmd
char *

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


droneTakeOff

decompiled_code:
ssize_t droneTakeOff()
{
__int64 v0; // rcx
char v2[88]; // [rsp+0h] [rbp-58h] BYREF

v0 = (unsigned int)droneSeqNum++;
snprintf(v2, 0x50uLL, "AT*REF=%u,290718208\r", v0);
return sendCommand(v2);
}

canonical_decompiled_code:
ssize_t func1()
{
__int64 v0; // rcx
char v2[88]; // [rsp+0h] [rbp-58h] BYREF

v0 = (unsigned int)droneSeqNum++;
snprintf(v2, 0x50uLL, "AT*REF=%u,290718208\r", v0);
return func0(v2);
}

original_code:
void droneTakeOff()
{
 char cmd[80];
 snprintf( cmd, 80, "AT*REF=%u,290718208\r", droneSeqNum++ );
 sendCommand( cmd );
}

variable_types:
cmd
char [80]


droneLand

decompiled_code:
ssize_t droneLand()
{
__int64 v0; // rcx
char v2[88]; // [rsp+0h] [rbp-58h] BYREF

v0 = (unsigned int)droneSeqNum++;
snprintf(v2, 0x50uLL, "AT*REF=%u,290717696\r", v0);
return sendCommand(v2);
}

canonical_decompiled_code:
ssize_t func2()
{
__int64 v0; // rcx
char v2[88]; // [rsp+0h] [rbp-58h] BYREF

v0 = (unsigned int)droneSeqNum++;
snprintf(v2, 0x50uLL, "AT*REF=%u,290717696\r", v0);
return func0(v2);
}

original_code:
void droneLand()
{
 char cmd[80];
 snprintf( cmd, 80, "AT*REF=%u,290717696\r", droneSeqNum++ );
 sendCommand( cmd );
}


droneHover

decompiled_code:
ssize_t droneHover()
{
__int64 v0; // rcx
char v2[88]; // [rsp+0h] [rbp-58h] BYREF

v0 = (unsigned int)droneSeqNum++;
snprintf(v2, 0x50uLL, "AT*PCMD=%u,1,0,0,0,0\r", v0);
return sendCommand(v2);
}

canonical_decompiled_code:
ssize_t func3()
{
__int64 v0; // rcx
char v2[88]; // [rsp+0h] [rbp-58h] BYREF

v0 = (unsigned int)droneSeqNum++;
snprintf(v2, 0x50uLL, "AT*PCMD=%u,1,0,0,0,0\r", v0);
return func0(v2);
}

original_code:
void droneHover()
{
 char cmd[80];
 snprintf( cmd, 80, "AT*PCMD=%u,1,0,0,0,0\r", droneSeqNum++ );
 sendCommand( cmd );
}


droneUp

decompiled_code:
ssize_t droneUp()
{
__int64 v0; // rcx
char v2[88]; // [rsp+0h] [rbp-58h] BYREF

v0 = (unsigned int)droneSeqNum++;
snprintf(v2, 0x50uLL, "AT*PCMD=%u,1,0,0,1045220557,0\r", v0);
return sendCommand(v2);
}

canonical_decompiled_code:
ssize_t func4()
{
__int64 v0; // rcx
char v2[88]; // [rsp+0h] [rbp-58h] BYREF

v0 = (unsigned int)droneSeqNum++;
snprintf(v2, 0x50uLL, "AT*PCMD=%u,1,0,0,1045220557,0\r", v0);
return func0(v2);
}

original_code:
void droneUp()
{
 char cmd[80];
 snprintf( cmd, 80, "AT*PCMD=%u,1,0,0,1045220557,0\r", droneSeqNum++ );
 sendCommand( cmd );
}


droneDown

decompiled_code:
ssize_t droneDown()
{
__int64 v0; // rcx
char v2[88]; // [rsp+0h] [rbp-58h] BYREF

v0 = (unsigned int)droneSeqNum++;
snprintf(v2, 0x50uLL, "AT*PCMD=%u,1,0,0,-1102263091,0\r", v0);
return sendCommand(v2);
}

canonical_decompiled_code:
ssize_t func5()
{
__int64 v0; // rcx
char v2[88]; // [rsp+0h] [rbp-58h] BYREF

v0 = (unsigned int)droneSeqNum++;
snprintf(v2, 0x50uLL, "AT*PCMD=%u,1,0,0,-1102263091,0\r", v0);
return func0(v2);
}

original_code:
void droneDown()
{
 char cmd[80];
 snprintf( cmd, 80, "AT*PCMD=%u,1,0,0,-1102263091,0\r", droneSeqNum++ );
 sendCommand( cmd );
}


droneForward

decompiled_code:
ssize_t droneForward()
{
__int64 v0; // rcx
char v2[88]; // [rsp+0h] [rbp-58h] BYREF

v0 = (unsigned int)droneSeqNum++;
snprintf(v2, 0x50uLL, "AT*PCMD=%u,1,0,-1102263091,0,0\r", v0);
return sendCommand(v2);
}

canonical_decompiled_code:
ssize_t func6()
{
__int64 v0; // rcx
char v2[88]; // [rsp+0h] [rbp-58h] BYREF

v0 = (unsigned int)droneSeqNum++;
snprintf(v2, 0x50uLL, "AT*PCMD=%u,1,0,-1102263091,0,0\r", v0);
return func0(v2);
}

original_code:
void droneForward()
{
 char cmd[80];
 snprintf( cmd, 80, "AT*PCMD=%u,1,0,-1102263091,0,0\r", droneSeqNum++ );
 sendCommand( cmd );
}


droneBack

decompiled_code:
ssize_t droneBack()
{
__int64 v0; // rcx
char v2[88]; // [rsp+0h] [rbp-58h] BYREF

v0 = (unsigned int)droneSeqNum++;
snprintf(v2, 0x50uLL, "AT*PCMD=%u,1,0,1045220557,0,0\r", v0);
return sendCommand(v2);
}

canonical_decompiled_code:
ssize_t func7()
{
__int64 v0; // rcx
char v2[88]; // [rsp+0h] [rbp-58h] BYREF

v0 = (unsigned int)droneSeqNum++;
snprintf(v2, 0x50uLL, "AT*PCMD=%u,1,0,1045220557,0,0\r", v0);
return func0(v2);
}

original_code:
void droneBack()
{
 char cmd[80];
 snprintf( cmd, 80, "AT*PCMD=%u,1,0,1045220557,0,0\r", droneSeqNum++ );
 sendCommand( cmd );
}


droneLeft

decompiled_code:
ssize_t droneLeft()
{
__int64 v0; // rcx
char v2[88]; // [rsp+0h] [rbp-58h] BYREF

v0 = (unsigned int)droneSeqNum++;
snprintf(v2, 0x50uLL, "AT*PCMD=%u,1,-1102263091,0,0,0\r", v0);
return sendCommand(v2);
}

canonical_decompiled_code:
ssize_t func8()
{
__int64 v0; // rcx
char v2[88]; // [rsp+0h] [rbp-58h] BYREF

v0 = (unsigned int)droneSeqNum++;
snprintf(v2, 0x50uLL, "AT*PCMD=%u,1,-1102263091,0,0,0\r", v0);
return func0(v2);
}

original_code:
void droneLeft()
{
 char cmd[80];
 snprintf( cmd, 80, "AT*PCMD=%u,1,-1102263091,0,0,0\r", droneSeqNum++ );
 sendCommand( cmd );
}


droneRight

decompiled_code:
ssize_t droneRight()
{
__int64 v0; // rcx
char v2[88]; // [rsp+0h] [rbp-58h] BYREF

v0 = (unsigned int)droneSeqNum++;
snprintf(v2, 0x50uLL, "AT*PCMD=%u,1,1045220557,0,0,0\r", v0);
return sendCommand(v2);
}

canonical_decompiled_code:
ssize_t func9()
{
__int64 v0; // rcx
char v2[88]; // [rsp+0h] [rbp-58h] BYREF

v0 = (unsigned int)droneSeqNum++;
snprintf(v2, 0x50uLL, "AT*PCMD=%u,1,1045220557,0,0,0\r", v0);
return func0(v2);
}

original_code:
void droneRight()
{
 char cmd[80];
 snprintf( cmd, 80, "AT*PCMD=%u,1,1045220557,0,0,0\r", droneSeqNum++ );
 sendCommand( cmd );
}


droneRotateLeft

decompiled_code:
ssize_t droneRotateLeft()
{
__int64 v0; // rcx
char v2[88]; // [rsp+0h] [rbp-58h] BYREF

v0 = (unsigned int)droneSeqNum++;
snprintf(v2, 0x50uLL, "AT*PCMD=%u,1,0,0,0,-1085485875\r", v0);
return sendCommand(v2);
}

canonical_decompiled_code:
ssize_t func10()
{
__int64 v0; // rcx
char v2[88]; // [rsp+0h] [rbp-58h] BYREF

v0 = (unsigned int)droneSeqNum++;
snprintf(v2, 0x50uLL, "AT*PCMD=%u,1,0,0,0,-1085485875\r", v0);
return func0(v2);
}

original_code:
void droneRotateLeft()
{
 char cmd[80];
 snprintf( cmd, 80, "AT*PCMD=%u,1,0,0,0,-1085485875\r", droneSeqNum++ );
 sendCommand( cmd );
}


droneRotateRight

decompiled_code:
ssize_t droneRotateRight()
{
__int64 v0; // rcx
char v2[88]; // [rsp+0h] [rbp-58h] BYREF

v0 = (unsigned int)droneSeqNum++;
snprintf(v2, 0x50uLL, "AT*PCMD=%u,1,0,0,0,1061997773\r", v0);
return sendCommand(v2);
}

canonical_decompiled_code:
ssize_t func11()
{
__int64 v0; // rcx
char v2[88]; // [rsp+0h] [rbp-58h] BYREF

v0 = (unsigned int)droneSeqNum++;
snprintf(v2, 0x50uLL, "AT*PCMD=%u,1,0,0,0,1061997773\r", v0);
return func0(v2);
}

original_code:
void droneRotateRight()
{
 char cmd[80];
 snprintf( cmd, 80, "AT*PCMD=%u,1,0,0,0,1061997773\r", droneSeqNum++ );
 sendCommand( cmd );
}


navdataInit

decompiled_code:
ssize_t navdataInit()
{
__int64 v0; // rcx
__int64 v1; // rcx
__int64 v2; // rcx
char v4[88]; // [rsp+0h] [rbp-58h] BYREF

v0 = (unsigned int)droneSeqNum++;
snprintf(v4, 0x50uLL, "AT*CONFIG=%d,\"general:navdata_demo\",\"TRUE\"\r", v0);
sendCommand(v4);
v1 = (unsigned int)droneSeqNum++;
snprintf(v4, 0x50uLL, "AT*CTRL=%d,0\r", v1);
sendCommand(v4);
v2 = (unsigned int)droneSeqNum++;
snprintf(v4, 0x50uLL, "AT*FTRIM=%d,\r", v2);
return sendCommand(v4);
}

canonical_decompiled_code:
ssize_t func12()
{
__int64 v0; // rcx
__int64 v1; // rcx
__int64 v2; // rcx
char v4[88]; // [rsp+0h] [rbp-58h] BYREF

v0 = (unsigned int)droneSeqNum++;
snprintf(v4, 0x50uLL, "AT*CONFIG=%d,\"general:navdata_demo\",\"TRUE\"\r", v0);
func0(v4);
v1 = (unsigned int)droneSeqNum++;
snprintf(v4, 0x50uLL, "AT*CTRL=%d,0\r", v1);
func0(v4);
v2 = (unsigned int)droneSeqNum++;
snprintf(v4, 0x50uLL, "AT*FTRIM=%d,\r", v2);
return func0(v4);
}

original_code:
void navdataInit()
{
  char cmd[80];
  snprintf( cmd, 80, "AT*CONFIG=%d,\"general:navdata_demo\",\"TRUE\"\r", droneSeqNum++ );
  sendCommand( cmd );
  snprintf( cmd, 80, "AT*CTRL=%d,0\r", droneSeqNum++ );
  sendCommand( cmd );
  snprintf( cmd, 80, "AT*FTRIM=%d,\r", droneSeqNum++ );
  sendCommand( cmd );
}


navdataKeepAlive

decompiled_code:
ssize_t navdataKeepAlive()
{
__int64 v0; // rcx
char v2[88]; // [rsp+0h] [rbp-58h] BYREF

v0 = (unsigned int)droneSeqNum++;
snprintf(v2, 0x50uLL, "AT*COMWDG=%d\r", v0);
return sendCommand(v2);
}

canonical_decompiled_code:
ssize_t func13()
{
__int64 v0; // rcx
char v2[88]; // [rsp+0h] [rbp-58h] BYREF

v0 = (unsigned int)droneSeqNum++;
snprintf(v2, 0x50uLL, "AT*COMWDG=%d\r", v0);
return func0(v2);
}

original_code:
void navdataKeepAlive()
{
  char cmd[80];
  snprintf( cmd, 80, "AT*COMWDG=%d\r", droneSeqNum++ );
  sendCommand( cmd );
}


createNavdataSocket

decompiled_code:
int createNavdataSocket()
{
struct hostent *v0; // rbx
__int16 v1; // ax
size_t v2; // rdx
int v3; // edx
int v4; // eax
int result; // eax

v0 = gethostbyname("192.168.1.1");
droneAddr_navdata.sa_family = v0->h_addrtype;
v1 = _bswap_16(5554);
v2 = v0->h_length;
*(_WORD *)droneAddr_navdata.sa_data = v1;
memcpy((void *)(unsigned int)((_DWORD)&droneAddr_navdata + 4), *(const void **)v0->h_addr_list, v2);
clientAddr_navdata.sa_family = 2;
*(_DWORD *)&clientAddr_navdata.sa_data[2] = _bswap_32_constprop_0(0LL, 2LL, 0LL);
*(_WORD *)clientAddr_navdata.sa_data = _bswap_16(0);
v4 = socket(2, 2, v3);
navDataSock = v4;
if ( v4 < 0 )
{
printf("%s: cannot open socket \n", *(const char **)v0->h_addr_list);
exit(1);
}
result = bind(v4, &clientAddr_navdata, 0x10u);
if ( result < 0 )
{
printf("%d: cannot bind port\n", 5554LL);
exit(1);
}
return result;
}

canonical_decompiled_code:
int func2()
{
struct hostent *v0; // rbx
__int16 v1; // ax
size_t v2; // rdx
int v3; // edx
int v4; // eax
int result; // eax

v0 = gethostbyname("192.168.1.1");
droneAddr_navdata.sa_family = v0->h_addrtype;
v1 = func0(5554);
v2 = v0->h_length;
*(_WORD *)droneAddr_navdata.sa_data = v1;
memcpy((void *)(unsigned int)((_DWORD)&droneAddr_navdata + 4), *(const void **)v0->h_addr_list, v2);
clientAddr_navdata.sa_family = 2;
*(_DWORD *)&clientAddr_navdata.sa_data[2] = func1(0LL, 2LL, 0LL);
*(_WORD *)clientAddr_navdata.sa_data = func0(0);
v4 = socket(2, 2, v3);
navDataSock = v4;
if ( v4 < 0 )
{
printf("%s: cannot open socket \n", *(const char **)v0->h_addr_list);
exit(1);
}
result = bind(v4, &clientAddr_navdata, 0x10u);
if ( result < 0 )
{
printf("%d: cannot bind port\n", 5554LL);
exit(1);
}
return result;
}

original_code:
void createNavdataSocket() {
  struct hostent *h;
  h = gethostbyname("192.168.1.1");
  droneAddr_navdata.sin_family = h->h_addrtype;
  droneAddr_navdata.sin_port = htons(5554);
  memcpy((char *) &(droneAddr_navdata.sin_addr.s_addr), h->h_addr_list[0], h->h_length);
  clientAddr_navdata.sin_family = 2;
  clientAddr_navdata.sin_addr.s_addr = htonl(((in_addr_t) 0x00000000));
  clientAddr_navdata.sin_port = htons(0);
  navDataSock = socket(2,SOCK_DGRAM,0);
  if(navDataSock<0) {
    printf("%s: cannot open socket \n", h->h_addr_list[0]);
    exit(1);
  }
  if(bind(navDataSock, (struct sockaddr *) &clientAddr_navdata, sizeof(clientAddr_navdata))<0) {
    printf("%d: cannot bind port\n", 5554);
    exit(1);
  }
}

canonical_original_code:
void createNavdataSocket() {
  struct hostent *h;
  h = gethostbyname("192.168.1.1");
  droneAddr_navdata.sin_family = h->h_addrtype;
  droneAddr_navdata.sin_port = htons(5554);
  memcpy((char *) &(droneAddr_navdata.sin_addr.s_addr), h->h_addr_list[0], h->h_length);
  clientAddr_navdata.sin_family = 2;
  clientAddr_navdata.sin_addr.s_addr = htonl(((unsigned int) 0x00000000));
  clientAddr_navdata.sin_port = htons(0);
  navDataSock = socket(2,SOCK_DGRAM,0);
  if(navDataSock<0) {
    printf("%s: cannot open socket \n", h->h_addr_list[0]);
    exit(1);
  }
  if(bind(navDataSock, (struct sockaddr *) &clientAddr_navdata, sizeof(clientAddr_navdata))<0) {
    printf("%d: cannot bind port\n", 5554);
    exit(1);
  }
}

variable_types: struct hostent { char *h_name; char **h_aliases; int h_addrtype; int h_length; char **h_addr_list; } *


sendNavData

decompiled_code:
ssize_t __fastcall sendNavData(void *buf)
{
size_t v1; // rax
ssize_t result; // rax

v1 = strlen((const char *)buf);
result = sendto(navDataSock, buf, v1 + 1, 0, &droneAddr_navdata, 0x10u);
if ( result < 0 )
{
fwrite("Error sending navdata to drone.\n", 1uLL, 0x20uLL, stderr);
exit(1);
}
return result;
}

canonical_decompiled_code:
ssize_t __fastcall func3(void *buf)
{
size_t v1; // rax
ssize_t result; // rax

v1 = strlen((const char *)buf);
result = sendto(navDataSock, buf, v1 + 1, 0, &droneAddr_navdata, 0x10u);
if ( result < 0 )
{
fwrite("Error sending navdata to drone.\n", 1uLL, 0x20uLL, stderr);
exit(1);
}
return result;
}

original_code:
void sendNavData( char *cmd )
{
 if( sendto( navDataSock, cmd, strlen(cmd)+1, 0, (struct sockaddr *) &droneAddr_navdata, sizeof( droneAddr_navdata ) ) < 0 )
 {
  fprintf( stderr, "Error sending navdata to drone.\n" );
  exit( 1 );
 }
}

canonical_original_code:
void sendNavData(char *cmd)
{
 if( sendto( navDataSock, cmd, strlen(cmd)+1, 0, (struct sockaddr *) &droneAddr_navdata, sizeof( droneAddr_navdata ) ) < 0 )
 {
  fprintf( stderr, "Error sending navdata to drone.\n" );
  exit( 1 );
 }
}


tickleNavData

decompiled_code:
ssize_t tickleNavData()
{
return sendNavData(&unk_1E1);
}

canonical_decompiled_code:
ssize_t func4()
{
return func3(&unk_1E1);
}

original_code:
void tickleNavData()
{
  sendNavData ("\x01\x00");
}


usage

repo: EPCCed/epcc-openacc-benchmarks

decompiled_code:
int __fastcall usage(const char **a1)
{
return printf(
"Usage: %s \n\t--reps <repetitions> (default %d)\n\t--datasize <datasize> (default %d bytes)\n",
*a1,
10LL,
0x100000LL);
}

canonical_decompiled_code:
int __fastcall func0(const char **a1)
{
return printf(
"Usage: %s \n\t--reps <repetitions> (default %d)\n\t--datasize <datasize> (default %d bytes)\n",
*a1,
10LL,
0x100000LL);
}

original_code:
void usage(char *argv[]) {
  printf("Usage: %s \n"
         "\t--reps <repetitions> (default %d)\n"
         "\t--datasize <datasize> (default %d bytes)\n",
         argv[0],
         10, 1048576);
}

variable_types:
argv
char *[]


decompiled_code:
void __fastcall parse_args(int a1, const char **a2)
{
__int64 v2; // rbx
const char *v3; // r14
const char *v4; // r8
const char *v5; // r14

if ( a1 > 1 )
{
v2 = 1LL;
do
{
v4 = a2[v2];
if ( !strcmp(v4, "--reps") )
{
v3 = a2[(unsigned int)(v2 + 1)];
reps = atoi(v3);
if ( !reps )
{
printf("Invalid integer:--reps: %s\n", v3);
usage(a2);
exit(1);
}
}
else
{
if ( strcmp(a2[v2], "--datasize") )
{
if ( *v4 == 45 && v4[1] == 104 && !v4[2] )
{
usage(a2);
exit(0);
}
printf("Invalid parameters: %s\n", a2[v2]);
usage(a2);
exit(1);
}
v5 = a2[(unsigned int)(v2 + 1)];
datasize = atoi(v5);
if ( !datasize )
{
printf("Invalid integer:--datasize: %s\n", v5);
usage(a2);
exit(1);
}
}
v2 += 2LL;
}
while ( v2 != 2LL * ((unsigned int)(a1 - 2) >> 1) + 3 );
}
}

canonical_decompiled_code:
void __fastcall func1(int a1, const char **a2)
{
__int64 v2; // rbx
const char *v3; // r14
const char *v4; // r8
const char *v5; // r14

if ( a1 > 1 )
{
v2 = 1LL;
do
{
v4 = a2[v2];
if ( !strcmp(v4, "--reps") )
{
v3 = a2[(unsigned int)(v2 + 1)];
reps = atoi(v3);
if ( !reps )
{
printf("Invalid integer:--reps: %s\n", v3);
func0(a2);
exit(1);
}
}
else
{
if ( strcmp(a2[v2], "--datasize") )
{
if ( *v4 == 45 && v4[1] == 104 && !v4[2] )
{
func0(a2);
exit(0);
}
printf("Invalid parameters: %s\n", a2[v2]);
func0(a2);
exit(1);
}
v5 = a2[(unsigned int)(v2 + 1)];
datasize = atoi(v5);
if ( !datasize )
{
printf("Invalid integer:--datasize: %s\n", v5);
func0(a2);
exit(1);
}
}
v2 += 2LL;
}
while ( v2 != 2LL * ((unsigned int)(a1 - 2) >> 1) + 3 );
}
}

original_code:
void parse_args(int argc, char *argv[]) {
  int arg;
  for (arg = 1; arg < argc; arg++) {
    if (strcmp(argv[arg], "--reps") == 0) {
      reps = atoi(argv[++arg]);
      if (reps == 0) {
        printf("Invalid integer:--reps: %s\n", argv[arg]);
        usage(argv);
        exit(1);
      }
    } else if (strcmp(argv[arg], "--datasize") == 0) {
      datasize = atoi(argv[++arg]);
      if (datasize == 0) {
        printf("Invalid integer:--datasize: %s\n", argv[arg]);
        usage(argv);
        exit(1);
      }
    } else if (strcmp(argv[arg], "-h") == 0) {
      usage(argv);
      exit(0);
    } else {
      printf("Invalid parameters: %s\n", argv[arg]);
      usage(argv);
      exit(1);
    }
  }
}

variable_types: argc int

variable_types: arg int


stats

original_code:
void stats(double *mtp, double *sdp) {
  double meantime, totaltime, sumsq, mintime, maxtime, sd;
  int i, good_reps;
  mintime = 1.0e10;
  maxtime = 0.;
  totaltime = 0.;
  good_reps = 0;
  for (i = 0; i < reps; i++) {
    if (times[i] != 0){
      mintime = (mintime < times[i]) ? mintime : times[i];
      maxtime = (maxtime > times[i]) ? maxtime : times[i];
      totaltime += times[i];
      good_reps++;
    }
  }
  meantime = totaltime / good_reps;
  sumsq = 0;
  for (i = 0; i < reps; i++) {
    if (times[i] != 0){
      sumsq += (times[i] - meantime) * (times[i] - meantime);
    }
  }
  sd = sqrt(sumsq / good_reps);
  *mtp = meantime;
  *sdp = sd;
}

canonical_original_code:
void stats(double *mtp, double *sdp) {
  double meantime; double totaltime; double sumsq; double mintime; double maxtime; double sd;
  int i; int good_reps;
  mintime = 1.0e10;
  maxtime = 0.;
  totaltime = 0.;
  good_reps = 0;
  for (i = 0; i < reps; i++) {
    if (times[i] != 0){
      mintime = (mintime < times[i]) ? mintime : times[i];
      maxtime = (maxtime > times[i]) ? maxtime : times[i];
      totaltime += times[i];
      good_reps++;
    }
  }
  meantime = totaltime / good_reps;
  sumsq = 0;
  for (i = 0; i < reps; i++) {
    if (times[i] != 0){
      sumsq += (times[i] - meantime) * (times[i] - meantime);
    }
  }
  sd = sqrt(sumsq / good_reps);
  *mtp = meantime;
  *sdp = sd;
}

variable_types:
mtp
double *

variable_types:
sdp
double *

variable_types: meantime double

variable_types: totaltime double

variable_types: sumsq double

variable_types: mintime double

variable_types: maxtime double

variable_types: sd double

variable_types: i int


decompiled_code:
int __fastcall print_results(const char *a1, double a2, double a3)
{
char v4[40]; // [rsp+0h] [rbp-28h] BYREF

strcpy(v4, "COMPILER");
return printf("%s %s %d %f %f\n", v4, a1, (unsigned int)datasize, a2 * 1000000.0, a3 * 1.96 * 1000000.0);
}

canonical_decompiled_code:
int __fastcall func3(const char *a1, double a2, double a3)
{
char v4[40]; // [rsp+0h] [rbp-28h] BYREF

strcpy(v4, "COMPILER");
return printf("%s %s %d %f %f\n", v4, a1, (unsigned int)datasize, a2 * 1000000.0, a3 * 1.96 * 1000000.0);
}

original_code:
void print_results(char *name, double testtime, double testsd) {
  char compiler[20];
  sprintf(compiler, "COMPILER");
  printf("%s %s %d %f %f\n", compiler, name, datasize, testtime*1e6, 1.96*testsd*1e6);
}

variable_types:
name
char *

variable_types: testtime double

variable_types: testsd double

variable_types:
compiler
char [20]


init

decompiled_code:
void *__fastcall init(int a1, const char **a2)
{
size_t v2; // rdi
void *result; // rax

parse_args(a1, a2);
if ( reps == -1 )
{
reps = 10;
v2 = 80LL;
}
else
{
v2 = 8LL * reps;
}
if ( datasize == -1 )
datasize = 0x100000;
result = malloc(v2);
times = result;
return result;
}

canonical_decompiled_code:
void *__fastcall func4(int a1, const char **a2)
{
size_t v2; // rdi
void *result; // rax

func1(a1, a2);
if ( reps == -1 )
{
reps = 10;
v2 = 80LL;
}
else
{
v2 = 8LL * reps;
}
if ( datasize == -1 )
datasize = 0x100000;
result = malloc(v2);
times = result;
return result;
}

original_code:
void init(int argc, char **argv)
{
  parse_args(argc, argv);
  if (reps == -1) {
    reps = 10;
  }
  if (datasize == (unsigned int)-1) {
    datasize = 1048576;
  }
  times = (double *)malloc((reps) * sizeof(double));
}

variable_types:
argv
char **


finalise

decompiled_code:
void finalise()
{
free(times);
}

canonical_decompiled_code:
void func5()
{
free(times);
}

original_code:
void finalise(void) {
  free(times);
}

canonical_original_code:
void finalise() {
  free(times);
}


benchmark

decompiled_code:
int __fastcall benchmark(const char *a1, double (*a2)(void))
{
__int64 i; // rbx
double v3; // xmm0_8
__int64 v4; // rbp
bool v5; // cc

for ( i = 0LL; reps > (int)i; ++i )
{
while ( 1 )
{
v3 = a2();
v4 = 8 * i;
if ( v3 != -10000.0 )
break;
++i;
printf("Memory allocation failure in %s\n", a1);
v5 = reps <= (int)i;
*(_QWORD *)((char *)times + v4) = 0LL;
if ( v5 )
goto LABEL_8;
}
if ( v3 == -11000.0 )
{
printf("CPU/GPU mismatch in %s\n", a1);
*((_QWORD *)times + i) = 0LL;
}
else
{
*((double *)times + i) = v3;
}
}
LABEL_8:
stats((double *)&testtime, (double *)&testsd);
return print_results(a1, *(double *)&testtime, *(double *)&testsd);
}

canonical_decompiled_code:
int __fastcall func6(const char *a1, double (*a2)(void))
{
__int64 i; // rbx
double v3; // xmm0_8
__int64 v4; // rbp
bool v5; // cc

for ( i = 0LL; reps > (int)i; ++i )
{
while ( 1 )
{
v3 = a2();
v4 = 8 * i;
if ( v3 != -10000.0 )
break;
++i;
printf("Memory allocation failure in %s\n", a1);
v5 = reps <= (int)i;
*(_QWORD *)((char *)times + v4) = 0LL;
if ( v5 )
goto LABEL_8;
}
if ( v3 == -11000.0 )
{
printf("CPU/GPU mismatch in %s\n", a1);
*((_QWORD *)times + i) = 0LL;
}
else
{
*((double *)times + i) = v3;
}
}
LABEL_8:
func2((double *)&testtime, (double *)&testsd);
return func3(a1, *(double *)&testtime, *(double *)&testsd);
}

original_code:
void benchmark(char *name, double (*test)(void))
{
  int i = 0;
  double tmp = 0;
  for (i=0; i<reps; i++) {
    tmp = test();
    if (tmp == -10000){
      printf("Memory allocation failure in %s\n", name);
      times[i] = 0;
    }
    else if (tmp == -11000){
      printf("CPU/GPU mismatch in %s\n", name);
      times[i] = 0;
    }
    else{
      times[i] = tmp;
    }
  }
  stats(&testtime, &testsd);
  print_results(name, testtime, testsd);
}

canonical_original_code:
void benchmark(char *name, double (*test)())
{
  int i = 0;
  double tmp = 0;
  for (i=0; i<reps; i++) {
    tmp = test();
    if (tmp == -10000){
      printf("Memory allocation failure in %s\n", name);
      times[i] = 0;
    }
    else if (tmp == -11000){
      printf("CPU/GPU mismatch in %s\n", name);
      times[i] = 0;
    }
    else{
      times[i] = tmp;
    }
  }
  stats(&testtime, &testsd);
  print_results(name, testtime, testsd);
}

variable_types:
test
double (*)()

variable_types: tmp double


wul

decompiled_code:
void wul()
{
double *v0; // r13
char *v1; // rax
char *v2; // rbp
double *v3; // rbx
__int64 i; // rax

v0 = (double *)malloc(0x10000uLL);
v1 = (char *)malloc(0x10000uLL);
v2 = v1;
if ( !v0 || !v1 )
puts("Unable to allocate memory in wul.");
v3 = v0;
do
*v3++ = (double)rand() * 4.656612873077393e-10;
while ( v0 + 0x2000 != v3 );
for ( i = 0LL; i != 0x2000; ++i )
*(double *)&v2[i * 8] = v0[i] + v0[i];
if ( *v0 < 0.0 )
puts("Error in WUL");
free(v0);
free(v2);
}

canonical_decompiled_code:
void func0()
{
double *v0; // r13
char *v1; // rax
char *v2; // rbp
double *v3; // rbx
__int64 i; // rax

v0 = (double *)malloc(0x10000uLL);
v1 = (char *)malloc(0x10000uLL);
v2 = v1;
if ( !v0 || !v1 )
puts("Unable to allocate memory in wul.");
v3 = v0;
do
*v3++ = (double)rand() * 4.656612873077393e-10;
while ( v0 + 0x2000 != v3 );
for ( i = 0LL; i != 0x2000; ++i )
*(double *)&v2[i * 8] = v0[i] + v0[i];
if ( *v0 < 0.0 )
puts("Error in WUL");
free(v0);
free(v2);
}

original_code:
void wul(){
  int data = 8192;
  double *arr_a = (double *)malloc(sizeof(double) * data);
  double *arr_b = (double *)malloc(sizeof(double) * data);
  int i = 0;
  if (arr_a==((void *)0)||arr_b==((void *)0)) {
      printf("Unable to allocate memory in wul.\n");
  }
  for (i=0;i<data;i++){
    arr_a[i] = (double) (rand()/(1.0+2147483647));
  }
#pragma acc data copy(arr_b[0:data]), copyin(arr_a[0:data])
  {
#pragma acc parallel loop
    for (i=0;i<data;i++){
      arr_b[i] = arr_a[i] * 2;
    }
  }
  if (arr_a[0] < 0){
    printf("Error in WUL\n");
  }
  free(arr_a);
  free(arr_b);
}

variable_types: data int


main

canonical_name: main

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

init(argc, argv, envp);
wul();
strcpy(v4.m128i_i8, "ContigH2D");
benchmark(&v4, &contig_htod);
strcpy(v4.m128i_i8, "ContigD2H");
benchmark(&v4, &contig_dtoh);
strcpy(v4.m128i_i8, "SlicedD2H");
benchmark(&v4, &sliced_dtoh);
strcpy(v4.m128i_i8, "SlicedH2D");
benchmark(&v4, &sliced_htod);
strcpy(v4.m128i_i8, "Kernels_If");
benchmark(&v4, &kernels_if);
strcpy(v4.m128i_i8, "Parallel_If");
benchmark(&v4, &parallel_if);
v5[0] = 0;
v4 = _mm_load_si128((const __m128i *)&LC4);
benchmark(&v4, &parallel_private);
strcpy(v5, "ate");
v4 = _mm_load_si128((const __m128i *)&LC5);
benchmark(&v4, &parallel_firstprivate);
v5[0] = 0;
v4 = _mm_load_si128((const __m128i *)&LC6);
benchmark(&v4, &kernels_combined);
strcpy(v5, "d");
v4 = _mm_load_si128((const __m128i *)&LC7);
benchmark(&v4, &parallel_combined);
strcpy(v4.m128i_i8, "Update_Host");
benchmark(&v4, &update);
strcpy(v5, "on");
v4 = _mm_load_si128((const __m128i *)&LC8);
benchmark(&v4, &kernels_invoc);
strcpy(v5, "ion");
v4 = _mm_load_si128((const __m128i *)&LC9);
benchmark(&v4, &parallel_invoc);
strcpy(v5, "on");
v4 = _mm_load_si128((const __m128i *)&LC10);
benchmark(&v4, &parallel_reduction);
strcpy(v5, "n");
v4 = _mm_load_si128((const __m128i *)&LC11);
benchmark(&v4, &kernels_reduction);
v4.m128i_i32[0] = 5066034;
benchmark(&v4, &twomm);
v4.m128i_i32[0] = 5066035;
benchmark(&v4, &threemm);
strcpy(v4.m128i_i8, "ATAX");
benchmark(&v4, &atax);
strcpy(v4.m128i_i8, "BICG");
benchmark(&v4, &bicg);
v4.m128i_i32[0] = 5527117;
benchmark(&v4, &mvt);
strcpy(v4.m128i_i8, "SYRK");
benchmark(&v4, &syrk);
v4.m128i_i32[0] = 5656387;
benchmark(&v4, &covariance);
v4.m128i_i32[0] = 5394243;
benchmark(&v4, &correlation);
strcpy(v4.m128i_i8, "SYR2K");
benchmark(&v4, &syr2k);
v4.m128i_i64[0] = 0x564D4D55534547LL;
benchmark(&v4, &gesummv);
strcpy(v4.m128i_i8, "GEMM");
benchmark(&v4, &gemm);
strcpy(v4.m128i_i8, "2DCONV");
benchmark(&v4, &twodconv);
strcpy(v4.m128i_i8, "3DCONV");
benchmark(&v4, &threedconv);
v4.m128i_i32[0] = 5453618;
benchmark(&v4, &stencil);
strcpy(v4.m128i_i8, "LE2D");
benchmark(&v4, &le_main);
strcpy(v4.m128i_i8, "HIMENO");
benchmark(&v4, &himeno_main);
finalise();
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__m128i v4; // [rsp+0h] [rbp-28h] BYREF
char v5[8]; // [rsp+10h] [rbp-18h] BYREF

init(argc, argv, envp);
func0();
strcpy(v4.m128i_i8, "ContigH2D");
benchmark(&v4, &contig_htod);
strcpy(v4.m128i_i8, "ContigD2H");
benchmark(&v4, &contig_dtoh);
strcpy(v4.m128i_i8, "SlicedD2H");
benchmark(&v4, &sliced_dtoh);
strcpy(v4.m128i_i8, "SlicedH2D");
benchmark(&v4, &sliced_htod);
strcpy(v4.m128i_i8, "Kernels_If");
benchmark(&v4, &kernels_if);
strcpy(v4.m128i_i8, "Parallel_If");
benchmark(&v4, &parallel_if);
v5[0] = 0;
v4 = _mm_load_si128((const __m128i *)&LC4);
benchmark(&v4, &parallel_private);
strcpy(v5, "ate");
v4 = _mm_load_si128((const __m128i *)&LC5);
benchmark(&v4, &parallel_firstprivate);
v5[0] = 0;
v4 = _mm_load_si128((const __m128i *)&LC6);
benchmark(&v4, &kernels_combined);
strcpy(v5, "d");
v4 = _mm_load_si128((const __m128i *)&LC7);
benchmark(&v4, &parallel_combined);
strcpy(v4.m128i_i8, "Update_Host");
benchmark(&v4, &update);
strcpy(v5, "on");
v4 = _mm_load_si128((const __m128i *)&LC8);
benchmark(&v4, &kernels_invoc);
strcpy(v5, "ion");
v4 = _mm_load_si128((const __m128i *)&LC9);
benchmark(&v4, &parallel_invoc);
strcpy(v5, "on");
v4 = _mm_load_si128((const __m128i *)&LC10);
benchmark(&v4, &parallel_reduction);
strcpy(v5, "n");
v4 = _mm_load_si128((const __m128i *)&LC11);
benchmark(&v4, &kernels_reduction);
v4.m128i_i32[0] = 5066034;
benchmark(&v4, &twomm);
v4.m128i_i32[0] = 5066035;
benchmark(&v4, &threemm);
strcpy(v4.m128i_i8, "ATAX");
benchmark(&v4, &atax);
strcpy(v4.m128i_i8, "BICG");
benchmark(&v4, &bicg);
v4.m128i_i32[0] = 5527117;
benchmark(&v4, &mvt);
strcpy(v4.m128i_i8, "SYRK");
benchmark(&v4, &syrk);
v4.m128i_i32[0] = 5656387;
benchmark(&v4, &covariance);
v4.m128i_i32[0] = 5394243;
benchmark(&v4, &correlation);
strcpy(v4.m128i_i8, "SYR2K");
benchmark(&v4, &syr2k);
v4.m128i_i64[0] = 0x564D4D55534547LL;
benchmark(&v4, &gesummv);
strcpy(v4.m128i_i8, "GEMM");
benchmark(&v4, &gemm);
strcpy(v4.m128i_i8, "2DCONV");
benchmark(&v4, &twodconv);
strcpy(v4.m128i_i8, "3DCONV");
benchmark(&v4, &threedconv);
v4.m128i_i32[0] = 5453618;
benchmark(&v4, &stencil);
strcpy(v4.m128i_i8, "LE2D");
benchmark(&v4, &le_main);
strcpy(v4.m128i_i8, "HIMENO");
benchmark(&v4, &himeno_main);
finalise();
return 0;
}

original_code:
int main(int argc, char **argv) {
  char testName[32];
  init(argc, argv);
  wul();
  sprintf(testName, "ContigH2D");
  benchmark(testName, &contig_htod);
  sprintf(testName, "ContigD2H");
  benchmark(testName, &contig_dtoh);
  sprintf(testName, "SlicedD2H");
  benchmark(testName, &sliced_dtoh);
  sprintf(testName, "SlicedH2D");
  benchmark(testName, &sliced_htod);
  sprintf(testName, "Kernels_If");
  benchmark(testName, &kernels_if);
  sprintf(testName, "Parallel_If");
  benchmark(testName, &parallel_if);
  sprintf(testName, "Parallel_private");
  benchmark(testName, &parallel_private);
  sprintf(testName, "Parallel_1stprivate");
  benchmark(testName, &parallel_firstprivate);
  sprintf(testName, "Kernels_combined");
  benchmark(testName, &kernels_combined);
  sprintf(testName, "Parallel_combined");
  benchmark(testName, &parallel_combined);
  sprintf(testName, "Update_Host");
  benchmark(testName, &update);
  sprintf(testName, "Kernels_Invocation");
  benchmark(testName, &kernels_invoc);
  sprintf(testName, "Parallel_Invocation");
  benchmark(testName, &parallel_invoc);
  sprintf(testName, "Parallel_Reduction");
  benchmark(testName, &parallel_reduction);
  sprintf(testName, "Kernels_Reduction");
  benchmark(testName, &kernels_reduction);
  sprintf(testName, "2MM");
  benchmark(testName, &twomm);
  sprintf(testName, "3MM");
  benchmark(testName, &threemm);
  sprintf(testName, "ATAX");
  benchmark(testName, &atax);
  sprintf(testName, "BICG");
  benchmark(testName, &bicg);
  sprintf(testName, "MVT");
  benchmark(testName, &mvt);
  sprintf(testName, "SYRK");
  benchmark(testName, &syrk);
  sprintf(testName, "COV");
  benchmark(testName, &covariance);
  sprintf(testName, "COR");
  benchmark(testName, &correlation);
  sprintf(testName, "SYR2K");
  benchmark(testName, &syr2k);
  sprintf(testName, "GESUMMV");
  benchmark(testName, &gesummv);
  sprintf(testName, "GEMM");
  benchmark(testName, &gemm);
  sprintf(testName, "2DCONV");
  benchmark(testName, &twodconv);
  sprintf(testName, "3DCONV");
  benchmark(testName, &threedconv);
  sprintf(testName, "27S");
  benchmark(testName, &stencil);
  sprintf(testName, "LE2D");
  benchmark(testName, &le_main);
  sprintf(testName, "HIMENO");
  benchmark(testName, &himeno_main);
  finalise();
  return 0;
}

variable_types: argc int

variable_types:
testName
char [32]


repo: Earlz/microforth

decompiled_code:
__int64 test_push_pop_works()
{
__int64 result; // rax
__int64 v1; // [rsp-10h] [rbp-48h]
_BYTE v2[56]; // [rsp+0h] [rbp-38h] BYREF

mf_init(v2, 100LL);
mf_push(v2, 4660LL);
++minunit_assert;
if ( mf_pop(v2) != 4660 )
{
snprintf(
minunit_last_message,
0x400uLL,
"%s failed:\n\t%s:%d: %s",
"test_push_pop_works",
"unittests.c",
46LL,
"mf_pop(&mf) == 0x1234");
LABEL_3:
result = v1;
minunit_status = 1;
return result;
}
putchar(46);
mf_push(v2, 17767LL);
mf_push(v2, 43981LL);
mf_push(v2, 65315LL);
++minunit_assert;
if ( mf_pop(v2) != 65315 )
{
snprintf(
minunit_last_message,
0x400uLL,
"%s failed:\n\t%s:%d: %s",
"test_push_pop_works",
"unittests.c",
51LL,
"mf_pop(&mf)==0xff23");
goto LABEL_3;
}
putchar(46);
++minunit_assert;
if ( mf_pop(v2) != 43981 )
{
snprintf(
minunit_last_message,
0x400uLL,
"%s failed:\n\t%s:%d: %s",
"test_push_pop_works",
"unittests.c",
52LL,
"mf_pop(&mf)==0xabcd");
goto LABEL_3;
}
putchar(46);
++minunit_assert;
if ( mf_pop(v2) != 17767 )
{
snprintf(
minunit_last_message,
0x400uLL,
"%s failed:\n\t%s:%d: %s",
"test_push_pop_works",
"unittests.c",
53LL,
"mf_pop(&mf)==0x4567");
goto LABEL_3;
}
putchar(46);
return mf_destroy(v2);
}

canonical_decompiled_code:
__int64 func7()
{
__int64 result; // rax
__int64 v1; // [rsp-10h] [rbp-48h]
_BYTE v2[56]; // [rsp+0h] [rbp-38h] BYREF

func14(v2, 100LL);
func12(v2, 4660LL);
++minunit_assert;
if ( func13(v2) != 4660 )
{
snprintf(
minunit_last_message,
0x400uLL,
"%s failed:\n\t%s:%d: %s",
"test_push_pop_works",
"unittests.c",
46LL,
"mf_pop(&mf) == 0x1234");
LABEL_3:
result = v1;
minunit_status = 1;
return result;
}
putchar(46);
func12(v2, 17767LL);
func12(v2, 43981LL);
func12(v2, 65315LL);
++minunit_assert;
if ( func13(v2) != 65315 )
{
snprintf(
minunit_last_message,
0x400uLL,
"%s failed:\n\t%s:%d: %s",
"test_push_pop_works",
"unittests.c",
51LL,
"mf_pop(&mf)==0xff23");
goto LABEL_3;
}
putchar(46);
++minunit_assert;
if ( func13(v2) != 43981 )
{
snprintf(
minunit_last_message,
0x400uLL,
"%s failed:\n\t%s:%d: %s",
"test_push_pop_works",
"unittests.c",
52LL,
"mf_pop(&mf)==0xabcd");
goto LABEL_3;
}
putchar(46);
++minunit_assert;
if ( func13(v2) != 17767 )
{
snprintf(
minunit_last_message,
0x400uLL,
"%s failed:\n\t%s:%d: %s",
"test_push_pop_works",
"unittests.c",
53LL,
"mf_pop(&mf)==0x4567");
goto LABEL_3;
}
putchar(46);
return func15(v2);
}

original_code:
static void test_push_pop_works()
{
  mf_state_t mf;
  mf_init(&mf, 100);
  mf_push(&mf, 0x1234);
  do { minunit_assert++; if (!(mf_pop(&mf) == 0x1234)) { snprintf(minunit_last_message, 1024, "%s failed:\n\t%s:%d: %s", __func__, "unittests.c", 46, "mf_pop(&mf) == 0x1234"); minunit_status = 1; return; } else { printf("."); }} while(0);
  mf_push(&mf, 0x4567);
  mf_push(&mf, 0xabcd);
  mf_push(&mf, 0xff23);
  do { minunit_assert++; if (!(mf_pop(&mf)==0xff23)) { snprintf(minunit_last_message, 1024, "%s failed:\n\t%s:%d: %s", __func__, "unittests.c", 51, "mf_pop(&mf)==0xff23"); minunit_status = 1; return; } else { printf("."); }} while(0);
  do { minunit_assert++; if (!(mf_pop(&mf)==0xabcd)) { snprintf(minunit_last_message, 1024, "%s failed:\n\t%s:%d: %s", __func__, "unittests.c", 52, "mf_pop(&mf)==0xabcd"); minunit_status = 1; return; } else { printf("."); }} while(0);
  do { minunit_assert++; if (!(mf_pop(&mf)==0x4567)) { snprintf(minunit_last_message, 1024, "%s failed:\n\t%s:%d: %s", __func__, "unittests.c", 53, "mf_pop(&mf)==0x4567"); minunit_status = 1; return; } else { printf("."); }} while(0);
  mf_destroy(&mf);
}

canonical_original_code:
static void test_push_pop_works()
{
  struct mf_state mf;
  mf_init(&mf, 100);
  mf_push(&mf, 0x1234);
  do { minunit_assert++; if (!(mf_pop(&mf) == 0x1234)) { snprintf(minunit_last_message, 1024, "%s failed:\n\t%s:%d: %s", __func__, "unittests.c", 46, "mf_pop(&mf) == 0x1234"); minunit_status = 1; return; } else { printf("."); }} while(0);
  mf_push(&mf, 0x4567);
  mf_push(&mf, 0xabcd);
  mf_push(&mf, 0xff23);
  do { minunit_assert++; if (!(mf_pop(&mf)==0xff23)) { snprintf(minunit_last_message, 1024, "%s failed:\n\t%s:%d: %s", __func__, "unittests.c", 51, "mf_pop(&mf)==0xff23"); minunit_status = 1; return; } else { printf("."); }} while(0);
  do { minunit_assert++; if (!(mf_pop(&mf)==0xabcd)) { snprintf(minunit_last_message, 1024, "%s failed:\n\t%s:%d: %s", __func__, "unittests.c", 52, "mf_pop(&mf)==0xabcd"); minunit_status = 1; return; } else { printf("."); }} while(0);
  do { minunit_assert++; if (!(mf_pop(&mf)==0x4567)) { snprintf(minunit_last_message, 1024, "%s failed:\n\t%s:%d: %s", __func__, "unittests.c", 53, "mf_pop(&mf)==0x4567"); minunit_status = 1; return; } else { printf("."); }} while(0);
  mf_destroy(&mf);
}

variable_types: struct mf_state { long *stack; unsigned long stackpos; unsigned long stacklen; int error; char *error_msg; struct mf_word_entry { struct mf_word_t { char *name; char *body; char *(*internal_func)(struct mf_state *state, char *context); } word; struct mf_word_entry *next; } *words; }

user_defined_types: struct mf_state { long *stack; unsigned long stackpos; unsigned long stacklen; int error; char *error_msg; struct mf_word_entry *words; }

user_defined_types: struct mf_word_entry { struct mf_word_t word; struct mf_word_entry *next; }


decompiled_code:
__int64 test_push_pop_proper_errors()
{
__int64 result; // rax
__int64 v1; // [rsp-10h] [rbp-48h]
_QWORD v2[3]; // [rsp+0h] [rbp-38h] BYREF
int v3; // [rsp+18h] [rbp-20h]
__int64 v4; // [rsp+20h] [rbp-18h]

mf_init(v2, 100LL);
v2[2] = 1LL;
mf_push(v2, 1LL);
++minunit_assert;
if ( v3 )
{
snprintf(
minunit_last_message,
0x400uLL,
"%s failed:\n\t%s:%d: %s",
"test_push_pop_proper_errors",
"unittests.c",
63LL,
"mf.error==0");
}
else
{
putchar(46);
mf_push(v2, 1LL);
++minunit_assert;
if ( v3 && v4 )
{
putchar(46);
v3 = 0;
mf_pop(v2);
++minunit_assert;
if ( v3 )
{
snprintf(
minunit_last_message,
0x400uLL,
"%s failed:\n\t%s:%d: %s",
"test_push_pop_proper_errors",
"unittests.c",
68LL,
"mf.error==0");
}
else
{
putchar(46);
mf_pop(v2);
++minunit_assert;
if ( v3 )
{
putchar(46);
return mf_destroy(v2);
}
snprintf(
minunit_last_message,
0x400uLL,
"%s failed:\n\t%s:%d: %s",
"test_push_pop_proper_errors",
"unittests.c",
70LL,
"mf.error!=0");
}
}
else
{
snprintf(
minunit_last_message,
0x400uLL,
"%s failed:\n\t%s:%d: %s",
"test_push_pop_proper_errors",
"unittests.c",
65LL,
"mf.error!=0 && mf.error_msg!=NULL");
}
}
result = v1;
minunit_status = 1;
return result;
}

canonical_decompiled_code:
__int64 func8()
{
__int64 result; // rax
__int64 v1; // [rsp-10h] [rbp-48h]
_QWORD v2[3]; // [rsp+0h] [rbp-38h] BYREF
int v3; // [rsp+18h] [rbp-20h]
__int64 v4; // [rsp+20h] [rbp-18h]

func14(v2, 100LL);
v2[2] = 1LL;
func12(v2, 1LL);
++minunit_assert;
if ( v3 )
{
snprintf(
minunit_last_message,
0x400uLL,
"%s failed:\n\t%s:%d: %s",
"test_push_pop_proper_errors",
"unittests.c",
63LL,
"mf.error==0");
}
else
{
putchar(46);
func12(v2, 1LL);
++minunit_assert;
if ( v3 && v4 )
{
putchar(46);
v3 = 0;
func13(v2);
++minunit_assert;
if ( v3 )
{
snprintf(
minunit_last_message,
0x400uLL,
"%s failed:\n\t%s:%d: %s",
"test_push_pop_proper_errors",
"unittests.c",
68LL,
"mf.error==0");
}
else
{
putchar(46);
func13(v2);
++minunit_assert;
if ( v3 )
{
putchar(46);
return func15(v2);
}
snprintf(
minunit_last_message,
0x400uLL,
"%s failed:\n\t%s:%d: %s",
"test_push_pop_proper_errors",
"unittests.c",
70LL,
"mf.error!=0");
}
}
else
{
snprintf(
minunit_last_message,
0x400uLL,
"%s failed:\n\t%s:%d: %s",
"test_push_pop_proper_errors",
"unittests.c",
65LL,
"mf.error!=0 && mf.error_msg!=NULL");
}
}
result = v1;
minunit_status = 1;
return result;
}

original_code:
static void test_push_pop_proper_errors()
{
  mf_state_t mf;
  mf_init(&mf, 100);
  mf.stacklen=1;
  mf_push(&mf, 1);
  do { minunit_assert++; if (!(mf.error==0)) { snprintf(minunit_last_message, 1024, "%s failed:\n\t%s:%d: %s", __func__, "unittests.c", 63, "mf.error==0"); minunit_status = 1; return; } else { printf("."); }} while(0);
  mf_push(&mf, 1);
  do { minunit_assert++; if (!(mf.error!=0 && mf.error_msg!=((void *)0))) { snprintf(minunit_last_message, 1024, "%s failed:\n\t%s:%d: %s", __func__, "unittests.c", 65, "mf.error!=0 && mf.error_msg!=NULL"); minunit_status = 1; return; } else { printf("."); }} while(0);
  mf.error=0;
  mf_pop(&mf);
  do { minunit_assert++; if (!(mf.error==0)) { snprintf(minunit_last_message, 1024, "%s failed:\n\t%s:%d: %s", __func__, "unittests.c", 68, "mf.error==0"); minunit_status = 1; return; } else { printf("."); }} while(0);
  mf_pop(&mf);
  do { minunit_assert++; if (!(mf.error!=0)) { snprintf(minunit_last_message, 1024, "%s failed:\n\t%s:%d: %s", __func__, "unittests.c", 70, "mf.error!=0"); minunit_status = 1; return; } else { printf("."); }} while(0);
  mf_destroy(&mf);
}

canonical_original_code:
static void test_push_pop_proper_errors()
{
  struct mf_state mf;
  mf_init(&mf, 100);
  mf.stacklen=1;
  mf_push(&mf, 1);
  do { minunit_assert++; if (!(mf.error==0)) { snprintf(minunit_last_message, 1024, "%s failed:\n\t%s:%d: %s", __func__, "unittests.c", 63, "mf.error==0"); minunit_status = 1; return; } else { printf("."); }} while(0);
  mf_push(&mf, 1);
  do { minunit_assert++; if (!(mf.error!=0 && mf.error_msg!=((void *)0))) { snprintf(minunit_last_message, 1024, "%s failed:\n\t%s:%d: %s", __func__, "unittests.c", 65, "mf.error!=0 && mf.error_msg!=NULL"); minunit_status = 1; return; } else { printf("."); }} while(0);
  mf.error=0;
  mf_pop(&mf);
  do { minunit_assert++; if (!(mf.error==0)) { snprintf(minunit_last_message, 1024, "%s failed:\n\t%s:%d: %s", __func__, "unittests.c", 68, "mf.error==0"); minunit_status = 1; return; } else { printf("."); }} while(0);
  mf_pop(&mf);
  do { minunit_assert++; if (!(mf.error!=0)) { snprintf(minunit_last_message, 1024, "%s failed:\n\t%s:%d: %s", __func__, "unittests.c", 70, "mf.error!=0"); minunit_status = 1; return; } else { printf("."); }} while(0);
  mf_destroy(&mf);
}

user_defined_types: struct mf_word_t { char *name; char *body; char *(*internal_func)(struct mf_state *state, char *context); }


decompiled_code:
double __fastcall mu_timer_real(const char *a1)
{
return -1.0;
}

canonical_decompiled_code:
double __fastcall func9(const char *a1)
{
return -1.0;
}

original_code:
double mu_timer_real( )
{
        return -1.0;
}

canonical_original_code:
double mu_timer_real()
{
        return -1.0;
}


decompiled_code:
double __fastcall mu_timer_cpu(const char *a1)
{
return mu_timer_real(a1);
}

canonical_decompiled_code:
double __fastcall func11(const char *a1)
{
return func9(a1);
}

original_code:
double mu_timer_cpu( )
{
        return -1;
}

canonical_original_code:
double mu_timer_cpu()
{
        return -1;
}


original_code:
intptr_t mf_pop(mf_state_t* state)
{
  if(state->stackpos==0)
  {
    state->error=1;
    state->error_msg="Stack Underflow";
    return -1;
  }
  return state->stack[--state->stackpos];
}

canonical_original_code:
long mf_pop(struct mf_state *state)
{
  if(state->stackpos==0)
  {
    state->error=1;
    state->error_msg="Stack Underflow";
    return -1;
  }
  return state->stack[--state->stackpos];
}

variable_types: struct mf_state { long *stack; unsigned long stackpos; unsigned long stacklen; int error; char *error_msg; struct mf_word_entry { struct mf_word_t { char *name; char *body; char *(*internal_func)(struct mf_state *state, char *context); } word; struct mf_word_entry *next; } *words; } *

return_type: long


decompiled_code:
__int64 __fastcall mf_init(__int64 a1, int a2)
{
void *v2; // rax
__int64 result; // rax

v2 = malloc(8LL * a2);
*(_QWORD *)a1 = v2;
if ( !v2 )
return 0xFFFFFFFFLL;
*(_QWORD *)(a1 + 8) = 0LL;
result = 0LL;
*(_QWORD *)(a1 + 16) = a2;
*(_DWORD *)(a1 + 24) = 0;
*(_QWORD *)(a1 + 32) = 0LL;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func14(__int64 a1, int a2)
{
void *v2; // rax
__int64 result; // rax

v2 = malloc(8LL * a2);
*(_QWORD *)a1 = v2;
if ( !v2 )
return 0xFFFFFFFFLL;
*(_QWORD *)(a1 + 8) = 0LL;
result = 0LL;
*(_QWORD *)(a1 + 16) = a2;
*(_DWORD *)(a1 + 24) = 0;
*(_QWORD *)(a1 + 32) = 0LL;
return result;
}

original_code:
int mf_init(mf_state_t* state, int stacksize)
{
  state->stack=malloc(stacksize*sizeof(intptr_t*));
  if(state->stack==((void *)0))
  {
    return -1;
  }
  state->stackpos=0;
  state->stacklen=stacksize;
  state->error=0;
  state->error_msg=((void *)0);
  return 0;
}

canonical_original_code:
int mf_init(struct mf_state *state, int stacksize)
{
  state->stack=malloc(stacksize*sizeof(long *));
  if(state->stack==((void *)0))
  {
    return -1;
  }
  state->stackpos=0;
  state->stacklen=stacksize;
  state->error=0;
  state->error_msg=((void *)0);
  return 0;
}

variable_types: stacksize int


decompiled_code:
__int64 __fastcall mf_destroy(void **a1)
{
void *v1; // rdi

v1 = *a1;
if ( v1 )
free(v1);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func15(void **a1)
{
void *v1; // rdi

v1 = *a1;
if ( v1 )
free(v1);
return 0LL;
}

original_code:
int mf_destroy(mf_state_t* state)
{
  if(state->stack!=((void *)0))
  {
    free(state->stack);
  }
  return 0;
}

canonical_original_code:
int mf_destroy(struct mf_state *state)
{
  if(state->stack!=((void *)0))
  {
    free(state->stack);
  }
  return 0;
}


cmpword

decompiled_code:
char *__fastcall cmpword(const char *a1, __int64 a2)
{
size_t v2; // rcx
__int64 v3; // rax
char v4; // dl
char *v5; // r12
char v6; // bl
int v7; // eax

v2 = strlen(a1);
v3 = 0LL;
while ( v2 != v3 )
{
v4 = a1[v3++];
if ( v4 != *(_BYTE *)(a2 + v3 - 1) )
return 0LL;
}
v5 = (char *)(a2 + v2 + 1);
v6 = *v5;
v7 = isspace(*v5);
if ( v6 )
{
if ( !v7 )
v5 = 0LL;
}
return v5;
}

canonical_decompiled_code:
char *__fastcall func17(const char *a1, __int64 a2)
{
size_t v2; // rcx
__int64 v3; // rax
char v4; // dl
char *v5; // r12
char v6; // bl
int v7; // eax

v2 = strlen(a1);
v3 = 0LL;
while ( v2 != v3 )
{
v4 = a1[v3++];
if ( v4 != *(_BYTE *)(a2 + v3 - 1) )
return 0LL;
}
v5 = (char *)(a2 + v2 + 1);
v6 = *v5;
v7 = isspace(*v5);
if ( v6 )
{
if ( !v7 )
v5 = 0LL;
}
return v5;
}

original_code:
const char* cmpword(const char* word, const char* text)
{
  int i=0;
  for(i=0;i<strlen(word);i++)
  {
    if(word[i]!=text[i])
    {
      return ((void *)0);
    }
  }
  char c=text[i+1];
  if(isspace(c) || c==0)
  {
    return &text[i+1];
  }
  return ((void *)0);
}

canonical_original_code:
char *cmpword(char *word, char *text)
{
  int i = 0;
  for(i=0;i<strlen(word);i++)
  {
    if(word[i]!=text[i])
    {
      return ((void *)0);
    }
  }
  char c = text[i+1];
  if(isspace(c) || c==0)
  {
    return &text[i+1];
  }
  return ((void *)0);
}

variable_types:
word
char *

variable_types:
text
char *

variable_types: c char

return_type: char *


getword

decompiled_code:
__int64 __fastcall getword(__int64 a1, __int64 a2, char **a3)
{
__int64 v4; // rbx
char *v5; // rax

if ( !a1 )
return 0LL;
v4 = a1;
do
{
v5 = cmpword(*(const char **)v4, a2);
if ( v5 )
{
*a3 = v5;
return v4;
}
v4 = *(_QWORD *)(v4 + 24);
}
while ( v4 );
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func18(__int64 a1, __int64 a2, char **a3)
{
__int64 v4; // rbx
char *v5; // rax

if ( !a1 )
return 0LL;
v4 = a1;
do
{
v5 = func17(*(const char **)v4, a2);
if ( v5 )
{
*a3 = v5;
return v4;
}
v4 = *(_QWORD *)(v4 + 24);
}
while ( v4 );
return 0LL;
}

original_code:
mf_word_t* getword(mf_word_entry_t* list, const char* text, char** endword)
{
  while(list!=((void *)0))
  {
    char* end=cmpword(list->word.name, text);
    if(end!=((void *)0))
    {
      *endword=end;
      return &list->word;
    }
    list=list->next;
  }
  return ((void *)0);
}

canonical_original_code:
struct mf_word_t *getword(struct mf_word_entry *list, char *text, char **endword)
{
  while(list!=((void *)0))
  {
    char *end = cmpword(list->word.name, text);
    if(end!=((void *)0))
    {
      *endword=end;
      return &list->word;
    }
    list=list->next;
  }
  return ((void *)0);
}

variable_types:
list
struct mf_word_entry *

variable_types:
endword
char **

variable_types:
end
char *

return_type: struct mf_word_t { char *name; char *body; char *(*internal_func)(struct mf_state { long *stack; unsigned long stackpos; unsigned long stacklen; int error; char *error_msg; struct mf_word_entry { struct mf_word_t word; struct mf_word_entry *next; } *words; } *state, char *context); } *


decompiled_code:
char *__fastcall mf_execute_word(__int64 a1, const char *a2)
{
char *v2; // r12
__int64 v4; // rsi
__int64 v5; // rax
__int64 (__fastcall *v6)(__int64, char *); // rax
char *endptr[4]; // [rsp+8h] [rbp-20h] BYREF

v2 = (char *)a2;
if ( !*a2 )
return v2;
endptr[0] = 0LL;
v4 = strtol(a2, endptr, 10);
if ( !endptr[0] || endptr[0] == v2 )
{
v5 = getword(*(_QWORD *)(a1 + 40), (__int64)v2, endptr);
if ( v5 )
{
v6 = *(__int64 (__fastcall **)(__int64, char *))(v5 + 16);
v2 = endptr[0];
if ( v6 )
return (char *)v6(a1, endptr[0]);
}
else
{
*(_DWORD *)(a1 + 24) = 1;
*(_QWORD *)(a1 + 32) = "Unknown word";
}
return v2;
}
if ( *endptr[0] == 117 )
v4 = strtoul(v2, endptr, 10);
mf_push((__int64 *)a1, v4);
return endptr[0];
}

canonical_decompiled_code:
char *__fastcall func19(__int64 a1, const char *a2)
{
char *v2; // r12
__int64 v4; // rsi
__int64 v5; // rax
__int64 (__fastcall *v6)(__int64, char *); // rax
char *endptr[4]; // [rsp+8h] [rbp-20h] BYREF

v2 = (char *)a2;
if ( !*a2 )
return v2;
endptr[0] = 0LL;
v4 = strtol(a2, endptr, 10);
if ( !endptr[0] || endptr[0] == v2 )
{
v5 = func18(*(_QWORD *)(a1 + 40), (__int64)v2, endptr);
if ( v5 )
{
v6 = *(__int64 (__fastcall **)(__int64, char *))(v5 + 16);
v2 = endptr[0];
if ( v6 )
return (char *)v6(a1, endptr[0]);
}
else
{
*(_DWORD *)(a1 + 24) = 1;
*(_QWORD *)(a1 + 32) = "Unknown word";
}
return v2;
}
if ( *endptr[0] == 117 )
v4 = strtoul(v2, endptr, 10);
func12((__int64 *)a1, v4);
return endptr[0];
}

original_code:
const char* mf_execute_word(mf_state_t* state, const char* word)
{
  if(*word==0) return word;
  char *end=((void *)0);
  long result=strtol(word, &end, 10);
  if(end!=word && end!=((void *)0))
  {
    if(*end=='u')
    {
      result=(long)strtoul(word, &end, 10);
    }
    mf_push(state, (intptr_t)result);
    return end;
  }
  mf_word_t* item=getword(state->words, word, &end);
  if(item==((void *)0))
  {
    state->error=1;
    state->error_msg="Unknown word";
    return word;
  }
  if(item->internal_func!=((void *)0))
  {
    return item->internal_func(state, end);
  }
  return end;
}

canonical_original_code:
char *mf_execute_word(struct mf_state *state, char *word)
{
  if(*word==0) return word;
  char *end = ((void *)0);
  long result = strtol(word, &end, 10);
  if(end!=word && end!=((void *)0))
  {
    if(*end=='u')
    {
      result=(long)strtoul(word, &end, 10);
    }
    mf_push(state, (long)result);
    return end;
  }
  struct mf_word_t *item = getword(state->words, word, &end);
  if(item==((void *)0))
  {
    state->error=1;
    state->error_msg="Unknown word";
    return word;
  }
  if(item->internal_func!=((void *)0))
  {
    return item->internal_func(state, end);
  }
  return end;
}

variable_types: result long

variable_types: struct mf_word_t { char *name; char *body; char *(*internal_func)(struct mf_state { long *stack; unsigned long stackpos; unsigned long stacklen; int error; char *error_msg; struct mf_word_entry { struct mf_word_t word; struct mf_word_entry *next; } *words; } *state, char *context); } *


decompiled_code:
__int64 __fastcall mf_execute(__int64 a1, unsigned __int8 *a2)
{
char *v2; // rax
unsigned __int8 *v3; // rax

v2 = (char *)a2;
do
{
if ( !*v2 )
return 0LL;
v3 = skip_whitespace(a2);
v2 = mf_execute_word(a1, (const char *)v3);
}
while ( !*(_DWORD *)(a1 + 24) );
fprintf(
stderr,
"Error at character '%il'. Message: '%s'\n",
(unsigned int)((_DWORD)v2 - (_DWORD)a2),
*(const char **)(a1 + 32));
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 __fastcall func20(__int64 a1, unsigned __int8 *a2)
{
char *v2; // rax
unsigned __int8 *v3; // rax

v2 = (char *)a2;
do
{
if ( !*v2 )
return 0LL;
v3 = func16(a2);
v2 = func19(a1, (const char *)v3);
}
while ( !*(_DWORD *)(a1 + 24) );
fprintf(
stderr,
"Error at character '%il'. Message: '%s'\n",
(unsigned int)((_DWORD)v2 - (_DWORD)a2),
*(const char **)(a1 + 32));
return 0xFFFFFFFFLL;
}

original_code:
int mf_execute(mf_state_t* state, const char* text)
{
  const char* word=text;
  while(*word!=0)
  {
    word=skip_whitespace(text);
    word=mf_execute_word(state, word);
    if(state->error!=0)
    {
      fprintf(stderr, "Error at character '%il'. Message: '%s'\n",(unsigned int)(word-text), state->error_msg);
      return -1;
    }
  }
  return 0;
}

canonical_original_code:
int mf_execute(struct mf_state *state, char *text)
{
  char *word = text;
  while(*word!=0)
  {
    word=skip_whitespace(text);
    word=mf_execute_word(state, word);
    if(state->error!=0)
    {
      fprintf(stderr, "Error at character '%il'. Message: '%s'\n",(unsigned int)(word-text), state->error_msg);
      return -1;
    }
  }
  return 0;
}


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
double v3; // xmm0_8
double v4; // xmm1_8
double v5; // xmm0_8

test_suite(argc, argv, envp);
minunit_setup = 0LL;
minunit_teardown = 0LL;
printf(
"\n\n%d tests, %d assertions, %d failures\n",
(unsigned int)minunit_run,
(unsigned int)minunit_assert,
(unsigned int)minunit_fail);
v5 = mu_timer_real("\nFinished in %.8f seconds (real) %.8f seconds (proc)\n\n", v3, v4);
printf(
"\nFinished in %.8f seconds (real) %.8f seconds (proc)\n\n",
v5 - *(double *)&minunit_real_timer,
v5 - *(double *)&minunit_proc_timer);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
double v3; // xmm0_8
double v4; // xmm1_8
double v5; // xmm0_8

func10(argc, argv, envp);
minunit_setup = 0LL;
minunit_teardown = 0LL;
printf(
"\n\n%d tests, %d assertions, %d failures\n",
(unsigned int)minunit_run,
(unsigned int)minunit_assert,
(unsigned int)minunit_fail);
v5 = func9("\nFinished in %.8f seconds (real) %.8f seconds (proc)\n\n", v3, v4);
printf(
"\nFinished in %.8f seconds (real) %.8f seconds (proc)\n\n",
v5 - *(double *)&minunit_real_timer,
v5 - *(double *)&minunit_proc_timer);
return 0;
}

original_code:
int main(int argc, char *argv[]) {
    do { test_suite(); minunit_setup = ((void *)0); minunit_teardown = ((void *)0);} while(0);
    do { printf("\n\n%d tests, %d assertions, %d failures\n", minunit_run, minunit_assert, minunit_fail); double minunit_end_real_timer = mu_timer_real(); double minunit_end_proc_timer = mu_timer_cpu(); printf("\nFinished in %.8f seconds (real) %.8f seconds (proc)\n\n", minunit_end_real_timer - minunit_real_timer, minunit_end_proc_timer - minunit_proc_timer);} while(0);
    return 0;
}

variable_types:
argv
char *[]


canonical_decompiled_code:
__int64 __fastcall func9(__int64 a1, int a2)
{
void *v2; // rax
__int64 result; // rax

v2 = malloc(8LL * a2);
*(_QWORD *)a1 = v2;
if ( !v2 )
return 0xFFFFFFFFLL;
*(_QWORD *)(a1 + 8) = 0LL;
result = 0LL;
*(_QWORD *)(a1 + 16) = a2;
*(_DWORD *)(a1 + 24) = 0;
*(_QWORD *)(a1 + 32) = 0LL;
return result;
}


canonical_decompiled_code:
__int64 __fastcall func10(void **a1)
{
void *v1; // rdi

v1 = *a1;
if ( v1 )
free(v1);
return 0LL;
}


cmpword

canonical_decompiled_code:
char *__fastcall func12(const char *a1, __int64 a2)
{
size_t v2; // rcx
__int64 v3; // rax
char v4; // dl
char *v5; // r12
char v6; // bl
int v7; // eax

v2 = strlen(a1);
v3 = 0LL;
while ( v2 != v3 )
{
v4 = a1[v3++];
if ( v4 != *(_BYTE *)(a2 + v3 - 1) )
return 0LL;
}
v5 = (char *)(a2 + v2 + 1);
v6 = *v5;
v7 = isspace(*v5);
if ( v6 )
{
if ( !v7 )
v5 = 0LL;
}
return v5;
}

variable_types: i int


getword

canonical_decompiled_code:
__int64 __fastcall func13(__int64 a1, __int64 a2, char **a3)
{
__int64 v4; // rbx
char *v5; // rax

if ( !a1 )
return 0LL;
v4 = a1;
do
{
v5 = func12(*(const char **)v4, a2);
if ( v5 )
{
*a3 = v5;
return v4;
}
v4 = *(_QWORD *)(v4 + 24);
}
while ( v4 );
return 0LL;
}


canonical_decompiled_code:
char *__fastcall func14(__int64 a1, const char *a2)
{
char *v2; // r12
__int64 v4; // rsi
__int64 v5; // rax
__int64 (__fastcall *v6)(__int64, char *); // rax
char *endptr[4]; // [rsp+8h] [rbp-20h] BYREF

v2 = (char *)a2;
if ( !*a2 )
return v2;
endptr[0] = 0LL;
v4 = strtol(a2, endptr, 10);
if ( !endptr[0] || endptr[0] == v2 )
{
v5 = func13(*(_QWORD *)(a1 + 40), (__int64)v2, endptr);
if ( v5 )
{
v6 = *(__int64 (__fastcall **)(__int64, char *))(v5 + 16);
v2 = endptr[0];
if ( v6 )
return (char *)v6(a1, endptr[0]);
}
else
{
*(_DWORD *)(a1 + 24) = 1;
*(_QWORD *)(a1 + 32) = "Unknown word";
}
return v2;
}
if ( *endptr[0] == 117 )
v4 = strtoul(v2, endptr, 10);
func7((__int64 *)a1, v4);
return endptr[0];
}


canonical_decompiled_code:
__int64 __fastcall func15(__int64 a1, unsigned __int8 *a2)
{
char *v2; // rax
unsigned __int8 *v3; // rax

v2 = (char *)a2;
do
{
if ( !*v2 )
return 0LL;
v3 = func11(a2);
v2 = func14(a1, (const char *)v3);
}
while ( !*(_DWORD *)(a1 + 24) );
fprintf(
stderr,
"Error at character '%il'. Message: '%s'\n",
(unsigned int)((_DWORD)v2 - (_DWORD)a2),
*(const char **)(a1 + 32));
return 0xFFFFFFFFLL;
}


strlcmpt

decompiled_code:
__int64 __fastcall strlcmpt(char *a1, char *a2, unsigned __int8 (__fastcall *a3)(_QWORD))
{
char v6; // al
_BYTE *v7; // r13

do
{
v7 = a1;
if ( a3((unsigned int)*a1) || a3((unsigned int)*a2) )
return 0LL;
v6 = *a2;
++a1;
++a2;
}
while ( *v7 == v6 );
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func16(char *a1, char *a2, unsigned __int8 (__fastcall *a3)(_QWORD))
{
char v6; // al
_BYTE *v7; // r13

do
{
v7 = a1;
if ( a3((unsigned int)*a1) || a3((unsigned int)*a2) )
return 0LL;
v6 = *a2;
++a1;
++a2;
}
while ( *v7 == v6 );
return 1LL;
}

original_code:
int strlcmpt(const char* str1, const char* str2, _Bool (*terminating)(char c))
{
  int i=0;
  while(!terminating(str1[i]) && !terminating(str2[i]))
  {
    if(str1[i] != str2[i])
    {
      return 1;
    }
    i++;
  }
  return 0;
}

canonical_original_code:
int strlcmpt(char *str1, char *str2, _Bool (*terminating)(char c))
{
  int i = 0;
  while(!terminating(str1[i]) && !terminating(str2[i]))
  {
    if(str1[i] != str2[i])
    {
      return 1;
    }
    i++;
  }
  return 0;
}

variable_types:
terminating
_Bool (*)(char c)


main

repo: Earnit/Hello-World

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

v5[0] = (__int64)v5;
v5[1] = (__int64)v5;
list_basic_add(&v4, argv, envp);
list_basic_print(&v4);
list_basic_print_simple(&v4);
return 0;
}

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

v5[0] = (__int64)v5;
v5[1] = (__int64)v5;
func9(&v4, argv, envp);
func10(&v4);
func11(&v4);
return 0;
}

original_code:
int main(void) {
    kool_list_t my_list;
    do { (&(my_list.list))->next = (&(my_list.list)); (&(my_list.list))->prev = (&(my_list.list)); } while (0);
    list_basic_add(&my_list);
    list_basic_print(&my_list);
    list_basic_print_simple(&my_list);
    return 0;
}

canonical_original_code:
int main() {
    struct kool_list my_list;
    do { (&(my_list.list))->next = (&(my_list.list)); (&(my_list.list))->prev = (&(my_list.list)); } while (0);
    list_basic_add(&my_list);
    list_basic_print(&my_list);
    list_basic_print_simple(&my_list);
    return 0;
}

variable_types: struct kool_list { int data; struct list_head { struct list_head *next; } list; }

user_defined_types: struct kool_list { int data; struct list_head list; }


decompiled_code:
void __fastcall list_basic_add(__int64 a1)
{
int i; // ebx
_QWORD *v2; // rax

for ( i = 0; i != 5; ++i )
{
v2 = malloc(0x18uLL);
*(_DWORD *)v2 = i;
list_add_tail(v2 + 1, a1 + 8);
}
}

canonical_decompiled_code:
void __fastcall func9(__int64 a1)
{
int i; // ebx
_QWORD *v2; // rax

for ( i = 0; i != 5; ++i )
{
v2 = malloc(0x18uLL);
*(_DWORD *)v2 = i;
func8(v2 + 1, a1 + 8);
}
}

original_code:
void list_basic_add(kool_list_t *list) {
    int i;
    kool_list_t *element;
    for (i = 0; i < 5; i++) {
 element = malloc(sizeof(kool_list_t));
 element->data = i;
 list_add_tail(&element->list, &list->list);
    }
}

canonical_original_code:
void list_basic_add(struct kool_list *list) {
    int i;
    struct kool_list *element;
    for (i = 0; i < 5; i++) {
 element = malloc(sizeof(kool_list_t));
 element->data = i;
 list_add_tail(&element->list, &list->list);
    }
}

variable_types: struct kool_list { int data; struct list_head { struct list_head *next; } list; } *


repo: EirSpace/Hera

decompiled_code:
__int64 __fastcall fc0012_writereg(__int64 a1, char a2, char a3)
{
char v4[10]; // [rsp+Eh] [rbp-Ah] BYREF

v4[0] = a2;
v4[1] = a3;
return (unsigned int)((int)rtlsdr_i2c_write_fn(a1, 198LL, v4, 2LL) >> 31);
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, char a2, char a3)
{
char v4[10]; // [rsp+Eh] [rbp-Ah] BYREF

v4[0] = a2;
v4[1] = a3;
return (unsigned int)((int)rtlsdr_i2c_write_fn(a1, 198LL, v4, 2LL) >> 31);
}

original_code:
static int fc0012_writereg(void *dev, uint8_t reg, uint8_t val)
{
 uint8_t data[2];
 data[0] = reg;
 data[1] = val;
 if (rtlsdr_i2c_write_fn(dev, 0xc6, data, 2) < 0)
  return -1;
 return 0;
}

canonical_original_code:
static int fc0012_writereg(void *dev, unsigned char reg, unsigned char val)
{
 unsigned char data[2];
 data[0] = reg;
 data[1] = val;
 if (rtlsdr_i2c_write_fn(dev, 0xc6, data, 2) < 0)
  return -1;
 return 0;
}

variable_types:
dev
void *

variable_types:
reg
unsigned char

variable_types:
val
unsigned char

variable_types:
data
unsigned char [2]


decompiled_code:
__int64 __fastcall fc0012_readreg(__int64 a1, char a2, _BYTE *a3)
{
char v5[25]; // [rsp+Fh] [rbp-19h] BYREF

v5[0] = a2;
if ( (int)rtlsdr_i2c_write_fn(a1, 198LL, v5, 1LL) < 0 || (int)rtlsdr_i2c_read_fn(a1, 198LL, v5, 1LL) < 0 )
return 0xFFFFFFFFLL;
*a3 = v5[0];
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, char a2, _BYTE *a3)
{
char v5[25]; // [rsp+Fh] [rbp-19h] BYREF

v5[0] = a2;
if ( (int)rtlsdr_i2c_write_fn(a1, 198LL, v5, 1LL) < 0 || (int)rtlsdr_i2c_read_fn(a1, 198LL, v5, 1LL) < 0 )
return 0xFFFFFFFFLL;
*a3 = v5[0];
return 0LL;
}

original_code:
static int fc0012_readreg(void *dev, uint8_t reg, uint8_t *val)
{
 uint8_t data = reg;
 if (rtlsdr_i2c_write_fn(dev, 0xc6, &data, 1) < 0)
  return -1;
 if (rtlsdr_i2c_read_fn(dev, 0xc6, &data, 1) < 0)
  return -1;
 *val = data;
 return 0;
}

canonical_original_code:
static int fc0012_readreg(void *dev, unsigned char reg, unsigned char *val)
{
 unsigned char data = reg;
 if (rtlsdr_i2c_write_fn(dev, 0xc6, &data, 1) < 0)
  return -1;
 if (rtlsdr_i2c_read_fn(dev, 0xc6, &data, 1) < 0)
  return -1;
 *val = data;
 return 0;
}

variable_types:
val
unsigned char *

variable_types:
data
unsigned char


variable_types: ret int

variable_types:
i
unsigned int

variable_types:
reg
unsigned char []


original_code:
int fc0012_set_params(void *dev, uint32_t freq, uint32_t bandwidth)
{
 int i, ret = 0;
 uint8_t reg[7], am, pm, multi, tmp;
 uint64_t f_vco;
 uint32_t xtal_freq_div_2;
 uint16_t xin, xdiv;
 int vco_select = 0;
 xtal_freq_div_2 = rtlsdr_get_tuner_clock(dev) / 2;
 if (freq < 37084000) {
  multi = 96;
  reg[5] = 0x82;
  reg[6] = 0x00;
 } else if (freq < 55625000) {
  multi = 64;
  reg[5] = 0x82;
  reg[6] = 0x02;
 } else if (freq < 74167000) {
  multi = 48;
  reg[5] = 0x42;
  reg[6] = 0x00;
 } else if (freq < 111250000) {
  multi = 32;
  reg[5] = 0x42;
  reg[6] = 0x02;
 } else if (freq < 148334000) {
  multi = 24;
  reg[5] = 0x22;
  reg[6] = 0x00;
 } else if (freq < 222500000) {
  multi = 16;
  reg[5] = 0x22;
  reg[6] = 0x02;
 } else if (freq < 296667000) {
  multi = 12;
  reg[5] = 0x12;
  reg[6] = 0x00;
 } else if (freq < 445000000) {
  multi = 8;
  reg[5] = 0x12;
  reg[6] = 0x02;
 } else if (freq < 593334000) {
  multi = 6;
  reg[5] = 0x0a;
  reg[6] = 0x00;
 } else {
  multi = 4;
  reg[5] = 0x0a;
  reg[6] = 0x02;
 }
 f_vco = freq * multi;
 if (f_vco >= 3060000000U) {
  reg[6] |= 0x08;
  vco_select = 1;
 }
 xdiv = (uint16_t)(f_vco / xtal_freq_div_2);
 if ((f_vco - xdiv * xtal_freq_div_2) >= (xtal_freq_div_2 / 2))
  xdiv++;
 pm = (uint8_t)(xdiv / 8);
 am = (uint8_t)(xdiv - (8 * pm));
 if (am < 2) {
  am += 8;
  pm--;
 }
 if (pm > 31) {
  reg[1] = am + (8 * (pm - 31));
  reg[2] = 31;
 } else {
  reg[1] = am;
  reg[2] = pm;
 }
 if ((reg[1] > 15) || (reg[2] < 0x0b)) {
  fprintf(stderr, "[FC0012] no valid PLL combination "
    "found for %u Hz!\n", freq);
  return -1;
 }
 reg[6] |= 0x20;
 xin = (uint16_t)((f_vco - (f_vco / xtal_freq_div_2) * xtal_freq_div_2) / 1000);
 xin = (xin << 15) / (xtal_freq_div_2 / 1000);
 if (xin >= 16384)
  xin += 32768;
 reg[3] = xin >> 8;
 reg[4] = xin & 0xff;
 reg[6] &= 0x3f;
 switch (bandwidth) {
 case 6000000:
  reg[6] |= 0x80;
  break;
 case 7000000:
  reg[6] |= 0x40;
  break;
 case 8000000:
 default:
  break;
 }
 reg[5] |= 0x07;
 for (i = 1; i <= 6; i++) {
  ret = fc0012_writereg(dev, i, reg[i]);
  if (ret)
   goto exit;
 }
 ret = fc0012_writereg(dev, 0x0e, 0x80);
 if (!ret)
  ret = fc0012_writereg(dev, 0x0e, 0x00);
 if (!ret)
  ret = fc0012_writereg(dev, 0x0e, 0x00);
 if (!ret) {
  ret = fc0012_readreg(dev, 0x0e, &tmp);
 }
 if (ret)
  goto exit;
 tmp &= 0x3f;
 if (vco_select) {
  if (tmp > 0x3c) {
   reg[6] &= ~0x08;
   ret = fc0012_writereg(dev, 0x06, reg[6]);
   if (!ret)
    ret = fc0012_writereg(dev, 0x0e, 0x80);
   if (!ret)
    ret = fc0012_writereg(dev, 0x0e, 0x00);
  }
 } else {
  if (tmp < 0x02) {
   reg[6] |= 0x08;
   ret = fc0012_writereg(dev, 0x06, reg[6]);
   if (!ret)
    ret = fc0012_writereg(dev, 0x0e, 0x80);
   if (!ret)
    ret = fc0012_writereg(dev, 0x0e, 0x00);
  }
 }
exit:
 return ret;
}

canonical_original_code:
int fc0012_set_params(void *dev, unsigned int freq, unsigned int bandwidth)
{
 int i; int ret = 0;
 unsigned char reg[7]; unsigned char am; unsigned char pm; unsigned char multi; unsigned char tmp;
 unsigned long f_vco;
 unsigned int xtal_freq_div_2;
 unsigned short xin; unsigned short xdiv;
 int vco_select = 0;
 xtal_freq_div_2 = rtlsdr_get_tuner_clock(dev) / 2;
 if (freq < 37084000) {
  multi = 96;
  reg[5] = 0x82;
  reg[6] = 0x00;
 } else if (freq < 55625000) {
  multi = 64;
  reg[5] = 0x82;
  reg[6] = 0x02;
 } else if (freq < 74167000) {
  multi = 48;
  reg[5] = 0x42;
  reg[6] = 0x00;
 } else if (freq < 111250000) {
  multi = 32;
  reg[5] = 0x42;
  reg[6] = 0x02;
 } else if (freq < 148334000) {
  multi = 24;
  reg[5] = 0x22;
  reg[6] = 0x00;
 } else if (freq < 222500000) {
  multi = 16;
  reg[5] = 0x22;
  reg[6] = 0x02;
 } else if (freq < 296667000) {
  multi = 12;
  reg[5] = 0x12;
  reg[6] = 0x00;
 } else if (freq < 445000000) {
  multi = 8;
  reg[5] = 0x12;
  reg[6] = 0x02;
 } else if (freq < 593334000) {
  multi = 6;
  reg[5] = 0x0a;
  reg[6] = 0x00;
 } else {
  multi = 4;
  reg[5] = 0x0a;
  reg[6] = 0x02;
 }
 f_vco = freq * multi;
 if (f_vco >= 3060000000U) {
  reg[6] |= 0x08;
  vco_select = 1;
 }
 xdiv = (unsigned short)(f_vco / xtal_freq_div_2);
 if ((f_vco - xdiv * xtal_freq_div_2) >= (xtal_freq_div_2 / 2))
  xdiv++;
 pm = (unsigned char)(xdiv / 8);
 am = (unsigned char)(xdiv - (8 * pm));
 if (am < 2) {
  am += 8;
  pm--;
 }
 if (pm > 31) {
  reg[1] = am + (8 * (pm - 31));
  reg[2] = 31;
 } else {
  reg[1] = am;
  reg[2] = pm;
 }
 if ((reg[1] > 15) || (reg[2] < 0x0b)) {
  fprintf(stderr, "[FC0012] no valid PLL combination "
    "found for %u Hz!\n", freq);
  return -1;
 }
 reg[6] |= 0x20;
 xin = (unsigned short)((f_vco - (f_vco / xtal_freq_div_2) * xtal_freq_div_2) / 1000);
 xin = (xin << 15) / (xtal_freq_div_2 / 1000);
 if (xin >= 16384)
  xin += 32768;
 reg[3] = xin >> 8;
 reg[4] = xin & 0xff;
 reg[6] &= 0x3f;
 switch (bandwidth) {
 case 6000000:
  reg[6] |= 0x80;
  break;
 case 7000000:
  reg[6] |= 0x40;
  break;
 case 8000000:
 default:
  break;
 }
 reg[5] |= 0x07;
 for (i = 1; i <= 6; i++) {
  ret = fc0012_writereg(dev, i, reg[i]);
  if (ret)
   goto exit;
 }
 ret = fc0012_writereg(dev, 0x0e, 0x80);
 if (!ret)
  ret = fc0012_writereg(dev, 0x0e, 0x00);
 if (!ret)
  ret = fc0012_writereg(dev, 0x0e, 0x00);
 if (!ret) {
  ret = fc0012_readreg(dev, 0x0e, &tmp);
 }
 if (ret)
  goto exit;
 tmp &= 0x3f;
 if (vco_select) {
  if (tmp > 0x3c) {
   reg[6] &= ~0x08;
   ret = fc0012_writereg(dev, 0x06, reg[6]);
   if (!ret)
    ret = fc0012_writereg(dev, 0x0e, 0x80);
   if (!ret)
    ret = fc0012_writereg(dev, 0x0e, 0x00);
  }
 } else {
  if (tmp < 0x02) {
   reg[6] |= 0x08;
   ret = fc0012_writereg(dev, 0x06, reg[6]);
   if (!ret)
    ret = fc0012_writereg(dev, 0x0e, 0x80);
   if (!ret)
    ret = fc0012_writereg(dev, 0x0e, 0x00);
  }
 }
exit:
 return ret;
}

variable_types:
freq
unsigned int

variable_types:
bandwidth
unsigned int

variable_types:
reg
unsigned char [7]

variable_types:
am
unsigned char

variable_types:
pm
unsigned char

variable_types:
multi
unsigned char

variable_types:
tmp
unsigned char

variable_types:
xin
unsigned short

variable_types:
xdiv
unsigned short


original_code:
int fc0012_set_gain(void *dev, int gain)
{
 int ret;
 uint8_t tmp = 0;
 ret = fc0012_readreg(dev, 0x13, &tmp);
 tmp &= 0xe0;
 switch (gain) {
 case -99:
  tmp |= 0x02;
  break;
 case -40:
  break;
 case 71:
  tmp |= 0x08;
  break;
 case 179:
  tmp |= 0x17;
  break;
 case 192:
 default:
  tmp |= 0x10;
  break;
 }
 ret = fc0012_writereg(dev, 0x13, tmp);
 return ret;
}

canonical_original_code:
int fc0012_set_gain(void *dev, int gain)
{
 int ret;
 unsigned char tmp = 0;
 ret = fc0012_readreg(dev, 0x13, &tmp);
 tmp &= 0xe0;
 switch (gain) {
 case -99:
  tmp |= 0x02;
  break;
 case -40:
  break;
 case 71:
  tmp |= 0x08;
  break;
 case 179:
  tmp |= 0x17;
  break;
 case 192:
 default:
  tmp |= 0x10;
  break;
 }
 ret = fc0012_writereg(dev, 0x13, tmp);
 return ret;
}

variable_types:
dev
void *

variable_types: gain int


decompiled_code:
__int64 __fastcall fc0013_writereg(__int64 a1, char a2, char a3)
{
char v4[10]; // [rsp+Eh] [rbp-Ah] BYREF

v4[0] = a2;
v4[1] = a3;
return (unsigned int)((int)rtlsdr_i2c_write_fn(a1, 198LL, v4, 2LL) >> 31);
}

original_code:
static int fc0013_writereg(void *dev, uint8_t reg, uint8_t val)
{
 uint8_t data[2];
 data[0] = reg;
 data[1] = val;
 if (rtlsdr_i2c_write_fn(dev, 0xc6, data, 2) < 0)
  return -1;
 return 0;
}

canonical_original_code:
static int fc0013_writereg(void *dev, unsigned char reg, unsigned char val)
{
 unsigned char data[2];
 data[0] = reg;
 data[1] = val;
 if (rtlsdr_i2c_write_fn(dev, 0xc6, data, 2) < 0)
  return -1;
 return 0;
}

variable_types:
reg
unsigned char

variable_types:
val
unsigned char

variable_types:
data
unsigned char [2]


decompiled_code:
__int64 __fastcall fc0013_readreg(__int64 a1, char a2, _BYTE *a3)
{
char v5[25]; // [rsp+Fh] [rbp-19h] BYREF

v5[0] = a2;
if ( (int)rtlsdr_i2c_write_fn(a1, 198LL, v5, 1LL) < 0 || (int)rtlsdr_i2c_read_fn(a1, 198LL, v5, 1LL) < 0 )
return 0xFFFFFFFFLL;
*a3 = v5[0];
return 0LL;
}

original_code:
static int fc0013_readreg(void *dev, uint8_t reg, uint8_t *val)
{
 uint8_t data = reg;
 if (rtlsdr_i2c_write_fn(dev, 0xc6, &data, 1) < 0)
  return -1;
 if (rtlsdr_i2c_read_fn(dev, 0xc6, &data, 1) < 0)
  return -1;
 *val = data;
 return 0;
}

canonical_original_code:
static int fc0013_readreg(void *dev, unsigned char reg, unsigned char *val)
{
 unsigned char data = reg;
 if (rtlsdr_i2c_write_fn(dev, 0xc6, &data, 1) < 0)
  return -1;
 if (rtlsdr_i2c_read_fn(dev, 0xc6, &data, 1) < 0)
  return -1;
 *val = data;
 return 0;
}

variable_types:
val
unsigned char *

variable_types:
data
unsigned char


decompiled_code:
__int64 __fastcall fc0013_set_vhf_track(__int64 a1, unsigned int a2)
{
__int64 result; // rax
char v3; // dl
char v4[25]; // [rsp+Fh] [rbp-19h] BYREF

result = fc0013_readreg(a1, 29, v4);
if ( !(_DWORD)result )
{
v3 = v4[0] & 0xE3;
v4[0] &= 0xE3u;
if ( a2 <= 0xA946F60 )
return fc0013_writereg(a1, 29, v3 | 0x1Cu);
if ( a2 <= 0xAFF3F20 )
return fc0013_writereg(a1, 29, v3 | 0x18u);
if ( a2 <= 0xB6A0EE0 )
return fc0013_writereg(a1, 29, v3 | 0x14u);
if ( a2 <= 0xBD4DEA0 )
return fc0013_writereg(a1, 29, v3 | 0x10u);
if ( a2 <= 0xC3FAE60 )
return fc0013_writereg(a1, 29, v3 | 0xCu);
if ( a2 <= 0xD154DE0 )
return fc0013_writereg(a1, 29, v3 | 8u);
if ( a2 > 0x11E1A2FF )
return fc0013_writereg(a1, 29, v3 | 0x1Cu);
result = fc0013_writereg(a1, 29, v3 | 4u);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, unsigned int a2)
{
__int64 result; // rax
char v3; // dl
char v4[25]; // [rsp+Fh] [rbp-19h] BYREF

result = func1(a1, 29, v4);
if ( !(_DWORD)result )
{
v3 = v4[0] & 0xE3;
v4[0] &= 0xE3u;
if ( a2 <= 0xA946F60 )
return func0(a1, 29, v3 | 0x1Cu);
if ( a2 <= 0xAFF3F20 )
return func0(a1, 29, v3 | 0x18u);
if ( a2 <= 0xB6A0EE0 )
return func0(a1, 29, v3 | 0x14u);
if ( a2 <= 0xBD4DEA0 )
return func0(a1, 29, v3 | 0x10u);
if ( a2 <= 0xC3FAE60 )
return func0(a1, 29, v3 | 0xCu);
if ( a2 <= 0xD154DE0 )
return func0(a1, 29, v3 | 8u);
if ( a2 > 0x11E1A2FF )
return func0(a1, 29, v3 | 0x1Cu);
result = func0(a1, 29, v3 | 4u);
}
return result;
}

original_code:
static int fc0013_set_vhf_track(void *dev, uint32_t freq)
{
 int ret;
 uint8_t tmp;
 ret = fc0013_readreg(dev, 0x1d, &tmp);
 if (ret)
  goto error_out;
 tmp &= 0xe3;
 if (freq <= 177500000) {
  ret = fc0013_writereg(dev, 0x1d, tmp | 0x1c);
 } else if (freq <= 184500000) {
  ret = fc0013_writereg(dev, 0x1d, tmp | 0x18);
 } else if (freq <= 191500000) {
  ret = fc0013_writereg(dev, 0x1d, tmp | 0x14);
 } else if (freq <= 198500000) {
  ret = fc0013_writereg(dev, 0x1d, tmp | 0x10);
 } else if (freq <= 205500000) {
  ret = fc0013_writereg(dev, 0x1d, tmp | 0x0c);
 } else if (freq <= 219500000) {
  ret = fc0013_writereg(dev, 0x1d, tmp | 0x08);
 } else if (freq < 300000000) {
  ret = fc0013_writereg(dev, 0x1d, tmp | 0x04);
 } else {
  ret = fc0013_writereg(dev, 0x1d, tmp | 0x1c);
 }
error_out:
 return ret;
}

canonical_original_code:
static int fc0013_set_vhf_track(void *dev, unsigned int freq)
{
 int ret;
 unsigned char tmp;
 ret = fc0013_readreg(dev, 0x1d, &tmp);
 if (ret)
  goto error_out;
 tmp &= 0xe3;
 if (freq <= 177500000) {
  ret = fc0013_writereg(dev, 0x1d, tmp | 0x1c);
 } else if (freq <= 184500000) {
  ret = fc0013_writereg(dev, 0x1d, tmp | 0x18);
 } else if (freq <= 191500000) {
  ret = fc0013_writereg(dev, 0x1d, tmp | 0x14);
 } else if (freq <= 198500000) {
  ret = fc0013_writereg(dev, 0x1d, tmp | 0x10);
 } else if (freq <= 205500000) {
  ret = fc0013_writereg(dev, 0x1d, tmp | 0x0c);
 } else if (freq <= 219500000) {
  ret = fc0013_writereg(dev, 0x1d, tmp | 0x08);
 } else if (freq < 300000000) {
  ret = fc0013_writereg(dev, 0x1d, tmp | 0x04);
 } else {
  ret = fc0013_writereg(dev, 0x1d, tmp | 0x1c);
 }
error_out:
 return ret;
}

variable_types: ret int


decompiled_code:
__int64 __fastcall fc0013_rc_cal_add(__int64 a1, int a2)
{
__int64 result; // rax
unsigned __int8 v3; // r12
int v4; // edx
char v5[25]; // [rsp+Fh] [rbp-19h] BYREF

result = fc0013_writereg(a1, 16, 0);
if ( !(_DWORD)result )
{
result = fc0013_readreg(a1, 16, v5);
if ( !(_DWORD)result )
{
v3 = v5[0] & 0xF;
v5[0] &= 0xFu;
result = fc0013_writereg(a1, 13, 17);
if ( !(_DWORD)result )
{
v4 = a2 + v3;
if ( v4 > 15 )
{
result = fc0013_writereg(a1, 16, 15);
}
else if ( v4 < 0 )
{
result = fc0013_writereg(a1, 16, 0);
}
else
{
result = fc0013_writereg(a1, 16, v4);
}
}
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1, int a2)
{
__int64 result; // rax
unsigned __int8 v3; // r12
int v4; // edx
char v5[25]; // [rsp+Fh] [rbp-19h] BYREF

result = func0(a1, 16, 0);
if ( !(_DWORD)result )
{
result = func1(a1, 16, v5);
if ( !(_DWORD)result )
{
v3 = v5[0] & 0xF;
v5[0] &= 0xFu;
result = func0(a1, 13, 17);
if ( !(_DWORD)result )
{
v4 = a2 + v3;
if ( v4 > 15 )
{
result = func0(a1, 16, 15);
}
else if ( v4 < 0 )
{
result = func0(a1, 16, 0);
}
else
{
result = func0(a1, 16, v4);
}
}
}
}
return result;
}

original_code:
int fc0013_rc_cal_add(void *dev, int rc_val)
{
 int ret;
 uint8_t rc_cal;
 int val;
 ret = fc0013_writereg(dev, 0x10, 0x00);
 if (ret)
  goto error_out;
 ret = fc0013_readreg(dev, 0x10, &rc_cal);
 if (ret)
  goto error_out;
 rc_cal &= 0x0f;
 val = (int)rc_cal + rc_val;
 ret = fc0013_writereg(dev, 0x0d, 0x11);
 if (ret)
  goto error_out;
 if (val > 15)
  ret = fc0013_writereg(dev, 0x10, 0x0f);
 else if (val < 0)
  ret = fc0013_writereg(dev, 0x10, 0x00);
 else
  ret = fc0013_writereg(dev, 0x10, (uint8_t)val);
error_out:
 return ret;
}

canonical_original_code:
int fc0013_rc_cal_add(void *dev, int rc_val)
{
 int ret;
 unsigned char rc_cal;
 int val;
 ret = fc0013_writereg(dev, 0x10, 0x00);
 if (ret)
  goto error_out;
 ret = fc0013_readreg(dev, 0x10, &rc_cal);
 if (ret)
  goto error_out;
 rc_cal &= 0x0f;
 val = (int)rc_cal + rc_val;
 ret = fc0013_writereg(dev, 0x0d, 0x11);
 if (ret)
  goto error_out;
 if (val > 15)
  ret = fc0013_writereg(dev, 0x10, 0x0f);
 else if (val < 0)
  ret = fc0013_writereg(dev, 0x10, 0x00);
 else
  ret = fc0013_writereg(dev, 0x10, (unsigned char)val);
error_out:
 return ret;
}

variable_types: val int


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

result = fc0013_writereg(a1, 13, 1);
if ( !(_DWORD)result )
result = fc0013_writereg(a1, 16, 0);
return result;
}

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

result = func0(a1, 13, 1);
if ( !(_DWORD)result )
result = func0(a1, 16, 0);
return result;
}

original_code:
int fc0013_rc_cal_reset(void *dev)
{
 int ret;
 ret = fc0013_writereg(dev, 0x0d, 0x01);
 if (!ret)
  ret = fc0013_writereg(dev, 0x10, 0x00);
 return ret;
}


original_code:
int fc0013_set_params(void *dev, uint32_t freq, uint32_t bandwidth)
{
 int i, ret = 0;
 uint8_t reg[7], am, pm, multi, tmp;
 uint64_t f_vco;
 uint32_t xtal_freq_div_2;
 uint16_t xin, xdiv;
 int vco_select = 0;
 xtal_freq_div_2 = rtlsdr_get_tuner_clock(dev) / 2;
 ret = fc0013_set_vhf_track(dev, freq);
 if (ret)
  goto exit;
 if (freq < 300000000) {
  ret = fc0013_readreg(dev, 0x07, &tmp);
  if (ret)
   goto exit;
  ret = fc0013_writereg(dev, 0x07, tmp | 0x10);
  if (ret)
   goto exit;
  ret = fc0013_readreg(dev, 0x14, &tmp);
  if (ret)
   goto exit;
  ret = fc0013_writereg(dev, 0x14, tmp & 0x1f);
  if (ret)
   goto exit;
 } else if (freq <= 862000000) {
  ret = fc0013_readreg(dev, 0x07, &tmp);
  if (ret)
   goto exit;
  ret = fc0013_writereg(dev, 0x07, tmp & 0xef);
  if (ret)
   goto exit;
  ret = fc0013_readreg(dev, 0x14, &tmp);
  if (ret)
   goto exit;
  ret = fc0013_writereg(dev, 0x14, (tmp & 0x1f) | 0x40);
  if (ret)
   goto exit;
 } else {
  ret = fc0013_readreg(dev, 0x07, &tmp);
  if (ret)
   goto exit;
  ret = fc0013_writereg(dev, 0x07, tmp & 0xef);
  if (ret)
   goto exit;
  ret = fc0013_readreg(dev, 0x14, &tmp);
  if (ret)
   goto exit;
  ret = fc0013_writereg(dev, 0x14, (tmp & 0x1f) | 0x20);
  if (ret)
   goto exit;
 }
 if (freq < 37084000) {
  multi = 96;
  reg[5] = 0x82;
  reg[6] = 0x00;
 } else if (freq < 55625000) {
  multi = 64;
  reg[5] = 0x02;
  reg[6] = 0x02;
 } else if (freq < 74167000) {
  multi = 48;
  reg[5] = 0x42;
  reg[6] = 0x00;
 } else if (freq < 111250000) {
  multi = 32;
  reg[5] = 0x82;
  reg[6] = 0x02;
 } else if (freq < 148334000) {
  multi = 24;
  reg[5] = 0x22;
  reg[6] = 0x00;
 } else if (freq < 222500000) {
  multi = 16;
  reg[5] = 0x42;
  reg[6] = 0x02;
 } else if (freq < 296667000) {
  multi = 12;
  reg[5] = 0x12;
  reg[6] = 0x00;
 } else if (freq < 445000000) {
  multi = 8;
  reg[5] = 0x22;
  reg[6] = 0x02;
 } else if (freq < 593334000) {
  multi = 6;
  reg[5] = 0x0a;
  reg[6] = 0x00;
 } else if (freq < 950000000) {
  multi = 4;
  reg[5] = 0x12;
  reg[6] = 0x02;
 } else {
  multi = 2;
  reg[5] = 0x0a;
  reg[6] = 0x02;
 }
 f_vco = freq * multi;
 if (f_vco >= 3060000000U) {
  reg[6] |= 0x08;
  vco_select = 1;
 }
 xdiv = (uint16_t)(f_vco / xtal_freq_div_2);
 if ((f_vco - xdiv * xtal_freq_div_2) >= (xtal_freq_div_2 / 2))
  xdiv++;
 pm = (uint8_t)(xdiv / 8);
 am = (uint8_t)(xdiv - (8 * pm));
 if (am < 2) {
  am += 8;
  pm--;
 }
 if (pm > 31) {
  reg[1] = am + (8 * (pm - 31));
  reg[2] = 31;
 } else {
  reg[1] = am;
  reg[2] = pm;
 }
 if ((reg[1] > 15) || (reg[2] < 0x0b)) {
  fprintf(stderr, "[FC0013] no valid PLL combination "
    "found for %u Hz!\n", freq);
  return -1;
 }
 reg[6] |= 0x20;
 xin = (uint16_t)((f_vco - (f_vco / xtal_freq_div_2) * xtal_freq_div_2) / 1000);
 xin = (xin << 15) / (xtal_freq_div_2 / 1000);
 if (xin >= 16384)
  xin += 32768;
 reg[3] = xin >> 8;
 reg[4] = xin & 0xff;
 reg[6] &= 0x3f;
 switch (bandwidth) {
 case 6000000:
  reg[6] |= 0x80;
  break;
 case 7000000:
  reg[6] |= 0x40;
  break;
 case 8000000:
 default:
  break;
 }
 reg[5] |= 0x07;
 for (i = 1; i <= 6; i++) {
  ret = fc0013_writereg(dev, i, reg[i]);
  if (ret)
   goto exit;
 }
 ret = fc0013_readreg(dev, 0x11, &tmp);
 if (ret)
  goto exit;
 if (multi == 64)
  ret = fc0013_writereg(dev, 0x11, tmp | 0x04);
 else
  ret = fc0013_writereg(dev, 0x11, tmp & 0xfb);
 if (ret)
  goto exit;
 ret = fc0013_writereg(dev, 0x0e, 0x80);
 if (!ret)
  ret = fc0013_writereg(dev, 0x0e, 0x00);
 if (!ret)
  ret = fc0013_writereg(dev, 0x0e, 0x00);
 if (!ret) {
  ret = fc0013_readreg(dev, 0x0e, &tmp);
 }
 if (ret)
  goto exit;
 tmp &= 0x3f;
 if (vco_select) {
  if (tmp > 0x3c) {
   reg[6] &= ~0x08;
   ret = fc0013_writereg(dev, 0x06, reg[6]);
   if (!ret)
    ret = fc0013_writereg(dev, 0x0e, 0x80);
   if (!ret)
    ret = fc0013_writereg(dev, 0x0e, 0x00);
  }
 } else {
  if (tmp < 0x02) {
   reg[6] |= 0x08;
   ret = fc0013_writereg(dev, 0x06, reg[6]);
   if (!ret)
    ret = fc0013_writereg(dev, 0x0e, 0x80);
   if (!ret)
    ret = fc0013_writereg(dev, 0x0e, 0x00);
  }
 }
exit:
 return ret;
}

canonical_original_code:
int fc0013_set_params(void *dev, unsigned int freq, unsigned int bandwidth)
{
 int i; int ret = 0;
 unsigned char reg[7]; unsigned char am; unsigned char pm; unsigned char multi; unsigned char tmp;
 unsigned long f_vco;
 unsigned int xtal_freq_div_2;
 unsigned short xin; unsigned short xdiv;
 int vco_select = 0;
 xtal_freq_div_2 = rtlsdr_get_tuner_clock(dev) / 2;
 ret = fc0013_set_vhf_track(dev, freq);
 if (ret)
  goto exit;
 if (freq < 300000000) {
  ret = fc0013_readreg(dev, 0x07, &tmp);
  if (ret)
   goto exit;
  ret = fc0013_writereg(dev, 0x07, tmp | 0x10);
  if (ret)
   goto exit;
  ret = fc0013_readreg(dev, 0x14, &tmp);
  if (ret)
   goto exit;
  ret = fc0013_writereg(dev, 0x14, tmp & 0x1f);
  if (ret)
   goto exit;
 } else if (freq <= 862000000) {
  ret = fc0013_readreg(dev, 0x07, &tmp);
  if (ret)
   goto exit;
  ret = fc0013_writereg(dev, 0x07, tmp & 0xef);
  if (ret)
   goto exit;
  ret = fc0013_readreg(dev, 0x14, &tmp);
  if (ret)
   goto exit;
  ret = fc0013_writereg(dev, 0x14, (tmp & 0x1f) | 0x40);
  if (ret)
   goto exit;
 } else {
  ret = fc0013_readreg(dev, 0x07, &tmp);
  if (ret)
   goto exit;
  ret = fc0013_writereg(dev, 0x07, tmp & 0xef);
  if (ret)
   goto exit;
  ret = fc0013_readreg(dev, 0x14, &tmp);
  if (ret)
   goto exit;
  ret = fc0013_writereg(dev, 0x14, (tmp & 0x1f) | 0x20);
  if (ret)
   goto exit;
 }
 if (freq < 37084000) {
  multi = 96;
  reg[5] = 0x82;
  reg[6] = 0x00;
 } else if (freq < 55625000) {
  multi = 64;
  reg[5] = 0x02;
  reg[6] = 0x02;
 } else if (freq < 74167000) {
  multi = 48;
  reg[5] = 0x42;
  reg[6] = 0x00;
 } else if (freq < 111250000) {
  multi = 32;
  reg[5] = 0x82;
  reg[6] = 0x02;
 } else if (freq < 148334000) {
  multi = 24;
  reg[5] = 0x22;
  reg[6] = 0x00;
 } else if (freq < 222500000) {
  multi = 16;
  reg[5] = 0x42;
  reg[6] = 0x02;
 } else if (freq < 296667000) {
  multi = 12;
  reg[5] = 0x12;
  reg[6] = 0x00;
 } else if (freq < 445000000) {
  multi = 8;
  reg[5] = 0x22;
  reg[6] = 0x02;
 } else if (freq < 593334000) {
  multi = 6;
  reg[5] = 0x0a;
  reg[6] = 0x00;
 } else if (freq < 950000000) {
  multi = 4;
  reg[5] = 0x12;
  reg[6] = 0x02;
 } else {
  multi = 2;
  reg[5] = 0x0a;
  reg[6] = 0x02;
 }
 f_vco = freq * multi;
 if (f_vco >= 3060000000U) {
  reg[6] |= 0x08;
  vco_select = 1;
 }
 xdiv = (unsigned short)(f_vco / xtal_freq_div_2);
 if ((f_vco - xdiv * xtal_freq_div_2) >= (xtal_freq_div_2 / 2))
  xdiv++;
 pm = (unsigned char)(xdiv / 8);
 am = (unsigned char)(xdiv - (8 * pm));
 if (am < 2) {
  am += 8;
  pm--;
 }
 if (pm > 31) {
  reg[1] = am + (8 * (pm - 31));
  reg[2] = 31;
 } else {
  reg[1] = am;
  reg[2] = pm;
 }
 if ((reg[1] > 15) || (reg[2] < 0x0b)) {
  fprintf(stderr, "[FC0013] no valid PLL combination "
    "found for %u Hz!\n", freq);
  return -1;
 }
 reg[6] |= 0x20;
 xin = (unsigned short)((f_vco - (f_vco / xtal_freq_div_2) * xtal_freq_div_2) / 1000);
 xin = (xin << 15) / (xtal_freq_div_2 / 1000);
 if (xin >= 16384)
  xin += 32768;
 reg[3] = xin >> 8;
 reg[4] = xin & 0xff;
 reg[6] &= 0x3f;
 switch (bandwidth) {
 case 6000000:
  reg[6] |= 0x80;
  break;
 case 7000000:
  reg[6] |= 0x40;
  break;
 case 8000000:
 default:
  break;
 }
 reg[5] |= 0x07;
 for (i = 1; i <= 6; i++) {
  ret = fc0013_writereg(dev, i, reg[i]);
  if (ret)
   goto exit;
 }
 ret = fc0013_readreg(dev, 0x11, &tmp);
 if (ret)
  goto exit;
 if (multi == 64)
  ret = fc0013_writereg(dev, 0x11, tmp | 0x04);
 else
  ret = fc0013_writereg(dev, 0x11, tmp & 0xfb);
 if (ret)
  goto exit;
 ret = fc0013_writereg(dev, 0x0e, 0x80);
 if (!ret)
  ret = fc0013_writereg(dev, 0x0e, 0x00);
 if (!ret)
  ret = fc0013_writereg(dev, 0x0e, 0x00);
 if (!ret) {
  ret = fc0013_readreg(dev, 0x0e, &tmp);
 }
 if (ret)
  goto exit;
 tmp &= 0x3f;
 if (vco_select) {
  if (tmp > 0x3c) {
   reg[6] &= ~0x08;
   ret = fc0013_writereg(dev, 0x06, reg[6]);
   if (!ret)
    ret = fc0013_writereg(dev, 0x0e, 0x80);
   if (!ret)
    ret = fc0013_writereg(dev, 0x0e, 0x00);
  }
 } else {
  if (tmp < 0x02) {
   reg[6] |= 0x08;
   ret = fc0013_writereg(dev, 0x06, reg[6]);
   if (!ret)
    ret = fc0013_writereg(dev, 0x0e, 0x80);
   if (!ret)
    ret = fc0013_writereg(dev, 0x0e, 0x00);
  }
 }
exit:
 return ret;
}

variable_types:
freq
unsigned int

variable_types:
bandwidth
unsigned int

variable_types: i int


decompiled_code:
__int64 __fastcall fc0013_set_gain_mode(__int64 a1, int a2)
{
int v2; // ebp
char v3; // dl
int v4; // ebx
char v6[41]; // [rsp+Fh] [rbp-29h] BYREF

v6[0] = 0;
v2 = fc0013_readreg(a1, 13, v6);
if ( a2 )
v3 = v6[0] | 8;
else
v3 = v6[0] & 0xF7;
v6[0] = v3;
v4 = fc0013_writereg(a1, 13, v3);
return v2 | v4 | (unsigned int)fc0013_writereg(a1, 19, 10);
}

original_code:
int fc0013_set_gain_mode(void *dev, int manual)
{
 int ret = 0;
 uint8_t tmp = 0;
 ret |= fc0013_readreg(dev, 0x0d, &tmp);
 if (manual)
  tmp |= (1 << 3);
 else
  tmp &= ~(1 << 3);
 ret |= fc0013_writereg(dev, 0x0d, tmp);
 ret |= fc0013_writereg(dev, 0x13, 0x0a);
 return ret;
}

canonical_original_code:
int fc0013_set_gain_mode(void *dev, int manual)
{
 int ret = 0;
 unsigned char tmp = 0;
 ret |= fc0013_readreg(dev, 0x0d, &tmp);
 if (manual)
  tmp |= (1 << 3);
 else
  tmp &= ~(1 << 3);
 ret |= fc0013_writereg(dev, 0x0d, tmp);
 ret |= fc0013_writereg(dev, 0x13, 0x0a);
 return ret;
}

variable_types: manual int


decompiled_code:
__int64 __fastcall fc0013_set_lna_gain(__int64 a1, int a2)
{
__int64 v3; // rsi
int v4; // ebx
__int64 v5; // rax
int v6; // esi
bool v7; // cl
bool v8; // dl
char v10[25]; // [rsp+Fh] [rbp-19h] BYREF

v10[0] = 0;
v3 = 1LL;
v4 = fc0013_readreg(a1, 20, v10);
if ( a2 > fc0013_lna_gains[0] )
{
v5 = 1LL;
do
{
v6 = 2 * v5;
v7 = fc0013_lna_gains[2 * v5] >= a2;
v8 = (_DWORD)v5++ == 23;
}
while ( !v8 && !v7 );
v3 = (unsigned int)(v6 + 1);
}
return v4 | (unsigned int)fc0013_writereg(a1, 20, LOBYTE(fc0013_lna_gains[v3]) | (unsigned __int8)(v10[0] & 0xE0));
}

canonical_decompiled_code:
__int64 __fastcall func8(__int64 a1, int a2)
{
__int64 v3; // rsi
int v4; // ebx
__int64 v5; // rax
int v6; // esi
bool v7; // cl
bool v8; // dl
char v10[25]; // [rsp+Fh] [rbp-19h] BYREF

v10[0] = 0;
v3 = 1LL;
v4 = func1(a1, 20, v10);
if ( a2 > fc0013_lna_gains[0] )
{
v5 = 1LL;
do
{
v6 = 2 * v5;
v7 = fc0013_lna_gains[2 * v5] >= a2;
v8 = (_DWORD)v5++ == 23;
}
while ( !v8 && !v7 );
v3 = (unsigned int)(v6 + 1);
}
return v4 | (unsigned int)func0(a1, 20, LOBYTE(fc0013_lna_gains[v3]) | (unsigned __int8)(v10[0] & 0xE0));
}

original_code:
int fc0013_set_lna_gain(void *dev, int gain)
{
 int ret = 0;
 unsigned int i;
 uint8_t tmp = 0;
 ret |= fc0013_readreg(dev, 0x14, &tmp);
 tmp &= 0xe0;
 for (i = 0; i < (sizeof(fc0013_lna_gains) / sizeof(int) / 2); i++) {
  if ((fc0013_lna_gains[i*2] >= gain) || (i+1 == (sizeof(fc0013_lna_gains) / sizeof(int) / 2))) {
   tmp |= fc0013_lna_gains[i*2 + 1];
   break;
  }
 }
 ret |= fc0013_writereg(dev, 0x14, tmp);
 return ret;
}

canonical_original_code:
int fc0013_set_lna_gain(void *dev, int gain)
{
 int ret = 0;
 unsigned int i;
 unsigned char tmp = 0;
 ret |= fc0013_readreg(dev, 0x14, &tmp);
 tmp &= 0xe0;
 for (i = 0; i < (sizeof(fc0013_lna_gains) / sizeof(int) / 2); i++) {
  if ((fc0013_lna_gains[i*2] >= gain) || (i+1 == (sizeof(fc0013_lna_gains) / sizeof(int) / 2))) {
   tmp |= fc0013_lna_gains[i*2 + 1];
   break;
  }
 }
 ret |= fc0013_writereg(dev, 0x14, tmp);
 return ret;
}

variable_types:
i
unsigned int