compareIndividuals

decompiled_code:
__int64 __fastcall compareIndividuals(__int64 a1, __int64 a2)
{
return (unsigned int)(int)(*(double *)(a1 + 8) - *(double *)(a2 + 8));
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1, __int64 a2)
{
return (unsigned int)(int)(*(double *)(a1 + 8) - *(double *)(a2 + 8));
}

original_code:
int compareIndividuals(const void *a, const void *b)
{
 const t_individual *c = a;
 const t_individual *d = b;
 return c->fitness - d->fitness;
}

canonical_original_code:
int compareIndividuals(void *a, void *b)
{
 struct s_individual *c = a;
 struct s_individual *d = b;
 return c->fitness - d->fitness;
}

variable_types:
a
void *

variable_types:
b
void *

variable_types: struct s_individual { unsigned char *var; double fitness; } *


main

canonical_name: main

repo: mgmillani/maxsat-GenAlg

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int v3; // eax
const char **v4; // rbx
clock_t v5; // r13
clock_t v6; // rbp
double v8; // [rsp+0h] [rbp-58h]
double v9; // [rsp+8h] [rbp-50h]
char v10[24]; // [rsp+10h] [rbp-48h] BYREF
int v11; // [rsp+28h] [rbp-30h]

v3 = time(0LL);
srand(v3);
if ( argc > 1 )
{
v4 = argv + 1;
do
{
satLoadInstance(v10, *v4);
v5 = clock();
v9 = (double)(int)geneticAlgorithmSat(v10, 100LL, 60LL, 0.1) + 0.0;
v6 = clock() - v5;
v8 = (double)(int)satAmountSatisfied(v10) + 0.0;
fprintf(stderr, "Result: %s\n", *v4);
fprintf(stderr, "Initial: %lf (%lf%%)\n", v9, v9 * 100.0 / (double)v11);
fprintf(stderr, "Amount satisfied: %lf\n", v8);
fprintf(stderr, "Percent satisfied: %lf\n", v8 / (double)v11);
fprintf(stderr, "Delay: %lu clocks = %lf s\n", v6, (double)(int)v6 / 1000000.0);
fwrite("####\n####\n", 1uLL, 0xAuLL, stderr);
++v4;
}
while ( &argv[(unsigned int)(argc - 2) + 2] != v4 );
}
return 0;
}

original_code:
int main(int argc, char *argv[])
{
 srand(time(((void *)0)));
 int i;
 for(i=1 ; i<argc ; i++)
 {
  t_instance inst;
  satLoadInstance(&inst,argv[i]);
  unsigned int j;
  clock_t tavg = 0;
  double satisfyAverage = 0;
  double iniAvg = 0;
  unsigned int k;
  satisfyAverage = 0;
  unsigned int step = 5;
  unsigned int repeat = 10;
  for(j=1 ; j<2 ; j++)
  {
   unsigned int k;
   satisfyAverage = 0;
    clock_t t0 = clock();
    iniAvg += geneticAlgorithmSat(&inst,100,60,0.1);
    tavg += clock() - t0;
    satisfyAverage += satAmountSatisfied(&inst);
  }
  fprintf(stderr,"Result: %s\n",argv[i]);;
  fprintf(stderr,"Initial: %lf (%lf%%)\n",iniAvg,100*iniAvg/inst.numClauses);
  fprintf(stderr,"Amount satisfied: %lf\n",satisfyAverage);;
  fprintf(stderr,"Percent satisfied: %lf\n",(double)satisfyAverage/inst.numClauses);;
  fprintf(stderr,"Delay: %lu clocks = %lf s\n",tavg,(double)(tavg)/((__clock_t) 1000000));;
  fprintf(stderr,"####\n####\n");;
 }
 return 0;
}

canonical_original_code:
int main(int argc, char *argv[])
{
 srand(time(((void *)0)));
 int i;
 for(i=1 ; i<argc ; i++)
 {
  struct s_instance inst;
  satLoadInstance(&inst,argv[i]);
  unsigned int j;
  long tavg = 0;
  double satisfyAverage = 0;
  double iniAvg = 0;
  unsigned int k;
  satisfyAverage = 0;
  unsigned int step = 5;
  unsigned int repeat = 10;
  for(j=1 ; j<2 ; j++)
  {
   unsigned int k;
   satisfyAverage = 0;
    long t0 = clock();
    iniAvg += geneticAlgorithmSat(&inst,100,60,0.1);
    tavg += clock() - t0;
    satisfyAverage += satAmountSatisfied(&inst);
  }
  fprintf(stderr,"Result: %s\n",argv[i]);;
  fprintf(stderr,"Initial: %lf (%lf%%)\n",iniAvg,100*iniAvg/inst.numClauses);
  fprintf(stderr,"Amount satisfied: %lf\n",satisfyAverage);;
  fprintf(stderr,"Percent satisfied: %lf\n",(double)satisfyAverage/inst.numClauses);;
  fprintf(stderr,"Delay: %lu clocks = %lf s\n",tavg,(double)(tavg)/((long) 1000000));;
  fprintf(stderr,"####\n####\n");;
 }
 return 0;
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types: i int

variable_types: struct s_instance { unsigned char *var; unsigned int numVars; struct s_clause { unsigned int *var; unsigned char *signal; unsigned int size; } *clause; unsigned int numClauses; }

variable_types:
j
unsigned int

variable_types: tavg long

variable_types: satisfyAverage double

variable_types: iniAvg double

variable_types:
k
unsigned int

variable_types:
step
unsigned int

variable_types:
repeat
unsigned int

return_type: int

user_defined_types: struct s_instance { unsigned char *var; unsigned int numVars; struct s_clause *clause; unsigned int numClauses; }


satPrintVars

decompiled_code:
int __fastcall satPrintVars(__int64 a1)
{
unsigned int v1; // ebx
int result; // eax

if ( *(_DWORD *)(a1 + 8) )
{
v1 = 0;
do
{
result = printf("X%u = %u\n", v1, *(unsigned __int8 *)(*(_QWORD *)a1 + v1));
++v1;
}
while ( *(_DWORD *)(a1 + 8) > v1 );
}
return result;
}

canonical_decompiled_code:
int __fastcall func0(__int64 a1)
{
unsigned int v1; // ebx
int result; // eax

if ( *(_DWORD *)(a1 + 8) )
{
v1 = 0;
do
{
result = printf("X%u = %u\n", v1, *(unsigned __int8 *)(*(_QWORD *)a1 + v1));
++v1;
}
while ( *(_DWORD *)(a1 + 8) > v1 );
}
return result;
}

original_code:
void satPrintVars(t_instance *inst)
{
 unsigned int i;
 for(i=0 ; i<inst->numVars ; i++)
 {
  printf("X%u = %u\n",i,(unsigned int)inst->var[i]);
 }
}

canonical_original_code:
void satPrintVars(struct s_instance *inst)
{
 unsigned int i;
 for(i=0 ; i<inst->numVars ; i++)
 {
  printf("X%u = %u\n",i,(unsigned int)inst->var[i]);
 }
}

variable_types: struct s_instance { unsigned char *var; unsigned int numVars; struct s_clause { unsigned int *var; unsigned char *signal; unsigned int size; } *clause; unsigned int numClauses; } *

variable_types:
i
unsigned int

return_type: void


satAmountSatisfied

original_code:
unsigned int satAmountSatisfied(t_instance *inst)
{
 unsigned int i;
 unsigned int satisfied = 0;
 for(i=0 ; i<inst->numClauses ; i++)
 {
  unsigned int j;
  unsigned int sum = 0;
  t_clause *c = inst->clause+i;
  for(j=0 ; j<c->size ; j++)
  {
   sum += inst->var[c->var[j]] ^ c->signal[j];
  }
  if(sum!=0)
   satisfied++;
 }
 return satisfied;
}

canonical_original_code:
unsigned int satAmountSatisfied(struct s_instance *inst)
{
 unsigned int i;
 unsigned int satisfied = 0;
 for(i=0 ; i<inst->numClauses ; i++)
 {
  unsigned int j;
  unsigned int sum = 0;
  struct s_clause *c = inst->clause+i;
  for(j=0 ; j<c->size ; j++)
  {
   sum += inst->var[c->var[j]] ^ c->signal[j];
  }
  if(sum!=0)
   satisfied++;
 }
 return satisfied;
}

variable_types:
satisfied
unsigned int

variable_types:
sum
unsigned int

variable_types: struct s_clause { unsigned int *var; unsigned char *signal; unsigned int size; } *

return_type: unsigned int


satPercentSatisfied

decompiled_code:
double __fastcall satPercentSatisfied(__int64 a1)
{
return (double)(int)satAmountSatisfied(a1) * 100.0 / (double)*(int *)(a1 + 24);
}

canonical_decompiled_code:
double __fastcall func2(__int64 a1)
{
return (double)(int)func1(a1) * 100.0 / (double)*(int *)(a1 + 24);
}

original_code:
double satPercentSatisfied(t_instance *inst)
{
 return 100.0*(double)satAmountSatisfied(inst)/inst->numClauses;
}

canonical_original_code:
double satPercentSatisfied(struct s_instance *inst)
{
 return 100.0*(double)satAmountSatisfied(inst)/inst->numClauses;
}

return_type: double

user_defined_types: struct s_clause { unsigned int *var; unsigned char *signal; unsigned int size; }


makeGlpkData

original_code:
void makeGlpkData(t_instance *inst)
{
 printf("data;\n");
 printf("set Clauses := ");
 unsigned int i;
 for(i=1 ; i<=inst->numClauses ; i++)
  printf("%u ",i);
 printf(";\n");
 printf("set Variables := ");
 for(i=1 ; i<=inst->numVars ; i++)
  printf("%u ",i);
 printf(";\n");
 printf("param Pos := \n");
 for(i=0 ; i<inst->numVars ; i++)
 {
  unsigned int j;
  for(j=0 ; j < inst->numClauses ; j++)
  {
   t_clause clause = inst->clause[j];
   unsigned int k;
   char found = 0;
   for(k=0 ; k<clause.size ; k++)
   {
    if(clause.var[k] == (i))
    {
     if(clause.signal[k] == 0)
      printf("%u %u 1\n",i+1,j+1);
     else
      printf("%u %u 0\n",i+1,j+1);
     found = 1;
     break;
    }
   }
   if(!found)
    printf("%u %u 0\n",i+1,j+1);
  }
 }
 printf("\n;");
 printf("param Neg := \n");
 for(i=0 ; i<inst->numVars ; i++)
 {
  unsigned int j;
  for(j=0 ; j < inst->numClauses ; j++)
  {
   t_clause clause = inst->clause[j];
   unsigned int k;
   char found = 0;
   for(k=0 ; k<clause.size ; k++)
   {
    if(clause.var[k] == (i))
    {
     if(clause.signal[k] == 1)
      printf("%u %u 1\n",i+1,j+1);
     else
      printf("%u %u 0\n",i+1,j+1);
     found = 1;
     break;
    }
   }
   if(!found)
    printf("%u %u 0\n",i+1,j+1);
  }
 }
 printf("\n;");
}

canonical_original_code:
void makeGlpkData(struct s_instance *inst)
{
 printf("data;\n");
 printf("set Clauses := ");
 unsigned int i;
 for(i=1 ; i<=inst->numClauses ; i++)
  printf("%u ",i);
 printf(";\n");
 printf("set Variables := ");
 for(i=1 ; i<=inst->numVars ; i++)
  printf("%u ",i);
 printf(";\n");
 printf("param Pos := \n");
 for(i=0 ; i<inst->numVars ; i++)
 {
  unsigned int j;
  for(j=0 ; j < inst->numClauses ; j++)
  {
   struct s_clause clause = inst->clause[j];
   unsigned int k;
   char found = 0;
   for(k=0 ; k<clause.size ; k++)
   {
    if(clause.var[k] == (i))
    {
     if(clause.signal[k] == 0)
      printf("%u %u 1\n",i+1,j+1);
     else
      printf("%u %u 0\n",i+1,j+1);
     found = 1;
     break;
    }
   }
   if(!found)
    printf("%u %u 0\n",i+1,j+1);
  }
 }
 printf("\n;");
 printf("param Neg := \n");
 for(i=0 ; i<inst->numVars ; i++)
 {
  unsigned int j;
  for(j=0 ; j < inst->numClauses ; j++)
  {
   struct s_clause clause = inst->clause[j];
   unsigned int k;
   char found = 0;
   for(k=0 ; k<clause.size ; k++)
   {
    if(clause.var[k] == (i))
    {
     if(clause.signal[k] == 1)
      printf("%u %u 1\n",i+1,j+1);
     else
      printf("%u %u 0\n",i+1,j+1);
     found = 1;
     break;
    }
   }
   if(!found)
    printf("%u %u 0\n",i+1,j+1);
  }
 }
 printf("\n;");
}

variable_types: struct s_clause { unsigned int *var; unsigned char *signal; unsigned int size; }

variable_types: found char


showClause

decompiled_code:
int __fastcall showClause(__int64 a1)
{
unsigned int v1; // ebx

if ( *(_DWORD *)(a1 + 16) )
{
v1 = 0;
do
{
if ( *(_BYTE *)(*(_QWORD *)(a1 + 8) + v1) == 1 )
fprintf(stderr, "-%u ", (unsigned int)(*(_DWORD *)(*(_QWORD *)a1 + 4LL * v1) + 1));
else
fprintf(stderr, " %u ", (unsigned int)(*(_DWORD *)(*(_QWORD *)a1 + 4LL * v1) + 1));
++v1;
}
while ( *(_DWORD *)(a1 + 16) > v1 );
}
return fputc(10, stderr);
}

canonical_decompiled_code:
int __fastcall func1(__int64 a1)
{
unsigned int v1; // ebx

if ( *(_DWORD *)(a1 + 16) )
{
v1 = 0;
do
{
if ( *(_BYTE *)(*(_QWORD *)(a1 + 8) + v1) == 1 )
fprintf(stderr, "-%u ", (unsigned int)(*(_DWORD *)(*(_QWORD *)a1 + 4LL * v1) + 1));
else
fprintf(stderr, " %u ", (unsigned int)(*(_DWORD *)(*(_QWORD *)a1 + 4LL * v1) + 1));
++v1;
}
while ( *(_DWORD *)(a1 + 16) > v1 );
}
return fputc(10, stderr);
}

original_code:
void showClause(t_clause *clause)
{
 unsigned int i;
 for(i=0 ; i<clause->size ; i++)
 {
  if(clause->signal[i] == 1)
  {
   fprintf(stderr,"-%u ",1+clause->var[i]);;
  }
  else
  {
   fprintf(stderr," %u ",1+clause->var[i]);;
  }
 }
 fprintf(stderr,"\n");;
}

canonical_original_code:
void showClause(struct s_clause *clause)
{
 unsigned int i;
 for(i=0 ; i<clause->size ; i++)
 {
  if(clause->signal[i] == 1)
  {
   fprintf(stderr,"-%u ",1+clause->var[i]);;
  }
  else
  {
   fprintf(stderr," %u ",1+clause->var[i]);;
  }
 }
 fprintf(stderr,"\n");;
}


showInstance

decompiled_code:
int __fastcall showInstance(__int64 a1)
{
unsigned int v1; // ebx
int result; // eax

if ( *(_DWORD *)(a1 + 24) )
{
v1 = 0;
do
result = showClause(*(_QWORD *)(a1 + 16) + 24LL * v1++);
while ( *(_DWORD *)(a1 + 24) > v1 );
}
return result;
}

canonical_decompiled_code:
int __fastcall func2(__int64 a1)
{
unsigned int v1; // ebx
int result; // eax

if ( *(_DWORD *)(a1 + 24) )
{
v1 = 0;
do
result = func1(*(_QWORD *)(a1 + 16) + 24LL * v1++);
while ( *(_DWORD *)(a1 + 24) > v1 );
}
return result;
}

original_code:
void showInstance(t_instance *inst)
{
 unsigned int i;
 for(i=0 ; i<inst->numClauses ; i++)
 {
  showClause(inst->clause+i);
 }
}

canonical_original_code:
void showInstance(struct s_instance *inst)
{
 unsigned int i;
 for(i=0 ; i<inst->numClauses ; i++)
 {
  showClause(inst->clause+i);
 }
}


randrange

decompiled_code:
__int64 __fastcall randrange(int a1)
{
return (unsigned int)(int)((double)(a1 + 1) * (double)rand() * 4.656612873077393e-10);
}

canonical_decompiled_code:
__int64 __fastcall func0(int a1)
{
return (unsigned int)(int)((double)(a1 + 1) * (double)rand() * 4.656612873077393e-10);
}

original_code:
int randrange(int max)
{
    return ((max+1) * ((double) rand())/((double)2147483647 +1));
}

variable_types: max int


repo: mgrennan/oswabox

decompiled_code:
int serial_init()
{
int result; // eax

result = open("/dev/ttyAMA0", 2306);
uart0_filestream = result;
return result;
}

canonical_decompiled_code:
int func0()
{
int result; // eax

result = open("/dev/ttyAMA0", 2306);
uart0_filestream = result;
return result;
}

original_code:
void serial_init(void)
{
    uart0_filestream = open("/dev/ttyAMA0", 02 | 0400 | 04000);
    if (uart0_filestream == -1) {
    }
}

canonical_original_code:
void serial_init()
{
    uart0_filestream = open("/dev/ttyAMA0", 02 | 0400 | 04000);
    if (uart0_filestream == -1) {
    }
}


decompiled_code:
int serial_config()
{
struct termios v1; // [rsp+0h] [rbp-48h] BYREF

tcgetattr(uart0_filestream, &v1);
v1.c_cflag = 2237;
v1.c_iflag = 4;
v1.c_oflag = 0;
v1.c_lflag = 0;
tcflush(uart0_filestream, 0);
return tcsetattr(uart0_filestream, 0, &v1);
}

canonical_decompiled_code:
int func1()
{
struct termios v1; // [rsp+0h] [rbp-48h] BYREF

tcgetattr(uart0_filestream, &v1);
v1.c_cflag = 2237;
v1.c_iflag = 4;
v1.c_oflag = 0;
v1.c_lflag = 0;
tcflush(uart0_filestream, 0);
return tcsetattr(uart0_filestream, 0, &v1);
}

original_code:
void serial_config(void)
{
    struct termios options;
    tcgetattr(uart0_filestream, &options);
    options.c_cflag = 0000015 | 0000060 | 0004000 | 0000200;
    options.c_iflag = 0000004;
    options.c_oflag = 0;
    options.c_lflag = 0;
    tcflush(uart0_filestream, 0);
    tcsetattr(uart0_filestream, 0, &options);
}

canonical_original_code:
void serial_config()
{
    struct termios options;
    tcgetattr(uart0_filestream, &options);
    options.c_cflag = 0000015 | 0000060 | 0004000 | 0000200;
    options.c_iflag = 0000004;
    options.c_oflag = 0;
    options.c_lflag = 0;
    tcflush(uart0_filestream, 0);
    tcsetattr(uart0_filestream, 0, &options);
}

variable_types: struct termios { unsigned int c_iflag; unsigned int c_oflag; unsigned int c_cflag; unsigned int c_lflag; unsigned char c_line; unsigned char c_cc[32]; unsigned int c_ispeed; unsigned int c_ospeed; }


decompiled_code:
void __fastcall serial_println(char *src, int a2)
{
int v2; // er12
char *v3; // rbx

v2 = uart0_filestream;
if ( uart0_filestream != -1 )
{
v3 = (char *)malloc(a2 + 1);
strcpy(v3, src);
v3[a2 - 1] = 13;
v3[a2] = 10;
write(v2, v3, a2 + 1);
free(v3);
}
}

canonical_decompiled_code:
void __fastcall func2(char *src, int a2)
{
int v2; // er12
char *v3; // rbx

v2 = uart0_filestream;
if ( uart0_filestream != -1 )
{
v3 = (char *)malloc(a2 + 1);
strcpy(v3, src);
v3[a2 - 1] = 13;
v3[a2] = 10;
write(v2, v3, a2 + 1);
free(v3);
}
}

original_code:
void serial_println(const char *line, int len)
{
    if (uart0_filestream != -1) {
        char *cpstr = (char *)malloc((len+1) * sizeof(char));
        strcpy(cpstr, line);
        cpstr[len-1] = '\r';
        cpstr[len] = '\n';
        int count = write(uart0_filestream, cpstr, len+1);
        if (count < 0) {
        }
        free(cpstr);
    }
}

canonical_original_code:
void serial_println(char *line, int len)
{
    if (uart0_filestream != -1) {
        char *cpstr = (char *)malloc((len+1) * sizeof(char));
        strcpy(cpstr, line);
        cpstr[len-1] = '\r';
        cpstr[len] = '\n';
        int count = write(uart0_filestream, cpstr, len+1);
        if (count < 0) {
        }
        free(cpstr);
    }
}

variable_types:
line
char *

variable_types: len int

variable_types:
cpstr
char *

variable_types: count int


decompiled_code:
int serial_close()
{
return close(uart0_filestream);
}

canonical_decompiled_code:
int func4()
{
return close(uart0_filestream);
}

original_code:
void serial_close(void)
{
    close(uart0_filestream);
}

canonical_original_code:
void serial_close()
{
    close(uart0_filestream);
}


decompiled_code:
__int64 __fastcall open_lockfile(const char *a1)
{
int v1; // eax
unsigned int v2; // ebx
int *v4; // rax
char *v5; // rax

v1 = open(a1, 64, 384LL);
if ( v1 < 0 )
{
v4 = _errno_location();
v5 = strerror(*v4);
printf("Failed to access lock file: %s\nerror: %s\nDid you sudo?\n", a1, v5);
exit(1);
}
v2 = v1;
if ( flock(v1, 6) == -1 )
{
if ( *_errno_location() != 11 )
{
perror("Flock failed");
exit(1);
}
puts("Lock file is in use, exiting...");
exit(1);
}
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func0(const char *a1)
{
int v1; // eax
unsigned int v2; // ebx
int *v4; // rax
char *v5; // rax

v1 = open(a1, 64, 384LL);
if ( v1 < 0 )
{
v4 = _errno_location();
v5 = strerror(*v4);
printf("Failed to access lock file: %s\nerror: %s\nDid you sudo?\n", a1, v5);
exit(1);
}
v2 = v1;
if ( flock(v1, 6) == -1 )
{
if ( *_errno_location() != 11 )
{
perror("Flock failed");
exit(1);
}
puts("Lock file is in use, exiting...");
exit(1);
}
return v2;
}

original_code:
int open_lockfile(const char *filename)
{
    int fd;
    fd = open(filename, 0100 | 00, 0600);
    if (fd < 0) {
        printf("Failed to access lock file: %s\nerror: %s\nDid you sudo?\n",
            filename, strerror((*__errno_location ())));
        exit(1);
    }
    while(flock(fd, 2 | 4) == -1) {
        if((*__errno_location ()) == 11) {
            printf("Lock file is in use, exiting...\n");
            exit(1);
        }
        perror("Flock failed");
        exit(1);
    }
    return fd;
}

canonical_original_code:
int open_lockfile(char *filename)
{
    int fd;
    fd = open(filename, 0100 | 00, 0600);
    if (fd < 0) {
        printf("Failed to access lock file: %s\nerror: %s\nDid you sudo?\n",
            filename, strerror((*__errno_location ())));
        exit(1);
    }
    while(flock(fd, 2 | 4) == -1) {
        if((*__errno_location ()) == 11) {
            printf("Lock file is in use, exiting...\n");
            exit(1);
        }
        perror("Flock failed");
        exit(1);
    }
    return fd;
}

variable_types:
filename
char *

variable_types: fd int


decompiled_code:
int __fastcall close_lockfile(int fd)
{
int result; // eax

if ( flock(fd, 8) == -1 )
{
perror("Failed to unlock file");
exit(1);
}
result = close(fd);
if ( result == -1 )
{
perror("Closing descriptor on lock file failed");
exit(1);
}
return result;
}

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

if ( flock(fd, 8) == -1 )
{
perror("Failed to unlock file");
exit(1);
}
result = close(fd);
if ( result == -1 )
{
perror("Closing descriptor on lock file failed");
exit(1);
}
return result;
}

original_code:
void close_lockfile(int fd)
{
    if(flock(fd, 8) == -1) {
        perror("Failed to unlock file");
        exit(1);
    }
    if(close(fd) == -1) {
        perror("Closing descriptor on lock file failed");
        exit(1);
    }
}


readCalibrationTable

decompiled_code:
_BOOL8 __fastcall readCalibrationTable(int fd, __int64 a2)
{
ssize_t v2; // rdx
_BOOL8 result; // rax
char buf[25]; // [rsp+Fh] [rbp-19h] BYREF

buf[0] = -86;
v2 = write(fd, buf, 1uLL);
result = 0LL;
if ( v2 == 1 )
result = read(fd, (void *)(a2 + 1), 0x16uLL) == 22;
return result;
}

canonical_decompiled_code:
_BOOL8 __fastcall func0(int fd, __int64 a2)
{
ssize_t v2; // rdx
_BOOL8 result; // rax
char buf[25]; // [rsp+Fh] [rbp-19h] BYREF

buf[0] = -86;
v2 = write(fd, buf, 1uLL);
result = 0LL;
if ( v2 == 1 )
result = read(fd, (void *)(a2 + 1), 0x16uLL) == 22;
return result;
}

original_code:
int readCalibrationTable(int fd, BMP085 *sensor)
{
    unsigned char cTableAddr = 0xAA;
    if (write(fd,&cTableAddr,1)!=1) {
        return 0;
    }
    if (read(fd,sensor->calibrationCoeficients,22)!=22) {
        return 0;
    }
    return 1;
}

canonical_original_code:
int readCalibrationTable(int fd, struct bmp085 *sensor)
{
    unsigned char cTableAddr = 0xAA;
    if (write(fd,&cTableAddr,1)!=1) {
        return 0;
    }
    if (read(fd,sensor->calibrationCoeficients,22)!=22) {
        return 0;
    }
    return 1;
}

variable_types: struct bmp085 { char i2cAddress; unsigned char calibrationCoeficients[22]; float temperature; long pressure; enum oversampling { ultraLowPower=0, standard=1, highResolution=2, ultraHighResolution=3 } oss; } *

variable_types:
cTableAddr
unsigned char

user_defined_types: struct bmp085 { char i2cAddress; unsigned char calibrationCoeficients[22]; float temperature; long pressure; enum oversampling oss; }


makeMeasurement

decompiled_code:
__int64 __fastcall makeMeasurement(int fd, __int64 a2)
{
int v3; // edx
__int16 v4; // ax
unsigned __int16 v5; // r14
unsigned __int16 v6; // r15
signed __int16 v7; // bp
__int64 v8; // r12
int v9; // esi
int v10; // er8
__int64 v11; // r12
__int64 v12; // rdx
float v13; // xmm0_4
__int64 v14; // r9
unsigned __int64 v15; // rdi
__int64 v16; // rdx
__int64 v17; // rcx
__int64 v18; // rdx
unsigned __int64 v19; // rax
signed __int64 v20; // rax
__int64 result; // rax
signed __int16 v22; // [rsp+2h] [rbp-66h]
signed __int16 v23; // [rsp+4h] [rbp-64h]
signed __int16 v24; // [rsp+6h] [rbp-62h]
unsigned __int16 v25; // [rsp+8h] [rbp-60h]
signed __int16 v26; // [rsp+Ah] [rbp-5Eh]
signed __int16 v27; // [rsp+Ch] [rbp-5Ch]
signed __int16 v28; // [rsp+Eh] [rbp-5Ah]
struct timespec requested_time; // [rsp+10h] [rbp-58h] BYREF
unsigned __int8 v30; // [rsp+22h] [rbp-46h] BYREF
unsigned __int8 v31; // [rsp+23h] [rbp-45h] BYREF
unsigned __int8 v32; // [rsp+24h] [rbp-44h] BYREF
char v33; // [rsp+25h] [rbp-43h] BYREF
char v34; // [rsp+26h] [rbp-42h] BYREF
char v35; // [rsp+27h] [rbp-41h] BYREF
__int16 v36; // [rsp+28h] [rbp-40h] BYREF
unsigned __int8 v37; // [rsp+2Ah] [rbp-3Eh] BYREF
unsigned __int8 v38; // [rsp+2Bh] [rbp-3Dh] BYREF
char v39; // [rsp+2Ch] [rbp-3Ch] BYREF
char v40; // [rsp+2Dh] [rbp-3Bh] BYREF
__int16 buf[29]; // [rsp+2Eh] [rbp-3Ah] BYREF

buf[0] = 12020;
v40 = -10;
v39 = -9;
v3 = *(_DWORD *)(a2 + 40);
v4 = ((_WORD)v3 << 14) + 13312;
LOBYTE(v4) = -12;
v36 = v4;
v35 = -10;
v34 = -9;
v33 = -8;
v22 = _byteswap_ushort(*(_WORD *)(a2 + 1));
v23 = _byteswap_ushort(*(_WORD *)(a2 + 3));
v24 = _byteswap_ushort(*(_WORD *)(a2 + 5));
v25 = _byteswap_ushort(*(_WORD *)(a2 + 7));
v5 = _byteswap_ushort(*(_WORD *)(a2 + 9));
v6 = _byteswap_ushort(*(_WORD *)(a2 + 11));
v26 = _byteswap_ushort(*(_WORD *)(a2 + 13));
v27 = _byteswap_ushort(*(_WORD *)(a2 + 15));
v7 = _byteswap_ushort(*(_WORD *)(a2 + 19));
v28 = _byteswap_ushort(*(_WORD *)(a2 + 21));
requested_time.tv_sec = 0LL;
requested_time.tv_nsec = pressureConversionTime[v3];
write(fd, buf, 2uLL);
nanosleep(&requested_time, 0LL);
write(fd, &v40, 1uLL);
read(fd, &v38, 1uLL);
write(fd, &v39, 1uLL);
read(fd, &v37, 1uLL);
v8 = v37 + (v38 << 8);
write(fd, &v36, 2uLL);
nanosleep(&requested_time, 0LL);
write(fd, &v35, 1uLL);
read(fd, &v32, 1uLL);
write(fd, &v34, 1uLL);
read(fd, &v31, 1uLL);
write(fd, &v33, 1uLL);
read(fd, &v30, 1uLL);
v9 = *(_DWORD *)(a2 + 40);
v10 = (v30 + (v32 << 16) + (v31 << 8)) >> (8 - v9);
v11 = ((v8 - v6) * v5) >> 15;
v12 = (v7 << 11) / (v11 + v28) + v11;
v13 = (double)(int)((v12 + 8) >> 4) * 0.1;
*(float *)(a2 + 24) = v13;
v12 -= 4000LL;
v14 = (v12 * v12) >> 12;
v15 = ((unsigned __int64)v25 * (((((v12 * v24) >> 13) + ((v14 * v26) >> 16) + 2) >> 2) + 0x8000)) >> 15;
v16 = (4 * v22 + ((v14 * v27) >> 11) + ((v23 * v12) >> 11)) << v9;
v17 = v16 + 5;
v18 = v16 + 2;
if ( v18 < 0 )
v18 = v17;
v19 = (50000 >> v9) * (v10 - (v18 >> 2));
if ( v19 > 0x7FFFFFFF )
v20 = 2 * (v19 / v15);
else
v20 = 2 * v19 / v15;
result = ((((-7357 * v20) >> 16) + ((3038 * (v20 >> 8) * (v20 >> 8)) >> 16) + 3791) >> 4) + v20;
*(_QWORD *)(a2 + 32) = result;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(int fd, __int64 a2)
{
int v3; // edx
__int16 v4; // ax
unsigned __int16 v5; // r14
unsigned __int16 v6; // r15
signed __int16 v7; // bp
__int64 v8; // r12
int v9; // esi
int v10; // er8
__int64 v11; // r12
__int64 v12; // rdx
float v13; // xmm0_4
__int64 v14; // r9
unsigned __int64 v15; // rdi
__int64 v16; // rdx
__int64 v17; // rcx
__int64 v18; // rdx
unsigned __int64 v19; // rax
signed __int64 v20; // rax
__int64 result; // rax
signed __int16 v22; // [rsp+2h] [rbp-66h]
signed __int16 v23; // [rsp+4h] [rbp-64h]
signed __int16 v24; // [rsp+6h] [rbp-62h]
unsigned __int16 v25; // [rsp+8h] [rbp-60h]
signed __int16 v26; // [rsp+Ah] [rbp-5Eh]
signed __int16 v27; // [rsp+Ch] [rbp-5Ch]
signed __int16 v28; // [rsp+Eh] [rbp-5Ah]
struct timespec requested_time; // [rsp+10h] [rbp-58h] BYREF
unsigned __int8 v30; // [rsp+22h] [rbp-46h] BYREF
unsigned __int8 v31; // [rsp+23h] [rbp-45h] BYREF
unsigned __int8 v32; // [rsp+24h] [rbp-44h] BYREF
char v33; // [rsp+25h] [rbp-43h] BYREF
char v34; // [rsp+26h] [rbp-42h] BYREF
char v35; // [rsp+27h] [rbp-41h] BYREF
__int16 v36; // [rsp+28h] [rbp-40h] BYREF
unsigned __int8 v37; // [rsp+2Ah] [rbp-3Eh] BYREF
unsigned __int8 v38; // [rsp+2Bh] [rbp-3Dh] BYREF
char v39; // [rsp+2Ch] [rbp-3Ch] BYREF
char v40; // [rsp+2Dh] [rbp-3Bh] BYREF
__int16 buf[29]; // [rsp+2Eh] [rbp-3Ah] BYREF

buf[0] = 12020;
v40 = -10;
v39 = -9;
v3 = *(_DWORD *)(a2 + 40);
v4 = ((_WORD)v3 << 14) + 13312;
LOBYTE(v4) = -12;
v36 = v4;
v35 = -10;
v34 = -9;
v33 = -8;
v22 = _byteswap_ushort(*(_WORD *)(a2 + 1));
v23 = _byteswap_ushort(*(_WORD *)(a2 + 3));
v24 = _byteswap_ushort(*(_WORD *)(a2 + 5));
v25 = _byteswap_ushort(*(_WORD *)(a2 + 7));
v5 = _byteswap_ushort(*(_WORD *)(a2 + 9));
v6 = _byteswap_ushort(*(_WORD *)(a2 + 11));
v26 = _byteswap_ushort(*(_WORD *)(a2 + 13));
v27 = _byteswap_ushort(*(_WORD *)(a2 + 15));
v7 = _byteswap_ushort(*(_WORD *)(a2 + 19));
v28 = _byteswap_ushort(*(_WORD *)(a2 + 21));
requested_time.tv_sec = 0LL;
requested_time.tv_nsec = pressureConversionTime[v3];
write(fd, buf, 2uLL);
nanosleep(&requested_time, 0LL);
write(fd, &v40, 1uLL);
read(fd, &v38, 1uLL);
write(fd, &v39, 1uLL);
read(fd, &v37, 1uLL);
v8 = v37 + (v38 << 8);
write(fd, &v36, 2uLL);
nanosleep(&requested_time, 0LL);
write(fd, &v35, 1uLL);
read(fd, &v32, 1uLL);
write(fd, &v34, 1uLL);
read(fd, &v31, 1uLL);
write(fd, &v33, 1uLL);
read(fd, &v30, 1uLL);
v9 = *(_DWORD *)(a2 + 40);
v10 = (v30 + (v32 << 16) + (v31 << 8)) >> (8 - v9);
v11 = ((v8 - v6) * v5) >> 15;
v12 = (v7 << 11) / (v11 + v28) + v11;
v13 = (double)(int)((v12 + 8) >> 4) * 0.1;
*(float *)(a2 + 24) = v13;
v12 -= 4000LL;
v14 = (v12 * v12) >> 12;
v15 = ((unsigned __int64)v25 * (((((v12 * v24) >> 13) + ((v14 * v26) >> 16) + 2) >> 2) + 0x8000)) >> 15;
v16 = (4 * v22 + ((v14 * v27) >> 11) + ((v23 * v12) >> 11)) << v9;
v17 = v16 + 5;
v18 = v16 + 2;
if ( v18 < 0 )
v18 = v17;
v19 = (50000 >> v9) * (v10 - (v18 >> 2));
if ( v19 > 0x7FFFFFFF )
v20 = 2 * (v19 / v15);
else
v20 = 2 * v19 / v15;
result = ((((-7357 * v20) >> 16) + ((3038 * (v20 >> 8) * (v20 >> 8)) >> 16) + 3791) >> 4) + v20;
*(_QWORD *)(a2 + 32) = result;
return result;
}

original_code:
void makeMeasurement(int fd, BMP085 *sensor)
{
    unsigned short startTempMeas = 0x2EF4;
    unsigned char tempMSBAddr = 0xF6, tempLSBAddr = 0xF6 + 1;
    unsigned char rawTempMSB,rawTempLSB;
    long rawTemperature,temperature = 0;
    unsigned short STARTPRESMEAS = (unsigned short)(((0x34+((sensor->oss)<<6)) << 8) | 0xF4);
    unsigned char pMSBAddress = 0xF6, pLSBAddress = 0xF7, pXLSBAddress = 0xF8;
    unsigned char pMSB, pLSB, pXLSB;
    long rawPressure = 0, pressure = 0;
    short ac1 = (short)((sensor->calibrationCoeficients[0] << 8) | sensor->calibrationCoeficients[1]);
    short ac2 = (short)((sensor->calibrationCoeficients[2] << 8) | sensor->calibrationCoeficients[3]);
    short ac3 = (short)((sensor->calibrationCoeficients[4] << 8) | sensor->calibrationCoeficients[5]);
    unsigned short ac4 = (unsigned short)((sensor->calibrationCoeficients[6] << 8) | sensor->calibrationCoeficients[7]);
    unsigned short ac5 = (unsigned short)((sensor->calibrationCoeficients[8] << 8) | sensor->calibrationCoeficients[9]);
    unsigned short ac6 = (unsigned short)((sensor->calibrationCoeficients[10] << 8) | sensor->calibrationCoeficients[11]);
    short b1 = (short)((sensor->calibrationCoeficients[12] << 8) | sensor->calibrationCoeficients[13]);
    short b2 = (short)((sensor->calibrationCoeficients[14] << 8) | sensor->calibrationCoeficients[15]);
    short mc = (short)((sensor->calibrationCoeficients[18] << 8) | sensor->calibrationCoeficients[19]);
    short md = (short)((sensor->calibrationCoeficients[20] << 8) | sensor->calibrationCoeficients[21]);
    struct timespec timer = {
        .tv_sec = 0,
        .tv_nsec = pressureConversionTime[sensor->oss],
    };
    long x1, x2, x3, b3, b5, b6 = 0;
    unsigned long b4, b7 =0;
    write(fd,&startTempMeas,2);
    nanosleep(&timer, ((void *)0));
    write(fd,&tempMSBAddr,1);
    read(fd,&rawTempMSB,1);
    write(fd,&tempLSBAddr,1);
    read(fd,&rawTempLSB,1);
    rawTemperature = (long)((rawTempMSB<<8)+rawTempLSB);
    write(fd,&STARTPRESMEAS,2);
    nanosleep(&timer,((void *)0));
    write(fd,&pMSBAddress,1);
    read(fd,&pMSB,1);
    write(fd,&pLSBAddress,1);
    read(fd,&pLSB,1);
    write(fd,&pXLSBAddress,1);
    read(fd,&pXLSB,1);
    rawPressure = ((pMSB<<16) + (pLSB<<8) + pXLSB)>>(8-sensor->oss);
    x1 = ((rawTemperature - ac6)*ac5)>>15;
    x2 = (mc << 11)/(x1 + md);
    b5 = x1 + x2;
    temperature = (b5 + 8)>>4;
    sensor->temperature = temperature * 0.1;
    b6 = b5 - 4000;
    x1 = (b2 * ((b6 * b6) >> 12)) >> 11;
    x2 = (ac2 * b6) >> 11;
    x3 = x1 + x2;
    b3 = ((( ac1 * 4 + x3 ) << sensor->oss) + 2 ) / 4;
    x1 = (ac3 * b6) >> 13;
    x2 = (b1 * ((b6 * b6) >> 12)) >> 16;
    x3 = ((x1+x2)+2) >> 2;
    b4 = (ac4 * (unsigned long)(x3 + 32768)) >> 15;
    b7 = ((unsigned long)rawPressure-b3)*(50000>>sensor->oss);
    if (b7<0x80000000)
        pressure=(b7*2)/b4;
    else
        pressure=(b7/b4)*2;
    x1=(pressure >> 8)* (pressure >> 8);
    x1=(x1*3038)>>16;
    x2=(-7357*pressure)>>16;
    pressure+=((x1+x2+3791)>>4);
    sensor->pressure = pressure;
}

canonical_original_code:
void makeMeasurement(int fd, struct bmp085 *sensor)
{
    unsigned short startTempMeas = 0x2EF4;
    unsigned char tempMSBAddr = 0xF6; unsigned char tempLSBAddr = 0xF6 + 1;
    unsigned char rawTempMSB; unsigned char rawTempLSB;
    long rawTemperature; long temperature = 0;
    unsigned short STARTPRESMEAS = (unsigned short)(((0x34+((sensor->oss)<<6)) << 8) | 0xF4);
    unsigned char pMSBAddress = 0xF6; unsigned char pLSBAddress = 0xF7; unsigned char pXLSBAddress = 0xF8;
    unsigned char pMSB; unsigned char pLSB; unsigned char pXLSB;
    long rawPressure = 0; long pressure = 0;
    short ac1 = (short)((sensor->calibrationCoeficients[0] << 8) | sensor->calibrationCoeficients[1]);
    short ac2 = (short)((sensor->calibrationCoeficients[2] << 8) | sensor->calibrationCoeficients[3]);
    short ac3 = (short)((sensor->calibrationCoeficients[4] << 8) | sensor->calibrationCoeficients[5]);
    unsigned short ac4 = (unsigned short)((sensor->calibrationCoeficients[6] << 8) | sensor->calibrationCoeficients[7]);
    unsigned short ac5 = (unsigned short)((sensor->calibrationCoeficients[8] << 8) | sensor->calibrationCoeficients[9]);
    unsigned short ac6 = (unsigned short)((sensor->calibrationCoeficients[10] << 8) | sensor->calibrationCoeficients[11]);
    short b1 = (short)((sensor->calibrationCoeficients[12] << 8) | sensor->calibrationCoeficients[13]);
    short b2 = (short)((sensor->calibrationCoeficients[14] << 8) | sensor->calibrationCoeficients[15]);
    short mc = (short)((sensor->calibrationCoeficients[18] << 8) | sensor->calibrationCoeficients[19]);
    short md = (short)((sensor->calibrationCoeficients[20] << 8) | sensor->calibrationCoeficients[21]);
    struct timespec timer = {
        .tv_sec = 0,
        .tv_nsec = pressureConversionTime[sensor->oss],
    };
    long x1; long x2; long x3; long b3; long b5; long b6 = 0;
    unsigned long b4; unsigned long b7 = 0;
    write(fd,&startTempMeas,2);
    nanosleep(&timer, ((void *)0));
    write(fd,&tempMSBAddr,1);
    read(fd,&rawTempMSB,1);
    write(fd,&tempLSBAddr,1);
    read(fd,&rawTempLSB,1);
    rawTemperature = (long)((rawTempMSB<<8)+rawTempLSB);
    write(fd,&STARTPRESMEAS,2);
    nanosleep(&timer,((void *)0));
    write(fd,&pMSBAddress,1);
    read(fd,&pMSB,1);
    write(fd,&pLSBAddress,1);
    read(fd,&pLSB,1);
    write(fd,&pXLSBAddress,1);
    read(fd,&pXLSB,1);
    rawPressure = ((pMSB<<16) + (pLSB<<8) + pXLSB)>>(8-sensor->oss);
    x1 = ((rawTemperature - ac6)*ac5)>>15;
    x2 = (mc << 11)/(x1 + md);
    b5 = x1 + x2;
    temperature = (b5 + 8)>>4;
    sensor->temperature = temperature * 0.1;
    b6 = b5 - 4000;
    x1 = (b2 * ((b6 * b6) >> 12)) >> 11;
    x2 = (ac2 * b6) >> 11;
    x3 = x1 + x2;
    b3 = ((( ac1 * 4 + x3 ) << sensor->oss) + 2 ) / 4;
    x1 = (ac3 * b6) >> 13;
    x2 = (b1 * ((b6 * b6) >> 12)) >> 16;
    x3 = ((x1+x2)+2) >> 2;
    b4 = (ac4 * (unsigned long)(x3 + 32768)) >> 15;
    b7 = ((unsigned long)rawPressure-b3)*(50000>>sensor->oss);
    if (b7<0x80000000)
        pressure=(b7*2)/b4;
    else
        pressure=(b7/b4)*2;
    x1=(pressure >> 8)* (pressure >> 8);
    x1=(x1*3038)>>16;
    x2=(-7357*pressure)>>16;
    pressure+=((x1+x2+3791)>>4);
    sensor->pressure = pressure;
}

variable_types:
startTempMeas
unsigned short

variable_types:
tempMSBAddr
unsigned char

variable_types:
tempLSBAddr
unsigned char

variable_types:
rawTempMSB
unsigned char

variable_types:
rawTempLSB
unsigned char

variable_types: rawTemperature long

variable_types: temperature long

variable_types:
STARTPRESMEAS
unsigned short

variable_types:
pMSBAddress
unsigned char

variable_types:
pLSBAddress
unsigned char

variable_types:
pXLSBAddress
unsigned char

variable_types:
pMSB
unsigned char

variable_types:
pLSB
unsigned char

variable_types:
pXLSB
unsigned char

variable_types: rawPressure long

variable_types: pressure long

variable_types: mc short

variable_types: md short

variable_types: struct timespec { long tv_sec; long tv_nsec; }

user_defined_types: enum oversampling { ultraLowPower=0, standard=1, highResolution=2, ultraHighResolution=3 }


printCalibrationTable

original_code:
void printCalibrationTable(BMP085 *sensor)
{
    const char *calCoefName[] = {"AC1","AC2","AC3","AC4","AC5","AC6","B1","B2","MB","MC","MD"};
    unsigned char i;
    for(i=0;i<11;i++) {
        switch (i) {
            case 3:
            case 4:
            case 5:
                printf("%s = \t%d\n",calCoefName[i],(unsigned short)((sensor->calibrationCoeficients[i*2] << 8) | sensor->calibrationCoeficients[i*2+1]));
                break;
            default:
                printf("%s = \t%d\n",calCoefName[i],(short)((sensor->calibrationCoeficients[i*2] << 8) | sensor->calibrationCoeficients[i*2+1]));
        }
    }
    printf("\n");
}

canonical_original_code:
void printCalibrationTable(struct bmp085 *sensor)
{
    char *calCoefName[] = {"AC1","AC2","AC3","AC4","AC5","AC6","B1","B2","MB","MC","MD"};
    unsigned char i;
    for(i=0;i<11;i++) {
        switch (i) {
            case 3:
            case 4:
            case 5:
                printf("%s = \t%d\n",calCoefName[i],(unsigned short)((sensor->calibrationCoeficients[i*2] << 8) | sensor->calibrationCoeficients[i*2+1]));
                break;
            default:
                printf("%s = \t%d\n",calCoefName[i],(short)((sensor->calibrationCoeficients[i*2] << 8) | sensor->calibrationCoeficients[i*2+1]));
        }
    }
    printf("\n");
}

variable_types: struct bmp085 { char i2cAddress; unsigned char calibrationCoeficients[22]; float temperature; long pressure; enum oversampling { ultraLowPower=0, standard=1, highResolution=2, ultraHighResolution=3 } oss; } *

variable_types:
calCoefName
char *[]

variable_types:
i
unsigned char


original_code:
void nmea_parse_gpgga(char *nmea, gpgga_t *loc)
{
    char *p = nmea;
    char s[3];
    p = strchr(p, ',')+1;
    s[0] = p[0];
    s[1] = p[1];
    s[2] = 0;
    loc->hour = atoi(s);
    s[0] = p[2];
    s[1] = p[3];
    s[2] = 0;
    loc->minute = atoi(s);
    s[0] = p[4];
    s[1] = p[5];
    s[2] = 0;
    loc->second = atoi(s);
    p = strchr(p, ',')+1;
    loc->latitude = atof(p);
    p = strchr(p, ',')+1;
    switch (p[0]) {
        case 'N':
            loc->lat = 'N';
            break;
        case 'S':
            loc->lat = 'S';
            break;
        case ',':
            loc->lat = '\0';
            break;
    }
    p = strchr(p, ',')+1;
    loc->longitude = atof(p);
    p = strchr(p, ',')+1;
    switch (p[0]) {
        case 'W':
            loc->lon = 'W';
            break;
        case 'E':
            loc->lon = 'E';
            break;
        case ',':
            loc->lon = '\0';
            break;
    }
    p = strchr(p, ',')+1;
    loc->quality = (uint8_t)atoi(p);
    p = strchr(p, ',')+1;
    loc->satellites = (uint8_t)atoi(p);
    p = strchr(p, ',')+1;
    p = strchr(p, ',')+1;
    loc->altitude = atof(p);
}

canonical_original_code:
void nmea_parse_gpgga(char *nmea, struct gpgga *loc)
{
    char *p = nmea;
    char s[3];
    p = strchr(p, ',')+1;
    s[0] = p[0];
    s[1] = p[1];
    s[2] = 0;
    loc->hour = atoi(s);
    s[0] = p[2];
    s[1] = p[3];
    s[2] = 0;
    loc->minute = atoi(s);
    s[0] = p[4];
    s[1] = p[5];
    s[2] = 0;
    loc->second = atoi(s);
    p = strchr(p, ',')+1;
    loc->latitude = atof(p);
    p = strchr(p, ',')+1;
    switch (p[0]) {
        case 'N':
            loc->lat = 'N';
            break;
        case 'S':
            loc->lat = 'S';
            break;
        case ',':
            loc->lat = '\0';
            break;
    }
    p = strchr(p, ',')+1;
    loc->longitude = atof(p);
    p = strchr(p, ',')+1;
    switch (p[0]) {
        case 'W':
            loc->lon = 'W';
            break;
        case 'E':
            loc->lon = 'E';
            break;
        case ',':
            loc->lon = '\0';
            break;
    }
    p = strchr(p, ',')+1;
    loc->quality = (unsigned char)atoi(p);
    p = strchr(p, ',')+1;
    loc->satellites = (unsigned char)atoi(p);
    p = strchr(p, ',')+1;
    p = strchr(p, ',')+1;
    loc->altitude = atof(p);
}

variable_types:
nmea
char *

variable_types: struct gpgga { double latitude; char lat; double longitude; char lon; unsigned char quality; unsigned char satellites; double altitude; int hour; int minute; int second; } *

variable_types:
p
char *

variable_types:
s
char [3]


original_code:
void nmea_parse_gprmc(char *nmea, gprmc_t *loc)
{
    char *p = nmea;
    char s[3];
    p = strchr(p, ',')+1;
    s[0] = p[0];
    s[1] = p[1];
    s[2] = 0;
    loc->hour = atoi(s);
    s[0] = p[2];
    s[1] = p[3];
    s[2] = 0;
    loc->minute = atoi(s);
    s[0] = p[4];
    s[1] = p[5];
    s[2] = 0;
    loc->second = atoi(s);
    p = strchr(p, ',')+1;
    p = strchr(p, ',')+1;
    loc->latitude = atof(p);
    p = strchr(p, ',')+1;
    switch (p[0]) {
        case 'N':
            loc->lat = 'N';
            break;
        case 'S':
            loc->lat = 'S';
            break;
        case ',':
            loc->lat = '\0';
            break;
    }
    p = strchr(p, ',')+1;
    loc->longitude = atof(p);
    p = strchr(p, ',')+1;
    switch (p[0]) {
        case 'W':
            loc->lon = 'W';
            break;
        case 'E':
            loc->lon = 'E';
            break;
        case ',':
            loc->lon = '\0';
            break;
    }
    p = strchr(p, ',')+1;
    loc->speed = atof(p);
    p = strchr(p, ',')+1;
    loc->course = atof(p);
    p = strchr(p, ',')+1;
    s[0] = p[0];
    s[1] = p[1];
    s[2] = 0;
    loc->day = atoi(s);
    s[0] = p[2];
    s[1] = p[3];
    s[2] = 0;
    loc->month = atoi(s);
    s[0] = p[4];
    s[1] = p[5];
    s[2] = 0;
    loc->year = atoi(s);
}

canonical_original_code:
void nmea_parse_gprmc(char *nmea, struct gprmc *loc)
{
    char *p = nmea;
    char s[3];
    p = strchr(p, ',')+1;
    s[0] = p[0];
    s[1] = p[1];
    s[2] = 0;
    loc->hour = atoi(s);
    s[0] = p[2];
    s[1] = p[3];
    s[2] = 0;
    loc->minute = atoi(s);
    s[0] = p[4];
    s[1] = p[5];
    s[2] = 0;
    loc->second = atoi(s);
    p = strchr(p, ',')+1;
    p = strchr(p, ',')+1;
    loc->latitude = atof(p);
    p = strchr(p, ',')+1;
    switch (p[0]) {
        case 'N':
            loc->lat = 'N';
            break;
        case 'S':
            loc->lat = 'S';
            break;
        case ',':
            loc->lat = '\0';
            break;
    }
    p = strchr(p, ',')+1;
    loc->longitude = atof(p);
    p = strchr(p, ',')+1;
    switch (p[0]) {
        case 'W':
            loc->lon = 'W';
            break;
        case 'E':
            loc->lon = 'E';
            break;
        case ',':
            loc->lon = '\0';
            break;
    }
    p = strchr(p, ',')+1;
    loc->speed = atof(p);
    p = strchr(p, ',')+1;
    loc->course = atof(p);
    p = strchr(p, ',')+1;
    s[0] = p[0];
    s[1] = p[1];
    s[2] = 0;
    loc->day = atoi(s);
    s[0] = p[2];
    s[1] = p[3];
    s[2] = 0;
    loc->month = atoi(s);
    s[0] = p[4];
    s[1] = p[5];
    s[2] = 0;
    loc->year = atoi(s);
}

variable_types: struct gprmc { double latitude; char lat; double longitude; char lon; double speed; double course; int hour; int minute; int second; int day; int month; int year; } *


decompiled_code:
__int64 __fastcall nmea_valid_checksum(__int64 a1)
{
char *v1; // rax
char v2; // si
char v3; // al
char *v4; // rdx
char v5; // cl
__int64 result; // rax

v1 = strchr((const char *)a1, 42);
v2 = strtol(v1 + 1, 0LL, 16);
v3 = *(_BYTE *)(a1 + 1);
if ( v3 == 42 )
{
v5 = 0;
}
else
{
v4 = (char *)(a1 + 2);
v5 = 0;
do
{
v5 ^= v3;
v3 = *v4++;
}
while ( v3 != 42 );
}
result = 0LL;
if ( v5 != v2 )
result = 4294967168LL;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1)
{
char *v1; // rax
char v2; // si
char v3; // al
char *v4; // rdx
char v5; // cl
__int64 result; // rax

v1 = strchr((const char *)a1, 42);
v2 = strtol(v1 + 1, 0LL, 16);
v3 = *(_BYTE *)(a1 + 1);
if ( v3 == 42 )
{
v5 = 0;
}
else
{
v4 = (char *)(a1 + 2);
v5 = 0;
do
{
v5 ^= v3;
v3 = *v4++;
}
while ( v3 != 42 );
}
result = 0LL;
if ( v5 != v2 )
result = 4294967168LL;
return result;
}

original_code:
uint8_t nmea_valid_checksum(const char *message)
{
    uint8_t checksum= (uint8_t)strtol(strchr(message, '*')+1, ((void *)0), 16);
    char p;
    uint8_t sum = 0;
    ++message;
    while ((p = *message++) != '*') {
        sum ^= p;
    }
    if (sum != checksum) {
        return 0x80;
    }
    return 0x00;
}

canonical_original_code:
unsigned char nmea_valid_checksum(char *message)
{
    unsigned char checksum = (uint8_t)strtol(strchr(message, '*')+1, ((void *)0), 16);
    char p;
    unsigned char sum = 0;
    ++message;
    while ((p = *message++) != '*') {
        sum ^= p;
    }
    if (sum != checksum) {
        return 0x80;
    }
    return 0x00;
}

variable_types:
message
char *

variable_types:
checksum
unsigned char

variable_types: p char

variable_types:
sum
unsigned char

return_type: unsigned char


decompiled_code:
char __fastcall nmea_get_message_type(char *haystack)
{
char result; // al
char *v2; // rdx

result = nmea_valid_checksum((__int64)haystack);
if ( !result )
{
v2 = strstr(haystack, "$GPGGA");
result = 2;
if ( !v2 )
result = strstr(haystack, "$GPRMC") != 0LL;
}
return result;
}

canonical_decompiled_code:
char __fastcall func3(char *haystack)
{
char result; // al
char *v2; // rdx

result = func2((__int64)haystack);
if ( !result )
{
v2 = strstr(haystack, "$GPGGA");
result = 2;
if ( !v2 )
result = strstr(haystack, "$GPRMC") != 0LL;
}
return result;
}

original_code:
uint8_t nmea_get_message_type(const char *message)
{
    uint8_t checksum = 0;
    if ((checksum = nmea_valid_checksum(message)) != 0x00) {
        return checksum;
    }
    if (strstr(message, "$GPGGA") != ((void *)0)) {
        return 0x02;
    }
    if (strstr(message, "$GPRMC") != ((void *)0)) {
        return 0x01;
    }
    return 0x00;
}

canonical_original_code:
unsigned char nmea_get_message_type(char *message)
{
    unsigned char checksum = 0;
    if ((checksum = nmea_valid_checksum(message)) != 0x00) {
        return checksum;
    }
    if (strstr(message, "$GPGGA") != ((void *)0)) {
        return 0x02;
    }
    if (strstr(message, "$GPRMC") != ((void *)0)) {
        return 0x01;
    }
    return 0x00;
}


decompiled_code:
__int64 gps_init()
{
serial_init();
return serial_config();
}

canonical_decompiled_code:
__int64 func0()
{
serial_init();
return serial_config();
}

original_code:
extern void gps_init(void)
{
    serial_init();
    serial_config();
}

canonical_original_code:
extern void gps_init()
{
    serial_init();
    serial_config();
}


decompiled_code:
void gps_on()
{
;
}

canonical_decompiled_code:
void func1()
{
;
}

original_code:
extern void gps_on(void)
{
}

canonical_original_code:
extern void gps_on()
{
}


decompiled_code:
__int64 gps_off()
{
return serial_close();
}

canonical_decompiled_code:
__int64 func2()
{
return serial_close();
}

original_code:
extern void gps_off(void)
{
    serial_close();
}

canonical_original_code:
extern void gps_off()
{
    serial_close();
}


original_code:
double gps_deg_dec(double deg_point)
{
    double ddeg;
    double sec = modf(deg_point, &ddeg)*60;
    int deg = (int)(ddeg/100);
    int min = (int)(deg_point-(deg*100));
    double absdlat = round(deg * 1000000.);
    double absmlat = round(min * 1000000.);
    double absslat = round(sec * 1000000.);
    return round(absdlat + (absmlat/60) + (absslat/3600)) /1000000;
}

variable_types: ddeg double

variable_types: sec double

variable_types: deg int

variable_types: min int

variable_types: absdlat double

variable_types: absmlat double

variable_types: absslat double


decompiled_code:
void __fastcall gps_convert_deg_to_dec(double *a1, char a2, double *a3, char a4)
{
double v5; // xmm0_8
double v6; // r12

if ( a2 == 78 )
v5 = *a1;
else
*(_QWORD *)&v5 = *(_QWORD *)a1 ^ LC4;
if ( a4 == 69 )
v6 = *a3;
else
*(_QWORD *)&v6 = *(_QWORD *)a3 ^ LC4;
*a1 = gps_deg_dec(v5);
*a3 = gps_deg_dec(v6);
}

canonical_decompiled_code:
void __fastcall func4(double *a1, char a2, double *a3, char a4)
{
double v5; // xmm0_8
double v6; // r12

if ( a2 == 78 )
v5 = *a1;
else
*(_QWORD *)&v5 = *(_QWORD *)a1 ^ LC4;
if ( a4 == 69 )
v6 = *a3;
else
*(_QWORD *)&v6 = *(_QWORD *)a3 ^ LC4;
*a1 = func3(v5);
*a3 = func3(v6);
}

original_code:
void gps_convert_deg_to_dec(double *latitude, char ns, double *longitude, char we)
{
    double lat = (ns == 'N') ? *latitude : -1 * (*latitude);
    double lon = (we == 'E') ? *longitude : -1 * (*longitude);
    *latitude = gps_deg_dec(lat);
    *longitude = gps_deg_dec(lon);
}

variable_types:
latitude
double *

variable_types: ns char

variable_types:
longitude
double *

variable_types: we char

variable_types: lat double

variable_types: lon double


original_code:
extern void gps_location(loc_t *coord)
{
    uint8_t status = 0x00;
    while(status != 0x03) {
        gpgga_t gpgga;
        gprmc_t gprmc;
        char buffer[256];
        serial_readln(buffer, 256);
        switch (nmea_get_message_type(buffer)) {
            case 0x02:
                nmea_parse_gpgga(buffer, &gpgga);
                gps_convert_deg_to_dec(&(gpgga.latitude), gpgga.lat, &(gpgga.longitude), gpgga.lon);
                coord->latitude = gpgga.latitude;
                coord->longitude = gpgga.longitude;
                coord->altitude = gpgga.altitude;
                coord->hour = gpgga.hour;
                coord->minute = gpgga.minute;
                coord->second = gpgga.second;
                status |= 0x02;
                break;
            case 0x01:
                nmea_parse_gprmc(buffer, &gprmc);
                coord->hour = gprmc.hour;
                coord->minute = gprmc.minute;
                coord->second = gprmc.second;
                coord->speed = gprmc.speed;
                coord->course = gprmc.course;
                coord->day = gprmc.day;
                coord->month = gprmc.month;
                coord->year = gprmc.year;
                status |= 0x01;
                break;
        }
    }
}

canonical_original_code:
extern void gps_location(struct location *coord)
{
    unsigned char status = 0x00;
    while(status != 0x03) {
        struct gpgga gpgga;
        struct gprmc gprmc;
        char buffer[256];
        serial_readln(buffer, 256);
        switch (nmea_get_message_type(buffer)) {
            case 0x02:
                nmea_parse_gpgga(buffer, &gpgga);
                gps_convert_deg_to_dec(&(gpgga.latitude), gpgga.lat, &(gpgga.longitude), gpgga.lon);
                coord->latitude = gpgga.latitude;
                coord->longitude = gpgga.longitude;
                coord->altitude = gpgga.altitude;
                coord->hour = gpgga.hour;
                coord->minute = gpgga.minute;
                coord->second = gpgga.second;
                status |= 0x02;
                break;
            case 0x01:
                nmea_parse_gprmc(buffer, &gprmc);
                coord->hour = gprmc.hour;
                coord->minute = gprmc.minute;
                coord->second = gprmc.second;
                coord->speed = gprmc.speed;
                coord->course = gprmc.course;
                coord->day = gprmc.day;
                coord->month = gprmc.month;
                coord->year = gprmc.year;
                status |= 0x01;
                break;
        }
    }
}

variable_types: struct location { double latitude; double longitude; double speed; double altitude; double course; int hour; int minute; int second; int day; int month; int year; } *

variable_types:
status
unsigned char

variable_types: struct gpgga { double latitude; char lat; double longitude; char lon; unsigned char quality; unsigned char satellites; double altitude; int hour; int minute; int second; }

variable_types: struct gprmc { double latitude; char lat; double longitude; char lon; double speed; double course; int hour; int minute; int second; int day; int month; int year; }

variable_types:
buffer
char [256]


repo: mholzinger/SSLUnit

decompiled_code:
__int64 print_ssl_error_stack()
{
__int64 result; // rax
__int64 i; // rdi
char v2[1032]; // [rsp+0h] [rbp-408h] BYREF

result = ERR_get_error();
for ( i = result; result; i = result )
{
ERR_error_string_n(i, v2, 1024LL);
printf("<%s>\n", v2);
result = ERR_get_error();
}
return result;
}

canonical_decompiled_code:
__int64 func0()
{
__int64 result; // rax
__int64 i; // rdi
char v2[1032]; // [rsp+0h] [rbp-408h] BYREF

result = ERR_get_error();
for ( i = result; result; i = result )
{
ERR_error_string_n(i, v2, 1024LL);
printf("<%s>\n", v2);
result = ERR_get_error();
}
return result;
}

original_code:
void print_ssl_error_stack(void)
{
    char error_msg[error_buf];
 unsigned long ul_error = ERR_get_error();
 while (ul_error != 0)
 {
  ERR_error_string_n(ul_error, error_msg, (size_t)error_buf);
  (void)printf("<%s>\n", error_msg);
  ul_error = ERR_get_error();
 }
 (void)memset((void*)error_msg, 0, sizeof(error_msg));
 ul_error = 0;
}

canonical_original_code:
void print_ssl_error_stack()
{
    char error_msg[-1];
 unsigned long ul_error = ERR_get_error();
 while (ul_error != 0)
 {
  ERR_error_string_n(ul_error, error_msg, (unsigned long)error_buf);
  (void)printf("<%s>\n", error_msg);
  ul_error = ERR_get_error();
 }
 (void)memset((void *)error_msg, 0, sizeof(error_msg));
 ul_error = 0;
}


decompiled_code:
__int64 set_fips()
{
__int64 result; // rax

OPENSSL_init_ssl(0LL, 0LL);
OPENSSL_init_ssl(2097154LL, 0LL);
if ( !(unsigned int)FIPS_mode_set(1LL) )
{
puts("FIPS mode has not been set");
print_ssl_error_stack();
}
result = FIPS_mode();
gi_fips_mode = result;
return result;
}

canonical_decompiled_code:
__int64 func1()
{
__int64 result; // rax

OPENSSL_init_ssl(0LL, 0LL);
OPENSSL_init_ssl(2097154LL, 0LL);
if ( !(unsigned int)FIPS_mode_set(1LL) )
{
puts("FIPS mode has not been set");
func0();
}
result = FIPS_mode();
gi_fips_mode = result;
return result;
}

original_code:
void set_fips(void)
{
 (void)OPENSSL_init_ssl(0, ((void *)0));
 OPENSSL_init_ssl(0x00200000L | 0x00000002L, ((void *)0));
 if (!FIPS_mode_set(1))
 {
  printf("FIPS mode has not been set\n");
  print_ssl_error_stack();
 }
 gi_fips_mode = FIPS_mode();
}

canonical_original_code:
void set_fips()
{
 (void)OPENSSL_init_ssl(0, ((void *)0));
 OPENSSL_init_ssl(0x00200000L | 0x00000002L, ((void *)0));
 if (!FIPS_mode_set(1))
 {
  printf("FIPS mode has not been set\n");
  print_ssl_error_stack();
 }
 gi_fips_mode = FIPS_mode();
}


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
set_fips(argc, argv, envp);
printf("FIPS Mode = <%d>\n", (unsigned int)gi_fips_mode);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
func1(argc, argv, envp);
printf("FIPS Mode = <%d>\n", (unsigned int)gi_fips_mode);
return 0;
}

original_code:
int main(int argc, char* argv[])
{
 set_fips();
 (void)printf("FIPS Mode = <%d>\n", gi_fips_mode);
}

canonical_original_code:
int main(int argc, char *argv[])
{
 set_fips();
 (void)printf("FIPS Mode = <%d>\n", gi_fips_mode);
}

variable_types: argc int

variable_types:
argv
char *[]


repo: mholzinger/fastlog

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v3; // rdx
__int64 v4; // rdx
__int64 v5; // rdx
const char *v6; // rsi
char v8; // [rsp+0h] [rbp-8h]
char v9; // [rsp+0h] [rbp-8h]
char v10; // [rsp+0h] [rbp-8h]
char v11; // [rsp+0h] [rbp-8h]
char v12; // [rsp+0h] [rbp-8h]
char v13; // [rsp+0h] [rbp-8h]

logpath("/tmp/test_one.log", argv, envp);
flog("The quick brown fox jumped over the lazy dog.", v8);
flog("int = <%d>, string = <%s>", v9);
closelogfile("int = <%d>, string = <%s>", 1234LL);
logpath("/var/log/syslog", 1234LL, v3);
flog("call to open syslog should fail, so this message should get written to syslog", v10);
closelogfile("call to open syslog should fail, so this message should get written to syslog", 1234LL);
logpath(0LL, 1234LL, v4);
flog("this should appear underneath an error statement in syslog", v11);
closelogfile("this should appear underneath an error statement in syslog", 1234LL);
logpath("/tmp/test_two.log", 1234LL, v5);
v6 = (const char *)getlogpath();
flog("logerror was sucessfully unset message now appears in <%s>", v12);
closelogfile("logerror was sucessfully unset message now appears in <%s>", v6);
getlogpath();
flog("logpath is set <%s>, while the logf FILE* is NULL, message appears in syslog", v13);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v3; // rdx
__int64 v4; // rdx
__int64 v5; // rdx
const char *v6; // rsi
char v8; // [rsp+0h] [rbp-8h]
char v9; // [rsp+0h] [rbp-8h]
char v10; // [rsp+0h] [rbp-8h]
char v11; // [rsp+0h] [rbp-8h]
char v12; // [rsp+0h] [rbp-8h]
char v13; // [rsp+0h] [rbp-8h]

func12("/tmp/test_one.log", argv, envp);
func10("The quick brown fox jumped over the lazy dog.", v8);
func10("int = <%d>, string = <%s>", v9);
closelogfile("int = <%d>, string = <%s>", 1234LL);
func12("/var/log/syslog", 1234LL, v3);
func10("call to open syslog should fail, so this message should get written to syslog", v10);
closelogfile("call to open syslog should fail, so this message should get written to syslog", 1234LL);
func12(0LL, 1234LL, v4);
func10("this should appear underneath an error statement in syslog", v11);
closelogfile("this should appear underneath an error statement in syslog", 1234LL);
func12("/tmp/test_two.log", 1234LL, v5);
v6 = (const char *)func7();
func10("logerror was sucessfully unset message now appears in <%s>", v12);
closelogfile("logerror was sucessfully unset message now appears in <%s>", v6);
func7();
func10("logpath is set <%s>, while the logf FILE* is NULL, message appears in syslog", v13);
return 0;
}

original_code:
int main(void)
{
    logpath("/tmp/test_one.log");
    flog("The quick brown fox jumped over the lazy dog.");
    flog("int = <%d>, string = <%s>", (int)1234,
        (char*)"string with space characters");
    closelogfile();
    logpath("/var/log/syslog");
    flog("call to open syslog should fail, so this message should get "
        "written to syslog");
    closelogfile();
    logpath(((void *)0));
    flog("this should appear underneath an error statement in syslog");
    closelogfile();
    logpath("/tmp/test_two.log");
    flog("logerror was sucessfully unset message now appears in <%s>",
        getlogpath());
    closelogfile();
    flog("logpath is set <%s>, while the logf FILE* "
        "is NULL, message appears in syslog", getlogpath());
    return 0;
}

canonical_original_code:
int main()
{
    logpath("/tmp/test_one.log");
    flog("The quick brown fox jumped over the lazy dog.");
    flog("int = <%d>, string = <%s>", (int)1234,
        (char *)"string with space characters");
    closelogfile();
    logpath("/var/log/syslog");
    flog("call to open syslog should fail, so this message should get "
        "written to syslog");
    closelogfile();
    logpath(((void *)0));
    flog("this should appear underneath an error statement in syslog");
    closelogfile();
    logpath("/tmp/test_two.log");
    flog("logerror was sucessfully unset message now appears in <%s>",
        getlogpath());
    closelogfile();
    flog("logpath is set <%s>, while the logf FILE* "
        "is NULL, message appears in syslog", getlogpath());
    return 0;
}


getlogpath

decompiled_code:
__int64 getlogpath()
{
return logfilename;
}

canonical_decompiled_code:
__int64 func7()
{
return logfilename;
}

original_code:
char* getlogpath(void)
{
    return logfilename;
}

canonical_original_code:
char *getlogpath()
{
    return logfilename;
}

return_type: char *


writesyslog

decompiled_code:
void writesyslog(char *format, ...)
{
__uid_t v1; // eax
gcc_va_list arg; // [rsp+8h] [rbp-4D0h] BYREF
char s[1024]; // [rsp+20h] [rbp-4B8h] BYREF

va_start(arg, format);
vsprintf(s, format, arg);
setlogmask(63);
openlog("libflog", 11, 136);
v1 = getuid();
syslog(5, s, v1);
closelog();
}

canonical_decompiled_code:
void func8(char *format, ...)
{
__uid_t v1; // eax
gcc_va_list arg; // [rsp+8h] [rbp-4D0h] BYREF
char s[1024]; // [rsp+20h] [rbp-4B8h] BYREF

va_start(arg, format);
vsprintf(s, format, arg);
setlogmask(63);
openlog("libflog", 11, 136);
v1 = getuid();
syslog(5, s, v1);
closelog();
}

original_code:
void writesyslog(const char* format, ...)
{
     char logstring[1024];
     va_list args;
     __builtin_va_start(args,format);
     vsprintf(logstring, format, args);
     __builtin_va_end(args);
     setlogmask(((1 << ((5)+1)) - 1));
     openlog("libflog", 0x02 | 0x01 | 0x08, (17<<3));
     syslog(5, logstring, getuid());
     closelog();
}

canonical_original_code:
void writesyslog(char *format, ...)
{
     char logstring[1024];
     __builtin_va_list args;
     __builtin_va_start(args,format);
     vsprintf(logstring, format, args);
     __builtin_va_end(args);
     setlogmask(((1 << ((5)+1)) - 1));
     openlog("libflog", 0x02 | 0x01 | 0x08, (17<<3));
     syslog(5, logstring, getuid());
     closelog();
}

variable_types:
format
char *

variable_types:
logstring
char [1024]


flushlog

decompiled_code:
int __fastcall flushlog()
{
int v0; // ebp
int *v1; // rbx
FILE **v2; // rax
unsigned int v3; // ebx
const char *v4; // rax

v1 = __errno_location();
*v1 = 0;
v2 = &logfp;
if ( logfp )
{
LODWORD(v2) = fflush(logfp);
v0 = (int)v2;
}
if ( v0 )
{
v3 = *v1;
v4 = (const char *)getlogpath();
writesyslog("flushlog fflush failed for log file <%s>\n", v4);
writesyslog("errno <%d>\n", v3);
v2 = (FILE **)logerror;
logerror[0] = 1;
}
return (int)v2;
}

canonical_decompiled_code:
int __fastcall func9()
{
int v0; // ebp
int *v1; // rbx
FILE **v2; // rax
unsigned int v3; // ebx
const char *v4; // rax

v1 = __errno_location();
*v1 = 0;
v2 = &logfp;
if ( logfp )
{
LODWORD(v2) = fflush(logfp);
v0 = (int)v2;
}
if ( v0 )
{
v3 = *v1;
v4 = (const char *)func7();
func8("flushlog fflush failed for log file <%s>\n", v4);
func8("errno <%d>\n", v3);
v2 = (FILE **)logerror;
logerror[0] = 1;
}
return (int)v2;
}

original_code:
void flushlog(void)
{
    int errno_state;
    int irc;
    (*__errno_location ()) = 0;
    if (logfp != ((void *)0)) irc = fflush(logfp);
    if (irc)
    {
        errno_state = (*__errno_location ());
        writesyslog(
            "flushlog fflush failed for log file <%s>\n", getlogpath());
        writesyslog("errno <%d>\n", errno_state);
        logerror = LOG_ERROR;
    }
}

canonical_original_code:
void flushlog()
{
    int errno_state;
    int irc;
    (*__errno_location ()) = 0;
    if (logfp != ((void *)0)) irc = fflush(logfp);
    if (irc)
    {
        errno_state = (*__errno_location ());
        writesyslog(
            "flushlog fflush failed for log file <%s>\n", getlogpath());
        writesyslog("errno <%d>\n", errno_state);
        logerror = LOG_ERROR;
    }
}

variable_types: irc int


flog

decompiled_code:
void flog(char *format, ...)
{
FILE *v1; // rbp
int v2; // eax
size_t v3; // rax
gcc_va_list arg; // [rsp+8h] [rbp-4E0h] BYREF
char s[1024]; // [rsp+20h] [rbp-4C8h] BYREF

va_start(arg, format);
vsprintf(s, format, arg);
if ( logerror[0] == 1 || (v1 = logfp) == 0LL )
{
writesyslog(s);
}
else
{
v2 = strlen(s);
s[v2] = 10;
s[v2 + 1] = 0;
v3 = strlen(s);
fwrite(s, 1uLL, v3, v1);
flushlog();
}
}

canonical_decompiled_code:
void func10(char *format, ...)
{
FILE *v1; // rbp
int v2; // eax
size_t v3; // rax
gcc_va_list arg; // [rsp+8h] [rbp-4E0h] BYREF
char s[1024]; // [rsp+20h] [rbp-4C8h] BYREF

va_start(arg, format);
vsprintf(s, format, arg);
if ( logerror[0] == 1 || (v1 = logfp) == 0LL )
{
func8(s);
}
else
{
v2 = strlen(s);
s[v2] = 10;
s[v2 + 1] = 0;
v3 = strlen(s);
fwrite(s, 1uLL, v3, v1);
func9();
}
}

original_code:
void flog(const char* output, ...)
{
    char logstring[1024];
    int array_count;
    va_list args;
    __builtin_va_start(args,output);
    vsprintf(logstring, output, args);
    __builtin_va_end(args);
    if ((logerror == LOG_ERROR) || (logfp == ((void *)0)))
    {
        writesyslog(logstring);
        return;
    }
    array_count = (int)strlen(logstring);
    logstring[array_count++] = 0x0a;
    logstring[array_count] = 0x00;
    (void)fwrite(logstring, 1, strlen(logstring), logfp);
    flushlog();
}

canonical_original_code:
void flog(char *output, ...)
{
    char logstring[1024];
    int array_count;
    __builtin_va_list args;
    __builtin_va_start(args,output);
    vsprintf(logstring, output, args);
    __builtin_va_end(args);
    if ((logerror == LOG_ERROR) || (logfp == ((void *)0)))
    {
        writesyslog(logstring);
        return;
    }
    array_count = (int)strlen(logstring);
    logstring[array_count++] = 0x0a;
    logstring[array_count] = 0x00;
    (void)fwrite(logstring, 1, strlen(logstring), logfp);
    flushlog();
}

variable_types:
output
char *


openlogfile

decompiled_code:
__int64 __fastcall openlogfile(const char *a1)
{
__int64 result; // rax

if ( a1 )
{
logfp = fopen(a1, "wb");
if ( logfp )
{
logerror[0] = 0;
result = 0LL;
}
else
{
writesyslog("openlogfile err: fopen failed for logfilename <%s>", a1);
logerror[0] = 1;
result = 1LL;
}
}
else
{
writesyslog("openlogfile err: logfilename is unset (null)");
logerror[0] = 1;
result = 1LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func11(const char *a1)
{
__int64 result; // rax

if ( a1 )
{
logfp = fopen(a1, "wb");
if ( logfp )
{
logerror[0] = 0;
result = 0LL;
}
else
{
func8("openlogfile err: fopen failed for logfilename <%s>", a1);
logerror[0] = 1;
result = 1LL;
}
}
else
{
func8("openlogfile err: logfilename is unset (null)");
logerror[0] = 1;
result = 1LL;
}
return result;
}

original_code:
int openlogfile(char* logfilename)
{
    if (logfilename == ((void *)0))
    {
        writesyslog("openlogfile err: logfilename is unset (null)");
        logerror = LOG_ERROR;
        return logerror;
    }
    logfp = fopen((const char*)logfilename, (const char*)"wb");
    if (logfp == ((void *)0))
    {
        writesyslog("openlogfile err: fopen failed for logfilename <%s>",
            logfilename);
        logerror = LOG_ERROR;
        return logerror;
    }
    logerror = NO_ERROR;
    return logerror;
}

canonical_original_code:
int openlogfile(char *logfilename)
{
    if (logfilename == ((void *)0))
    {
        writesyslog("openlogfile err: logfilename is unset (null)");
        logerror = LOG_ERROR;
        return logerror;
    }
    logfp = fopen((char *)logfilename, (char *)"wb");
    if (logfp == ((void *)0))
    {
        writesyslog("openlogfile err: fopen failed for logfilename <%s>",
            logfilename);
        logerror = LOG_ERROR;
        return logerror;
    }
    logerror = NO_ERROR;
    return logerror;
}

variable_types:
logfilename
char *


logpath

decompiled_code:
__int64 __fastcall logpath(const char *a1)
{
logfilename = a1;
return openlogfile(a1);
}

canonical_decompiled_code:
__int64 __fastcall func12(const char *a1)
{
logfilename = a1;
return func11(a1);
}

original_code:
void logpath(char* logfile)
{
    logfilename = logfile;
    openlogfile(logfilename);
}

canonical_original_code:
void logpath(char *logfile)
{
    logfilename = logfile;
    openlogfile(logfilename);
}

variable_types:
logfile
char *


closelogfile

decompiled_code:
FILE **closelogfile()
{
FILE **result; // rax

if ( logfp )
fclose(logfp);
result = &logfp;
logfp = 0LL;
return result;
}

canonical_decompiled_code:
FILE **func6()
{
FILE **result; // rax

if ( logfp )
fclose(logfp);
result = &logfp;
logfp = 0LL;
return result;
}

original_code:
void closelogfile(void)
{
    if (logfp != ((void *)0)) (void)fclose(logfp);
    logfp = ((void *)0);
}

canonical_original_code:
void closelogfile()
{
    if (logfp != ((void *)0)) (void)fclose(logfp);
    logfp = ((void *)0);
}


flushlog

decompiled_code:
int __fastcall flushlog()
{
int v0; // ebp
int *v1; // rbx
FILE **v2; // rax
unsigned int v3; // ebx
__int64 v4; // rax
__int64 v5; // rdx
__int64 v6; // rcx
__int64 v7; // r8
__int64 v8; // r9
__int64 v9; // rdx
__int64 v10; // rcx
__int64 v11; // r8
__int64 v12; // r9
char v14; // [rsp+0h] [rbp-18h]
char v15; // [rsp+0h] [rbp-18h]

v1 = __errno_location();
*v1 = 0;
v2 = &logfp;
if ( logfp )
{
LODWORD(v2) = fflush(logfp);
v0 = (int)v2;
}
if ( v0 )
{
v3 = *v1;
v4 = getlogpath();
writesyslog("flushlog fflush failed for log file <%s>\n", v4, v5, v6, v7, v8, v14);
writesyslog("errno <%d>\n", v3, v9, v10, v11, v12, v15);
v2 = (FILE **)logerror;
logerror[0] = 1;
}
return (int)v2;
}

canonical_decompiled_code:
int __fastcall func9()
{
int v0; // ebp
int *v1; // rbx
FILE **v2; // rax
unsigned int v3; // ebx
__int64 v4; // rax
__int64 v5; // rdx
__int64 v6; // rcx
__int64 v7; // r8
__int64 v8; // r9
__int64 v9; // rdx
__int64 v10; // rcx
__int64 v11; // r8
__int64 v12; // r9
char v14; // [rsp+0h] [rbp-18h]
char v15; // [rsp+0h] [rbp-18h]

v1 = __errno_location();
*v1 = 0;
v2 = &logfp;
if ( logfp )
{
LODWORD(v2) = fflush(logfp);
v0 = (int)v2;
}
if ( v0 )
{
v3 = *v1;
v4 = func7();
func8("flushlog fflush failed for log file <%s>\n", v4, v5, v6, v7, v8, v14);
func8("errno <%d>\n", v3, v9, v10, v11, v12, v15);
v2 = (FILE **)logerror;
logerror[0] = 1;
}
return (int)v2;
}


flog

decompiled_code:
__int64 flog(char *format, ...)
{
__int64 v1; // rdx
__int64 v2; // rcx
__int64 v3; // r8
__int64 v4; // r9
FILE *v5; // rbp
int v6; // eax
size_t v7; // rax
char v9; // [rsp+0h] [rbp-4E8h]
gcc_va_list arg; // [rsp+8h] [rbp-4E0h] BYREF
char s[1024]; // [rsp+20h] [rbp-4C8h] BYREF
__int64 v12; // [rsp+428h] [rbp-C0h]
__int64 v13; // [rsp+430h] [rbp-B8h]
__int64 v14; // [rsp+438h] [rbp-B0h]
__int64 v15; // [rsp+440h] [rbp-A8h]
__int64 v16; // [rsp+448h] [rbp-A0h]

va_start(arg, format);
v12 = va_arg(arg, _QWORD);
v13 = va_arg(arg, _QWORD);
v14 = va_arg(arg, _QWORD);
v15 = va_arg(arg, _QWORD);
v16 = va_arg(arg, _QWORD);
va_end(arg);
va_start(arg, format);
vsprintf(s, format, arg);
if ( logerror[0] == 1 )
return writesyslog(s, (__int64)format, v1, v2, v3, v4, v9);
v5 = logfp;
if ( !logfp )
return writesyslog(s, (__int64)format, v1, v2, v3, v4, v9);
v6 = strlen(s);
s[v6] = 10;
s[v6 + 1] = 0;
v7 = strlen(s);
fwrite(s, 1uLL, v7, v5);
return flushlog();
}

canonical_decompiled_code:
__int64 func10(char *format, ...)
{
__int64 v1; // rdx
__int64 v2; // rcx
__int64 v3; // r8
__int64 v4; // r9
FILE *v5; // rbp
int v6; // eax
size_t v7; // rax
char v9; // [rsp+0h] [rbp-4E8h]
gcc_va_list arg; // [rsp+8h] [rbp-4E0h] BYREF
char s[1024]; // [rsp+20h] [rbp-4C8h] BYREF
__int64 v12; // [rsp+428h] [rbp-C0h]
__int64 v13; // [rsp+430h] [rbp-B8h]
__int64 v14; // [rsp+438h] [rbp-B0h]
__int64 v15; // [rsp+440h] [rbp-A8h]
__int64 v16; // [rsp+448h] [rbp-A0h]

va_start(arg, format);
v12 = va_arg(arg, _QWORD);
v13 = va_arg(arg, _QWORD);
v14 = va_arg(arg, _QWORD);
v15 = va_arg(arg, _QWORD);
v16 = va_arg(arg, _QWORD);
va_end(arg);
va_start(arg, format);
vsprintf(s, format, arg);
if ( logerror[0] == 1 )
return func8(s, (__int64)format, v1, v2, v3, v4, v9);
v5 = logfp;
if ( !logfp )
return func8(s, (__int64)format, v1, v2, v3, v4, v9);
v6 = strlen(s);
s[v6] = 10;
s[v6 + 1] = 0;
v7 = strlen(s);
fwrite(s, 1uLL, v7, v5);
return func9();
}


openlogfile

decompiled_code:
__int64 __fastcall openlogfile(const char *a1, __int64 a2, __int64 a3, __int64 a4, __int64 a5, __int64 a6)
{
__int64 v6; // rcx
__int64 v7; // r8
__int64 v8; // r9
__int64 result; // rax
char v10; // [rsp+0h] [rbp-8h]

if ( a1 )
{
logfp = fopen(a1, "wb");
if ( logfp )
{
logerror[0] = 0;
result = 0LL;
}
else
{
writesyslog("openlogfile err: fopen failed for logfilename <%s>", (__int64)a1, (__int64)&logfp, v6, v7, v8, v10);
logerror[0] = 1;
result = 1LL;
}
}
else
{
writesyslog("openlogfile err: logfilename is unset (null)", a2, a3, a4, a5, a6, v10);
logerror[0] = 1;
result = 1LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func11(const char *a1, __int64 a2, __int64 a3, __int64 a4, __int64 a5, __int64 a6)
{
__int64 v6; // rcx
__int64 v7; // r8
__int64 v8; // r9
__int64 result; // rax
char v10; // [rsp+0h] [rbp-8h]

if ( a1 )
{
logfp = fopen(a1, "wb");
if ( logfp )
{
logerror[0] = 0;
result = 0LL;
}
else
{
func8("openlogfile err: fopen failed for logfilename <%s>", (__int64)a1, (__int64)&logfp, v6, v7, v8, v10);
logerror[0] = 1;
result = 1LL;
}
}
else
{
func8("openlogfile err: logfilename is unset (null)", a2, a3, a4, a5, a6, v10);
logerror[0] = 1;
result = 1LL;
}
return result;
}


logpath

decompiled_code:
__int64 __fastcall logpath(__int64 a1)
{
logfilename = a1;
return openlogfile();
}

canonical_decompiled_code:
__int64 __fastcall func12(__int64 a1)
{
logfilename = a1;
return func11();
}


decompiled_code:
void v_print(char *format, ...)
{
int v1; // eax
gcc_va_list arg; // [rsp+8h] [rbp-8D0h] BYREF
char s[2048]; // [rsp+20h] [rbp-8B8h] BYREF

if ( verbose_flag )
{
va_start(arg, format);
vsprintf(s, format, arg);
v1 = strlen(s);
s[v1] = 10;
s[v1 + 1] = 0;
printf("%s", s);
}
}

canonical_decompiled_code:
void func2(char *format, ...)
{
int v1; // eax
gcc_va_list arg; // [rsp+8h] [rbp-8D0h] BYREF
char s[2048]; // [rsp+20h] [rbp-8B8h] BYREF

if ( verbose_flag )
{
va_start(arg, format);
vsprintf(s, format, arg);
v1 = strlen(s);
s[v1] = 10;
s[v1 + 1] = 0;
printf("%s", s);
}
}

original_code:
void v_print(const char* output, ...)
{
    if (verbose_flag == 0) return;
    char msg_string[msg_buf];
    int array_count;
    va_list args;
    __builtin_va_start(args,output);
    vsprintf(msg_string, output, args);
    __builtin_va_end(args);
    array_count = (int)strlen(msg_string);
    msg_string[array_count++] = 0x0a;
    msg_string[array_count] = 0x00;
    (void)printf("%s", msg_string);
}

canonical_original_code:
void v_print(char *output, ...)
{
    if (verbose_flag == 0) return;
    char msg_string[-1];
    int array_count;
    __builtin_va_list args;
    __builtin_va_start(args,output);
    vsprintf(msg_string, output, args);
    __builtin_va_end(args);
    array_count = (int)strlen(msg_string);
    msg_string[array_count++] = 0x0a;
    msg_string[array_count] = 0x00;
    (void)printf("%s", msg_string);
}


decompiled_code:
__int64 __fastcall close_socket(int fd)
{
if ( fd == -1 )
return 0xFFFFFFFFLL;
v_print("info : closing socket <%d>", (unsigned int)fd);
if ( close(fd) )
v_print("error <18>: close for socket failed");
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 __fastcall func3(int fd)
{
if ( fd == -1 )
return 0xFFFFFFFFLL;
func2("info : closing socket <%d>", (unsigned int)fd);
if ( close(fd) )
func2("error <18>: close for socket failed");
return 0xFFFFFFFFLL;
}

original_code:
int close_socket(int socket)
{
    if (socket != closed_socket)
    {
        v_print("info : closing socket <%d>", socket);
        if (close(socket))
        {
            v_print("error <18>: close for socket failed");
        }
        socket = closed_socket;
    }
    return socket;
}

variable_types: socket int


decompiled_code:
__int64 print_ssl_error_stack()
{
__int64 result; // rax
__int64 i; // rdi
char v2[1032]; // [rsp+0h] [rbp-408h] BYREF

result = ERR_get_error();
for ( i = result; result; i = result )
{
ERR_error_string_n(i, v2, 1024LL);
v_print("<%s>", v2);
result = ERR_get_error();
}
return result;
}

canonical_decompiled_code:
__int64 func4()
{
__int64 result; // rax
__int64 i; // rdi
char v2[1032]; // [rsp+0h] [rbp-408h] BYREF

result = ERR_get_error();
for ( i = result; result; i = result )
{
ERR_error_string_n(i, v2, 1024LL);
func2("<%s>", v2);
result = ERR_get_error();
}
return result;
}

original_code:
void print_ssl_error_stack(void)
{
    char error_msg[error_buf];
    unsigned long ul_error = ERR_get_error();
    while (ul_error != 0)
    {
        ERR_error_string_n(ul_error, error_msg, (size_t)error_buf);
        (void)v_print("<%s>", error_msg);
        ul_error = ERR_get_error();
    }
    (void)memset((void*)error_msg, 0, sizeof(error_msg));
    ul_error = 0;
}

canonical_original_code:
void print_ssl_error_stack()
{
    char error_msg[-1];
    unsigned long ul_error = ERR_get_error();
    while (ul_error != 0)
    {
        ERR_error_string_n(ul_error, error_msg, (unsigned long)error_buf);
        (void)v_print("<%s>", error_msg);
        ul_error = ERR_get_error();
    }
    (void)memset((void *)error_msg, 0, sizeof(error_msg));
    ul_error = 0;
}


decompiled_code:
__int64 set_fips()
{
__int64 result; // rax

if ( (unsigned int)FIPS_mode_set(1LL) )
{
v_print("FIPS mode has been set");
}
else
{
v_print("error <1>: FIPS mode has not been set");
print_ssl_error_stack();
}
result = FIPS_mode();
gi_fips_mode = result;
return result;
}

canonical_decompiled_code:
__int64 func6()
{
__int64 result; // rax

if ( (unsigned int)FIPS_mode_set(1LL) )
{
func2("FIPS mode has been set");
}
else
{
func2("error <1>: FIPS mode has not been set");
func4();
}
result = FIPS_mode();
gi_fips_mode = result;
return result;
}

original_code:
void set_fips(void)
{
    if (!FIPS_mode_set(1))
    {
        v_print("error <1>: FIPS mode has not been set");
        print_ssl_error_stack();
    }
    else (void)v_print("FIPS mode has been set");
    gi_fips_mode = FIPS_mode();
}

canonical_original_code:
void set_fips()
{
    if (!FIPS_mode_set(1))
    {
        v_print("error <1>: FIPS mode has not been set");
        print_ssl_error_stack();
    }
    else (void)v_print("FIPS mode has been set");
    gi_fips_mode = FIPS_mode();
}


decompiled_code:
__int64 tcp_init()
{
int v0; // eax
unsigned int v1; // ebx
__int16 v2; // ax
struct sockaddr v4; // [rsp+0h] [rbp-18h] BYREF

v_print("info: TCP initialize socket");
v0 = socket(2, 1, 6);
if ( v0 < 0 )
{
v_print("error <2>: Failed to initialize new socket");
v1 = -1;
}
else
{
v1 = v0;
v4.sa_family = 2;
*(_DWORD *)&v4.sa_data[10] = 0;
*(_QWORD *)&v4.sa_data[2] = (unsigned int)_bswap_32(0);
v2 = atol("9000");
*(_WORD *)v4.sa_data = _bswap_16(v2);
v_print("info: Bind socket to address/port:<%s><%s>", "localhost", "9000");
if ( bind(v1, &v4, 0x10u) )
{
v_print("error <3>: TCP bind() failed for port <%s>", "9000");
v1 = -1;
}
else
{
v_print("info: TCP setup listen");
if ( listen(v1, 5) )
{
v_print("error <4>: TCP listen() failed for socket <%d>", v1);
v1 = -1;
}
}
}
return v1;
}

canonical_decompiled_code:
__int64 func7()
{
int v0; // eax
unsigned int v1; // ebx
__int16 v2; // ax
struct sockaddr v4; // [rsp+0h] [rbp-18h] BYREF

func2("info: TCP initialize socket");
v0 = socket(2, 1, 6);
if ( v0 < 0 )
{
func2("error <2>: Failed to initialize new socket");
v1 = -1;
}
else
{
v1 = v0;
v4.sa_family = 2;
*(_DWORD *)&v4.sa_data[10] = 0;
*(_QWORD *)&v4.sa_data[2] = (unsigned int)func0(0);
v2 = atol("9000");
*(_WORD *)v4.sa_data = func1(v2);
func2("info: Bind socket to address/port:<%s><%s>", "localhost", "9000");
if ( bind(v1, &v4, 0x10u) )
{
func2("error <3>: TCP bind() failed for port <%s>", "9000");
v1 = -1;
}
else
{
func2("info: TCP setup listen");
if ( listen(v1, 5) )
{
func2("error <4>: TCP listen() failed for socket <%d>", v1);
v1 = -1;
}
}
}
return v1;
}

original_code:
int tcp_init(void)
{
    int irc = 0;
    int server_socket;
    char* port = ((void *)0);
    struct sockaddr_in stSvrSockAddr;
    uint16_t ut16Port;
    v_print("info: TCP initialize socket");
    port = "9000";
    server_socket = closed_socket;
    server_socket = socket(2, SOCK_STREAM, IPPROTO_TCP);
    if (server_socket < 0)
    {
        v_print("error <2>: Failed to initialize new socket");
        goto Error;
    }
    (void)memset((void*)&stSvrSockAddr, 0, sizeof(stSvrSockAddr));
    stSvrSockAddr.sin_family = (sa_family_t)2;
    stSvrSockAddr.sin_addr.s_addr = htonl(((in_addr_t) 0x00000000));
    ut16Port = (uint16_t)atol((const char*)port);
    stSvrSockAddr.sin_port = htons(ut16Port);
    v_print("info: Bind socket to address/port:<%s><%s>", "localhost",
        port);
    irc = bind(server_socket, (const struct sockaddr*)&stSvrSockAddr,
        (socklen_t)sizeof(stSvrSockAddr));
    if (irc != 0)
    {
        v_print("error <3>: TCP bind() failed for port <%s>", port);
        goto Error;
    }
    v_print("info: TCP setup listen");
    irc = listen(server_socket, 5);
    if (irc != 0)
    {
        v_print("error <4>: TCP listen() failed for socket <%d>", server_socket);
        goto Error;
    }
    return server_socket;
    Error:
    server_socket = socket_error;
    return server_socket;
}

canonical_original_code:
int tcp_init()
{
    int irc = 0;
    int server_socket;
    char *port = ((void *)0);
    struct sockaddr_in stSvrSockAddr;
    unsigned short ut16Port;
    v_print("info: TCP initialize socket");
    port = "9000";
    server_socket = closed_socket;
    server_socket = socket(2, SOCK_STREAM, IPPROTO_TCP);
    if (server_socket < 0)
    {
        v_print("error <2>: Failed to initialize new socket");
        goto Error;
    }
    (void)memset((void *)&stSvrSockAddr, 0, sizeof(stSvrSockAddr));
    stSvrSockAddr.sin_family = (unsigned short)2;
    stSvrSockAddr.sin_addr.s_addr = htonl(((unsigned int) 0x00000000));
    ut16Port = (unsigned short)atol((char *)port);
    stSvrSockAddr.sin_port = htons(ut16Port);
    v_print("info: Bind socket to address/port:<%s><%s>", "localhost",
        port);
    irc = bind(server_socket, (struct sockaddr *)&stSvrSockAddr,
        (unsigned int)sizeof(stSvrSockAddr));
    if (irc != 0)
    {
        v_print("error <3>: TCP bind() failed for port <%s>", port);
        goto Error;
    }
    v_print("info: TCP setup listen");
    irc = listen(server_socket, 5);
    if (irc != 0)
    {
        v_print("error <4>: TCP listen() failed for socket <%d>", server_socket);
        goto Error;
    }
    return server_socket;
    Error:
    server_socket = socket_error;
    return server_socket;
}

variable_types:
port
char *

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

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

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


main

repo: mhrheaume/libxpb

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
char *v3; // rbx
const char *v4; // rsi
const char *v5; // rdi
__int64 v7[20]; // [rsp+0h] [rbp-B8h] BYREF
char v8; // [rsp+A0h] [rbp-18h] BYREF

v7[0] = (__int64)"defaults";
v7[1] = (__int64)&test_defaults;
v7[2] = (__int64)"top_left";
v7[3] = (__int64)&test_top_left;
v7[4] = (__int64)"green_fg";
v7[5] = (__int64)&test_green_fg;
v7[6] = (__int64)"green_bg";
v7[7] = (__int64)&test_green_bg;
v7[8] = (__int64)"big_pads";
v7[9] = (__int64)&test_big_pads;
v7[10] = (__int64)"squares";
v7[11] = (__int64)&test_squares;
v7[12] = (__int64)"many_squares";
v7[13] = (__int64)&test_many_squares;
v7[14] = (__int64)"bad_pointers";
v7[15] = (__int64)&test_bad_pointers;
v7[16] = (__int64)"bad_vals";
v7[17] = (__int64)&test_bad_vals;
v7[18] = (__int64)"too_large";
v7[19] = (__int64)&test_too_large;
v3 = (char *)v7;
do
{
v4 = *(const char **)v3;
printf("Running %s.. ", *(const char **)v3);
v5 = "Fail\n";
if ( !(*((unsigned int (**)(const char *, ...))v3 + 1))("Running %s.. ", v4) )
v5 = "Pass\n";
printf(v5);
v3 += 16;
}
while ( v3 != &v8 );
return 0;
}

original_code:
int main(int argc, char **argv)
{
 int i, status;
 struct test_unit *current_test;
 struct test_unit test_list[10] = {
  { .name = "defaults", .run = test_defaults },
  { .name = "top_left", .run = test_top_left },
  { .name = "green_fg", .run = test_green_fg },
  { .name = "green_bg", .run = test_green_bg },
  { .name = "big_pads", .run = test_big_pads },
  { .name = "squares", .run = test_squares },
  { .name = "many_squares", .run = test_many_squares },
  { .name = "bad_pointers", .run = test_bad_pointers },
  { .name = "bad_vals", .run = test_bad_vals },
  { .name = "too_large", .run = test_too_large }
 };
 for (i = 0; i < 10; i++) {
  current_test = &test_list[i];
  printf("Running %s.. ", current_test->name);
  status = (*(current_test->run))();
  printf(status == 0 ? "Pass\n" : "Fail\n");
 }
 return 0;
}

canonical_original_code:
int main(int argc, char **argv)
{
 int i; int status;
 struct test_unit *current_test;
 struct test_unit test_list[10] = {
  { .name = "defaults", .run = test_defaults },
  { .name = "top_left", .run = test_top_left },
  { .name = "green_fg", .run = test_green_fg },
  { .name = "green_bg", .run = test_green_bg },
  { .name = "big_pads", .run = test_big_pads },
  { .name = "squares", .run = test_squares },
  { .name = "many_squares", .run = test_many_squares },
  { .name = "bad_pointers", .run = test_bad_pointers },
  { .name = "bad_vals", .run = test_bad_vals },
  { .name = "too_large", .run = test_too_large }
 };
 for (i = 0; i < 10; i++) {
  current_test = &test_list[i];
  printf("Running %s.. ", current_test->name);
  status = (*(current_test->run))();
  printf(status == 0 ? "Pass\n" : "Fail\n");
 }
 return 0;
}

variable_types:
argv
char **

variable_types: i int

variable_types: status int

variable_types: struct test_unit { char *name; int (*run)(); } *

variable_types: struct test_unit { char *name; int (*run)(); } [10]


decompiled_code:
char *__fastcall xpb_status_tostring(unsigned int a1)
{
char *result; // rax

if ( a1 > 0xB )
result = 0LL;
else
result = (&strmap_0)[a1];
return result;
}

canonical_decompiled_code:
char *__fastcall func12(unsigned int a1)
{
char *result; // rax

if ( a1 > 0xB )
result = 0LL;
else
result = (&strmap_0)[a1];
return result;
}

original_code:
const char *xpb_status_tostring(int status)
{
 static const char *strmap[] = {
  "success",
  "bad number of rectangles",
  "bad padding number",
  "bad rectangle x-size",
  "bad rectangle y-size",
  "bad x-position",
  "bad y-position",
  "bad foreground color",
  "bad background color",
  "out of memory",
  "bar too large",
  "bad pointer"
 };
 if (is_bad_status(status)) {
  return ((void *)0);
 }
 return strmap[status];
}

canonical_original_code:
char *xpb_status_tostring(int status)
{
 static char *strmap[] = {
  "success",
  "bad number of rectangles",
  "bad padding number",
  "bad rectangle x-size",
  "bad rectangle y-size",
  "bad x-position",
  "bad y-position",
  "bad foreground color",
  "bad background color",
  "out of memory",
  "bar too large",
  "bad pointer"
 };
 if (is_bad_status(status)) {
  return ((void *)0);
 }
 return strmap[status];
}

variable_types:
strmap
char *[]


repo: mhspradlin/c

decompiled_code:
__int64 __fastcall get_node(__int64 a1, int a2)
{
return *(_QWORD *)(a1 + 8LL * a2);
}

canonical_decompiled_code:
__int64 __fastcall func10(__int64 a1, int a2)
{
return *(_QWORD *)(a1 + 8LL * a2);
}

original_code:
struct node *get_node (struct node **cache, int id) {
    return cache[id];
}

canonical_original_code:
struct node *get_node(struct node **cache, int id) {
    return cache[id];
}

variable_types:
cache
struct node **

variable_types: id int

return_type: struct node { int num_back; int *back; int id; } *


decompiled_code:
int __fastcall print_path(unsigned int *a1)
{
int v1; // er12
__int64 v2; // r12
__int64 v3; // rbx

v1 = a1[1];
if ( !v1 )
return puts("No path exists.");
printf("Path order: %d", **((unsigned int **)a1 + 1));
if ( v1 > 1 )
{
v2 = 4LL * (unsigned int)v1;
v3 = 4LL;
do
{
printf(", %d", *(unsigned int *)(*((_QWORD *)a1 + 1) + v3));
v3 += 4LL;
}
while ( v3 != v2 );
}
return printf("\nCost: %d\n", *a1);
}

canonical_decompiled_code:
int __fastcall func11(unsigned int *a1)
{
int v1; // er12
__int64 v2; // r12
__int64 v3; // rbx

v1 = a1[1];
if ( !v1 )
return puts("No path exists.");
printf("Path order: %d", **((unsigned int **)a1 + 1));
if ( v1 > 1 )
{
v2 = 4LL * (unsigned int)v1;
v3 = 4LL;
do
{
printf(", %d", *(unsigned int *)(*((_QWORD *)a1 + 1) + v3));
v3 += 4LL;
}
while ( v3 != v2 );
}
return printf("\nCost: %d\n", *a1);
}

original_code:
void print_path (struct path *path) {
    int len = path->numelems;
    if (len == 0) {
        printf ("No path exists.\n");
        return;
    }
    int i;
    printf ("Path order: %d", path->elems[0]);
    for (i = 1; i < len; i++)
        printf (", %d", path->elems[i]);
    printf ("\nCost: %d\n", path->length);
    return;
}

canonical_original_code:
void print_path(struct path *path) {
    int len = path->numelems;
    if (len == 0) {
        printf ("No path exists.\n");
        return;
    }
    int i;
    printf ("Path order: %d", path->elems[0]);
    for (i = 1; i < len; i++)
        printf (", %d", path->elems[i]);
    printf ("\nCost: %d\n", path->length);
    return;
}

variable_types: struct path { int length; int numelems; int *elems; } *

variable_types: len int


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

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

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

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

original_code:
struct path *no_path (void) {
    struct path *stub = malloc (sizeof (struct path));
    memset (stub, 0, sizeof (struct path));
    stub->numelems = 0;
    return stub;
}

canonical_original_code:
struct path *no_path() {
    struct path *stub = malloc (sizeof (struct path));
    memset (stub, 0, sizeof (struct path));
    stub->numelems = 0;
    return stub;
}

return_type: struct path { int length; int numelems; int *elems; } *


decompiled_code:
__int64 __fastcall has_cycle(__int64 a1)
{
int v1; // eax
unsigned int v2; // er12
__int64 v3; // rbx

v1 = *(_DWORD *)(a1 + 4);
v2 = *(_DWORD *)(*(_QWORD *)(a1 + 8) + 4LL * v1 - 4);
if ( v1 <= 1 )
return 0LL;
v3 = 0LL;
while ( 1 )
{
printf("last: %d, considering: %d\n", v2, *(unsigned int *)(*(_QWORD *)(a1 + 8) + 4 * v3));
if ( *(_DWORD *)(*(_QWORD *)(a1 + 8) + 4 * v3) == v2 )
break;
if ( *(_DWORD *)(a1 + 4) - 1 <= (int)++v3 )
return 0LL;
}
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func13(__int64 a1)
{
int v1; // eax
unsigned int v2; // er12
__int64 v3; // rbx

v1 = *(_DWORD *)(a1 + 4);
v2 = *(_DWORD *)(*(_QWORD *)(a1 + 8) + 4LL * v1 - 4);
if ( v1 <= 1 )
return 0LL;
v3 = 0LL;
while ( 1 )
{
printf("last: %d, considering: %d\n", v2, *(unsigned int *)(*(_QWORD *)(a1 + 8) + 4 * v3));
if ( *(_DWORD *)(*(_QWORD *)(a1 + 8) + 4 * v3) == v2 )
break;
if ( *(_DWORD *)(a1 + 4) - 1 <= (int)++v3 )
return 0LL;
}
return 1LL;
}

original_code:
_Bool has_cycle (struct path *path) {
    int last_stop = path->elems[path->numelems - 1];
    int i;
    for (i = 0; i < path->numelems - 1; i++) {
        printf ("last: %d, considering: %d\n", last_stop, path->elems[i]);
        if (last_stop == path->elems[i])
            return 1;
    }
    return 0;
}

canonical_original_code:
_Bool has_cycle(struct path *path) {
    int last_stop = path->elems[path->numelems - 1];
    int i;
    for (i = 0; i < path->numelems - 1; i++) {
        printf ("last: %d, considering: %d\n", last_stop, path->elems[i]);
        if (last_stop == path->elems[i])
            return 1;
    }
    return 0;
}

user_defined_types: struct path { int length; int numelems; int *elems; }


decompiled_code:
void *__fastcall init_path_cache(int a1)
{
void *v1; // rax

v1 = malloc(8LL * a1);
return memset(v1, 0, 8LL * a1);
}

canonical_decompiled_code:
void *__fastcall func14(int a1)
{
void *v1; // rax

v1 = malloc(8LL * a1);
return memset(v1, 0, 8LL * a1);
}

original_code:
struct path **init_path_cache (int num_nodes) {
    struct path **cache = malloc (num_nodes * sizeof (struct path *));
    memset (cache, 0, num_nodes * sizeof (struct path *));
    return cache;
}

canonical_original_code:
struct path **init_path_cache(int num_nodes) {
    struct path **cache = malloc (num_nodes * sizeof (struct path *));
    memset (cache, 0, num_nodes * sizeof (struct path *));
    return cache;
}

variable_types: struct path { int length; int numelems; int *elems; } **


decompiled_code:
unsigned int *__fastcall find_shortest(__int64 a1, __int64 a2, int a3, unsigned int a4, int a5)
{
void *v7; // rax

v7 = init_path_cache(a3);
return find_shortest_(a1, (__int64)v7, a2, a4, a5);
}

canonical_decompiled_code:
unsigned int *__fastcall func16(__int64 a1, __int64 a2, int a3, unsigned int a4, int a5)
{
void *v7; // rax

v7 = func14(a3);
return func15(a1, (__int64)v7, a2, a4, a5);
}

original_code:
struct path *find_shortest (int **weights, struct node **graph, int num_nodes, int id1, int id2) {
    struct path **path_cache = init_path_cache (num_nodes);
    return find_shortest_ (weights, path_cache, graph, id1, id2);
}

canonical_original_code:
struct path *find_shortest(int **weights, struct node **graph, int num_nodes, int id1, int id2) {
    struct path **path_cache = init_path_cache (num_nodes);
    return find_shortest_ (weights, path_cache, graph, id1, id2);
}

variable_types:
weights
int **

variable_types: struct node { int num_back; int *back; int id; } **


decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int result; // eax
int v4; // er14
_QWORD *v5; // rax
_QWORD *v6; // r15
void **v7; // rbx
__int64 v8; // r13
void *v9; // rbx
int v10; // er12
int v11; // eax
unsigned int *v12; // rax

result = 1;
if ( argc == 4 )
{
v4 = num_nodes(argv[1]);
v5 = malloc(8LL * v4);
v6 = v5;
if ( v4 > 0 )
{
v7 = (void **)v5;
v8 = (__int64)&v5[(unsigned int)(v4 - 1) + 1];
do
*v7++ = malloc(4LL * v4);
while ( v7 != (void **)v8 );
}
v9 = init_cache(v4);
construct_from_file(v6, (__int64)v9, argv[1]);
v10 = atoi(argv[3]);
v11 = atoi(argv[2]);
v12 = find_shortest((__int64)v6, (__int64)v9, v4, v11, v10);
print_path(v12);
result = 0;
}
return result;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int result; // eax
int v4; // er14
_QWORD *v5; // rax
_QWORD *v6; // r15
void **v7; // rbx
__int64 v8; // r13
void *v9; // rbx
int v10; // er12
int v11; // eax
unsigned int *v12; // rax

result = 1;
if ( argc == 4 )
{
v4 = func7(argv[1]);
v5 = malloc(8LL * v4);
v6 = v5;
if ( v4 > 0 )
{
v7 = (void **)v5;
v8 = (__int64)&v5[(unsigned int)(v4 - 1) + 1];
do
*v7++ = malloc(4LL * v4);
while ( v7 != (void **)v8 );
}
v9 = func9(v4);
func8(v6, (__int64)v9, argv[1]);
v10 = atoi(argv[3]);
v11 = atoi(argv[2]);
v12 = func16((__int64)v6, (__int64)v9, v4, v11, v10);
func11(v12);
result = 0;
}
return result;
}

original_code:
int main (int argc, char **argv) {
    if (argc != 4)
        return 1;
    int num_verts = num_nodes (argv[1]);
    int **weights = malloc (num_verts * sizeof (int *));
    int i;
    for (i = 0; i < num_verts; i++)
        weights[i] = malloc (num_verts * sizeof (int));
    struct node **graph = init_cache (num_verts);
    construct_from_file (weights, graph, argv[1]);
    struct path *shortest = find_shortest (weights, graph, num_verts, atoi(argv[2]), atoi(argv[3]));
    print_path (shortest);
    return 0;
}

canonical_original_code:
int main(int argc, char **argv) {
    if (argc != 4)
        return 1;
    int num_verts = num_nodes (argv[1]);
    int **weights = malloc (num_verts * sizeof (int *));
    int i;
    for (i = 0; i < num_verts; i++)
        weights[i] = malloc (num_verts * sizeof (int));
    struct node **graph = init_cache (num_verts);
    construct_from_file (weights, graph, argv[1]);
    struct path *shortest = find_shortest (weights, graph, num_verts, atoi(argv[2]), atoi(argv[3]));
    print_path (shortest);
    return 0;
}

variable_types: argc int

user_defined_types: struct node { int num_back; int *back; int id; }


cmdBufferGrow

repo: michael-grunder/buffer-optimize

decompiled_code:
__int64 __fastcall cmdBufferGrow(__int64 a1, __int64 a2)
{
unsigned __int64 v2; // rsi
size_t v3; // rbp
void *v4; // rax

v2 = *(_QWORD *)(a1 + 16) + a2;
v3 = v2 + 0x100000;
if ( v2 <= 0xFFFFF )
v3 = 2 * v2;
v4 = realloc(*(void **)a1, v3);
if ( !v4 )
return 0xFFFFFFFFLL;
*(_QWORD *)(a1 + 8) = v3;
*(_QWORD *)a1 = v4;
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, __int64 a2)
{
unsigned __int64 v2; // rsi
size_t v3; // rbp
void *v4; // rax

v2 = *(_QWORD *)(a1 + 16) + a2;
v3 = v2 + 0x100000;
if ( v2 <= 0xFFFFF )
v3 = 2 * v2;
v4 = realloc(*(void **)a1, v3);
if ( !v4 )
return 0xFFFFFFFFLL;
*(_QWORD *)(a1 + 8) = v3;
*(_QWORD *)a1 = v4;
return 0LL;
}

original_code:
static inline int cmdBufferGrow(cmdBuffer *buffer, size_t addlen) {
    size_t newlen = buffer->pos+addlen;
    char *newbuf;
    if(newlen < (1024*1024)) {
        newlen *= 2;
    } else {
        newlen += (1024*1024);
    }
    if((newbuf = realloc(buffer->buf, newlen)) == ((void *)0))
        return -1;
    buffer->size = newlen;
    buffer->buf = newbuf;
    return 0;
}

canonical_original_code:
static inline int cmdBufferGrow(struct _cmdBuffer *buffer, unsigned long addlen) {
    unsigned long newlen = buffer->pos+addlen;
    char *newbuf;
    if(newlen < (1024*1024)) {
        newlen *= 2;
    } else {
        newlen += (1024*1024);
    }
    if((newbuf = realloc(buffer->buf, newlen)) == ((void *)0))
        return -1;
    buffer->size = newlen;
    buffer->buf = newbuf;
    return 0;
}

variable_types: struct _cmdBuffer { char *buf; unsigned long size; unsigned long pos; unsigned int cmd_count; } *

variable_types:
addlen
unsigned long

variable_types:
newlen
unsigned long

variable_types:
newbuf
char *


cmdBufferCreate

decompiled_code:
_QWORD *cmdBufferCreate()
{
_QWORD *v0; // rbx
void *v1; // rbp

v0 = calloc(1uLL, 0x20uLL);
if ( v0 )
{
v1 = malloc(0x8000uLL);
*v0 = v1;
if ( v1 )
{
v0[1] = 0x8000LL;
}
else
{
free(v0);
v0 = 0LL;
}
}
return v0;
}

canonical_decompiled_code:
_QWORD *func1()
{
_QWORD *v0; // rbx
void *v1; // rbp

v0 = calloc(1uLL, 0x20uLL);
if ( v0 )
{
v1 = malloc(0x8000uLL);
*v0 = v1;
if ( v1 )
{
v0[1] = 0x8000LL;
}
else
{
free(v0);
v0 = 0LL;
}
}
return v0;
}

original_code:
cmdBuffer* cmdBufferCreate(void) {
    cmdBuffer *buffer;
    if((buffer = calloc(1, sizeof(cmdBuffer))) == ((void *)0))
        return ((void *)0);
    if((buffer->buf = malloc(32768)) == ((void *)0)) {
        free(buffer);
        return ((void *)0);
    }
    buffer->size = 32768;
    return buffer;
}

canonical_original_code:
struct _cmdBuffer *cmdBufferCreate() {
    struct _cmdBuffer *buffer;
    if((buffer = calloc(1, sizeof(cmdBuffer))) == ((void *)0))
        return ((void *)0);
    if((buffer->buf = malloc(32768)) == ((void *)0)) {
        free(buffer);
        return ((void *)0);
    }
    buffer->size = 32768;
    return buffer;
}

return_type: struct _cmdBuffer { char *buf; unsigned long size; unsigned long pos; unsigned int cmd_count; } *


cmdBufferFree

decompiled_code:
__int64 __fastcall cmdBufferFree(void *ptr)
{
void *v2; // rdi

if ( !ptr )
return 0xFFFFFFFFLL;
v2 = *(void **)ptr;
if ( v2 )
free(v2);
free(ptr);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func2(void *ptr)
{
void *v2; // rdi

if ( !ptr )
return 0xFFFFFFFFLL;
v2 = *(void **)ptr;
if ( v2 )
free(v2);
free(ptr);
return 0LL;
}

original_code:
int cmdBufferFree(cmdBuffer *buffer) {
    if(!buffer)
        return -1;
    if(buffer->buf)
        free(buffer->buf);
    free(buffer);
    return 0;
}

canonical_original_code:
int cmdBufferFree(struct _cmdBuffer *buffer) {
    if(!buffer)
        return -1;
    if(buffer->buf)
        free(buffer->buf);
    free(buffer);
    return 0;
}

user_defined_types: struct _cmdBuffer { char *buf; unsigned long size; unsigned long pos; unsigned int cmd_count; }


cmdBufferAppend

decompiled_code:
__int64 __fastcall cmdBufferAppend(__int64 a1, const void *a2, size_t a3, int a4)
{
if ( *(_QWORD *)(a1 + 16) + a3 > *(_QWORD *)(a1 + 8) && (unsigned int)cmdBufferGrow(a1, a3) )
return 0xFFFFFFFFLL;
memcpy((void *)(*(_QWORD *)a1 + *(_QWORD *)(a1 + 16)), a2, a3);
*(_QWORD *)(a1 + 16) += a3;
*(_DWORD *)(a1 + 24) += a4;
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, const void *a2, size_t a3, int a4)
{
if ( *(_QWORD *)(a1 + 16) + a3 > *(_QWORD *)(a1 + 8) && (unsigned int)func0(a1, a3) )
return 0xFFFFFFFFLL;
memcpy((void *)(*(_QWORD *)a1 + *(_QWORD *)(a1 + 16)), a2, a3);
*(_QWORD *)(a1 + 16) += a3;
*(_DWORD *)(a1 + 24) += a4;
return 0LL;
}

original_code:
int cmdBufferAppend(cmdBuffer *buffer, char *str, size_t len,
                    unsigned int cmd_count)
{
    if(buffer->pos + len > buffer->size && cmdBufferGrow(buffer, len)!=0)
        return -1;
    memcpy(buffer->buf+buffer->pos, str, len);
    buffer->pos += len;
    buffer->cmd_count += cmd_count;
    return 0;
}

canonical_original_code:
int cmdBufferAppend(struct _cmdBuffer *buffer, char *str, unsigned long len, unsigned int cmd_count)
{
    if(buffer->pos + len > buffer->size && cmdBufferGrow(buffer, len)!=0)
        return -1;
    memcpy(buffer->buf+buffer->pos, str, len);
    buffer->pos += len;
    buffer->cmd_count += cmd_count;
    return 0;
}

variable_types:
str
char *

variable_types:
len
unsigned long