repo: schmijos/dancepads

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int v3; // ebp
__int16 v5; // [rsp+0h] [rbp-78h] BYREF
__m128i v6; // [rsp+2h] [rbp-76h]
char v7[8]; // [rsp+12h] [rbp-66h] BYREF

v3 = socket(1, 1, 0);
if ( (v3 & 0x80000000) != 0 )
errorExit("socket");
v5 = 1;
strcpy(v7, "cket");
v6 = _mm_load_si128((const __m128i *)&LC7);
printf("Found Socket %d\n", v3);
if ( connect(v3, (const struct sockaddr *)&v5, 0x16u) )
errorExit("connect");
puts("Choose Pad by Number:");
copyData(v3, 0LL);
printf("Pad Status: ");
copyData(1LL, v3);
puts("\nSend Command to Pad:");
copyData(v3, 0LL);
close(v3);
puts("Connection closed.");
return 0;
}

original_code:
int main(int argc, char *argv[]) {
 struct sockaddr_un strAddr;
 socklen_t lenAddr;
 int fdSock;
 if ((fdSock = socket(1, SOCK_STREAM, 0)) < 0)
  errorExit("socket");
 strAddr.sun_family = 1;
 strcpy(strAddr.sun_path, "/tmp/dancepad_socket");
 lenAddr = sizeof(strAddr.sun_family) + strlen(strAddr.sun_path);
 printf("Found Socket %d\n", fdSock);
 if (connect(fdSock, (struct sockaddr*) &strAddr, lenAddr) != 0)
  errorExit("connect");
 printf("Choose Pad by Number:\n");
 copyData(fdSock, 0);
 printf("Pad Status: ");
 copyData(1, fdSock);
 printf("\nSend Command to Pad:\n");
 copyData(fdSock, 0);
 close(fdSock);
 printf("Connection closed.\n");
 return 0;
}

canonical_original_code:
int main(int argc, char *argv[]) {
 struct sockaddr_un strAddr;
 unsigned int lenAddr;
 int fdSock;
 if ((fdSock = socket(1, SOCK_STREAM, 0)) < 0)
  errorExit("socket");
 strAddr.sun_family = 1;
 strcpy(strAddr.sun_path, "/tmp/dancepad_socket");
 lenAddr = sizeof(strAddr.sun_family) + strlen(strAddr.sun_path);
 printf("Found Socket %d\n", fdSock);
 if (connect(fdSock, (struct sockaddr *) &strAddr, lenAddr) != 0)
  errorExit("connect");
 printf("Choose Pad by Number:\n");
 copyData(fdSock, 0);
 printf("Pad Status: ");
 copyData(1, fdSock);
 printf("\nSend Command to Pad:\n");
 copyData(fdSock, 0);
 close(fdSock);
 printf("Connection closed.\n");
 return 0;
}

variable_types: struct sockaddr_un { unsigned short sun_family; char sun_path[108]; }

variable_types:
lenAddr
unsigned int

variable_types: fdSock int


decompiled_code:
int uds_listen()
{
int v0; // er12
int v1; // eax
int v2; // ebp
char buf[2]; // [rsp+Ah] [rbp-48Eh] BYREF
socklen_t addr_len; // [rsp+Ch] [rbp-48Ch] BYREF
char addr[18]; // [rsp+10h] [rbp-488h] BYREF
char v7[8]; // [rsp+22h] [rbp-476h] BYREF
char v8[1048]; // [rsp+80h] [rbp-418h] BYREF

v0 = socket(1, 1, 0);
if ( v0 < 0 )
errorExit("socket");
unlink("/tmp/dancepad_socket");
*(_WORD *)addr = 1;
strcpy(v7, "cket");
addr_len = 22;
*(__m128i *)&addr[2] = _mm_load_si128((const __m128i *)&LC11);
if ( bind(v0, (const struct sockaddr *)addr, 0x16u) )
errorExit("bind");
if ( listen(v0, 5) )
errorExit("listen");
printf("uds server initialized with socket %d\n", (unsigned int)v0);
while ( 1 )
{
v1 = accept(v0, (struct sockaddr *)addr, &addr_len);
v2 = v1;
if ( v1 < 0 )
break;
if ( read(v1, v8, 8uLL) < 0 )
errorExit("read");
printf("Read: %s\n", v8);
if ( write(v2, "42", 3uLL) < 0 )
errorExit("write");
printf("Wrote: %s\n", "42");
if ( read(v2, buf, 2uLL) < 0 )
errorExit("read");
printf("uds got %s for Pad %s\n", buf, v8);
close(v2);
}
return close(v0);
}

canonical_decompiled_code:
int func0()
{
int v0; // er12
int v1; // eax
int v2; // ebp
char buf[2]; // [rsp+Ah] [rbp-48Eh] BYREF
socklen_t addr_len; // [rsp+Ch] [rbp-48Ch] BYREF
char addr[18]; // [rsp+10h] [rbp-488h] BYREF
char v7[8]; // [rsp+22h] [rbp-476h] BYREF
char v8[1048]; // [rsp+80h] [rbp-418h] BYREF

v0 = socket(1, 1, 0);
if ( v0 < 0 )
errorExit("socket");
unlink("/tmp/dancepad_socket");
*(_WORD *)addr = 1;
strcpy(v7, "cket");
addr_len = 22;
*(__m128i *)&addr[2] = _mm_load_si128((const __m128i *)&LC11);
if ( bind(v0, (const struct sockaddr *)addr, 0x16u) )
errorExit("bind");
if ( listen(v0, 5) )
errorExit("listen");
printf("uds server initialized with socket %d\n", (unsigned int)v0);
while ( 1 )
{
v1 = accept(v0, (struct sockaddr *)addr, &addr_len);
v2 = v1;
if ( v1 < 0 )
break;
if ( read(v1, v8, 8uLL) < 0 )
errorExit("read");
printf("Read: %s\n", v8);
if ( write(v2, "42", 3uLL) < 0 )
errorExit("write");
printf("Wrote: %s\n", "42");
if ( read(v2, buf, 2uLL) < 0 )
errorExit("read");
printf("uds got %s for Pad %s\n", buf, v8);
close(v2);
}
return close(v0);
}

original_code:
void uds_listen(dp_exchange_t* p) {
 struct sockaddr_un strAddr;
 socklen_t lenAddr;
 int fdSock;
 int fdConn;
 if ((fdSock = socket(1, SOCK_STREAM, 0)) < 0)
  errorExit("socket");
 unlink("/tmp/dancepad_socket");
 strAddr.sun_family = 1;
 strcpy(strAddr.sun_path, "/tmp/dancepad_socket");
 lenAddr = sizeof(strAddr.sun_family) + strlen(strAddr.sun_path);
 if (bind(fdSock, (struct sockaddr*) &strAddr, lenAddr) != 0)
  errorExit("bind");
 if (listen(fdSock, 5) != 0)
  errorExit("listen");
 printf("uds server initialized with socket %d\n", fdSock);
 while ((fdConn = accept(fdSock, (struct sockaddr*) &strAddr, &lenAddr)) >= 0) {
  char padNr[1024];
  if (read(fdConn, padNr, 8) < 0) {
   errorExit("read");
  }
  printf("Read: %s\n", padNr);
  char* padStatus = "42";
  if (write(fdConn, padStatus, 3) < 0) {
   errorExit("write");
  }
  printf("Wrote: %s\n", padStatus);
  char padCmd[2];
  if (read(fdConn, padCmd, 2) < 0) {
   errorExit("read");
  }
  printf("uds got %s for Pad %s\n", padCmd, padNr);
  close(fdConn);
 }
 close(fdSock);
}

canonical_original_code:
void uds_listen(struct dp_exchange *p) {
 struct sockaddr_un strAddr;
 unsigned int lenAddr;
 int fdSock;
 int fdConn;
 if ((fdSock = socket(1, SOCK_STREAM, 0)) < 0)
  errorExit("socket");
 unlink("/tmp/dancepad_socket");
 strAddr.sun_family = 1;
 strcpy(strAddr.sun_path, "/tmp/dancepad_socket");
 lenAddr = sizeof(strAddr.sun_family) + strlen(strAddr.sun_path);
 if (bind(fdSock, (struct sockaddr *) &strAddr, lenAddr) != 0)
  errorExit("bind");
 if (listen(fdSock, 5) != 0)
  errorExit("listen");
 printf("uds server initialized with socket %d\n", fdSock);
 while ((fdConn = accept(fdSock, (struct sockaddr *) &strAddr, &lenAddr)) >= 0) {
  char padNr[1024];
  if (read(fdConn, padNr, 8) < 0) {
   errorExit("read");
  }
  printf("Read: %s\n", padNr);
  char *padStatus = "42";
  if (write(fdConn, padStatus, 3) < 0) {
   errorExit("write");
  }
  printf("Wrote: %s\n", padStatus);
  char padCmd[2];
  if (read(fdConn, padCmd, 2) < 0) {
   errorExit("read");
  }
  printf("uds got %s for Pad %s\n", padCmd, padNr);
  close(fdConn);
 }
 close(fdSock);
}

variable_types: struct dp_exchange { union pthread_mutex_t { struct __pthread_mutex_s { int __lock; unsigned int __count; int __owner; unsigned int __nusers; int __kind; short __spins; short __elision; struct __pthread_internal_list { struct __pthread_internal_list *__prev; struct __pthread_internal_list *__next; } __list; } __data; char __size[40]; long __align; } mutex; unsigned int padnr; union dp_command { unsigned int is_rgb; struct { unsigned int; unsigned int r; unsigned int g; unsigned int b; } rgb; unsigned char bytes[2]; unsigned int is_not_empty; } command; union dp_status { unsigned int is_pressed; struct { unsigned int; unsigned int value; } data; unsigned char byte; } status; } *

variable_types: fdConn int

variable_types:
padNr
char [1024]

variable_types:
padStatus
char *

variable_types:
padCmd
char [2]

return_type: void

user_defined_types: struct sockaddr_un { unsigned short sun_family; char sun_path[108]; }

user_defined_types: struct dp_exchange { union pthread_mutex_t mutex; unsigned int padnr; union dp_command command; union dp_status status; }

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

user_defined_types: union pthread_mutex_t { struct __pthread_mutex_s __data; char __size[40]; long __align; }

user_defined_types: struct __pthread_mutex_s { int __lock; unsigned int __count; int __owner; unsigned int __nusers; int __kind; short __spins; short __elision; struct __pthread_internal_list __list; }


errorExit

decompiled_code:
void __fastcall __noreturn errorExit(const char *a1)
{
perror(a1);
exit(1);
}

canonical_decompiled_code:
void __fastcall __noreturn func0(const char *a1)
{
perror(a1);
exit(1);
}

original_code:
void errorExit(char* msg) {
 perror(msg);
 exit(1);
}

canonical_original_code:
void errorExit(char *msg) {
 perror(msg);
 exit(1);
}

variable_types:
msg
char *


copyData

decompiled_code:
ssize_t __fastcall copyData(int fd, int a2)
{
ssize_t result; // rax
_BYTE v3[1048]; // [rsp+0h] [rbp-418h] BYREF

while ( 1 )
{
result = read(a2, v3, 0x400uLL);
if ( (int)result <= 0 )
break;
if ( write(fd, v3, (int)result) != (int)result )
errorExit("write");
}
if ( (_DWORD)result )
errorExit("read");
return result;
}

canonical_decompiled_code:
ssize_t __fastcall func1(int fd, int a2)
{
ssize_t result; // rax
_BYTE v3[1048]; // [rsp+0h] [rbp-418h] BYREF

while ( 1 )
{
result = read(a2, v3, 0x400uLL);
if ( (int)result <= 0 )
break;
if ( write(fd, v3, (int)result) != (int)result )
func0("write");
}
if ( (_DWORD)result )
func0("read");
return result;
}

original_code:
void copyData(int iDest, int iSrc) {
 char acBuff[1024];
 int iCount;
 while ((iCount = read(iSrc, acBuff, sizeof(acBuff))) > 0) {
  if (write(iDest, acBuff, iCount) != iCount)
   errorExit("write");
 }
 if (iCount < 0)
  errorExit("read");
 return;
}

variable_types: iDest int

variable_types: iSrc int

variable_types:
acBuff
char [1024]

variable_types: iCount int


onSignal

repo: schoentoon/mtop

decompiled_code:
void __noreturn onSignal()
{
event_base_free(event_base);
exit(0);
}

canonical_decompiled_code:
void __noreturn func0()
{
event_base_free(event_base);
exit(0);
}

original_code:
void onSignal(int signal) {
  event_base_free(event_base);
  exit(0);
}

variable_types: signal int


usage

decompiled_code:
__int64 __fastcall usage(const char *a1)
{
fprintf(stderr, "USAGE: %s [options]\n", a1);
fwrite("-h, --help\tShow this help message.\n", 1uLL, 0x23uLL, stderr);
fwrite("-C, --config\tUse this config file.\n", 1uLL, 0x23uLL, stderr);
fwrite("-D, --debug\tIncrease the debug level\n", 1uLL, 0x25uLL, stderr);
fwrite(
" \tYou can also directly set a certain debug level with -D5 where 5 is the debug level.\n",
1uLL,
0x61uLL,
stderr);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func1(const char *a1)
{
fprintf(stderr, "USAGE: %s [options]\n", a1);
fwrite("-h, --help\tShow this help message.\n", 1uLL, 0x23uLL, stderr);
fwrite("-C, --config\tUse this config file.\n", 1uLL, 0x23uLL, stderr);
fwrite("-D, --debug\tIncrease the debug level\n", 1uLL, 0x25uLL, stderr);
fwrite(
" \tYou can also directly set a certain debug level with -D5 where 5 is the debug level.\n",
1uLL,
0x61uLL,
stderr);
return 0LL;
}

original_code:
int usage(char* program) {
  fprintf(stderr, "USAGE: %s [options]\n", program);
  fprintf(stderr, "-h, --help\tShow this help message.\n");
  fprintf(stderr, "-C, --config\tUse this config file.\n");
  fprintf(stderr, "-D, --debug\tIncrease the debug level\n");
  fprintf(stderr, "           \tYou can also directly set a certain debug level with -D5 where 5 is the debug level.\n");
  return 0;
}

canonical_original_code:
int usage(char *program) {
  fprintf(stderr, "USAGE: %s [options]\n", program);
  fprintf(stderr, "-h, --help\tShow this help message.\n");
  fprintf(stderr, "-C, --config\tUse this config file.\n");
  fprintf(stderr, "-D, --debug\tIncrease the debug level\n");
  fprintf(stderr, "           \tYou can also directly set a certain debug level with -D5 where 5 is the debug level.\n");
  return 0;
}

variable_types:
program
char *

return_type: int


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // eax
int result; // eax
char *v5; // r13
int *v6; // rax
int *v7; // r12
unsigned __int64 v8; // rax
int v9; // er8
int longind[11]; // [rsp+Ch] [rbp-2Ch] BYREF

while ( 1 )
{
v3 = getopt_long(argc, (char *const *)argv, "hD::C:", &options, longind);
if ( v3 == -1 )
break;
switch ( v3 )
{
case 'D':
v5 = optarg;
if ( optarg )
{
v6 = _errno_location();
*v6 = 0;
v7 = v6;
v8 = strtol(v5, 0LL, 0);
if ( *v7 || v8 > 0xFF )
{
fprintf(stderr, "%ld is an invalid debug level.\n", v8);
return 1;
}
debug = v8;
}
else
{
++debug;
}
break;
case 'h':
return usage(*argv);
case 'C':
result = parse_config(optarg);
if ( result )
return result;
break;
}
}
event_base = event_base_new();
v9 = dispatch_config(event_base);
result = 1;
if ( !v9 )
{
signal(15, (__sighandler_t)onSignal);
signal(2, (__sighandler_t)onSignal);
while ( 1 )
event_base_dispatch(event_base);
}
return result;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // eax
int result; // eax
char *v5; // r13
int *v6; // rax
int *v7; // r12
unsigned __int64 v8; // rax
int v9; // er8
int longind[11]; // [rsp+Ch] [rbp-2Ch] BYREF

while ( 1 )
{
v3 = getopt_long(argc, (char *const *)argv, "hD::C:", &options, longind);
if ( v3 == -1 )
break;
switch ( v3 )
{
case 'D':
v5 = optarg;
if ( optarg )
{
v6 = _errno_location();
*v6 = 0;
v7 = v6;
v8 = strtol(v5, 0LL, 0);
if ( *v7 || v8 > 0xFF )
{
fprintf(stderr, "%ld is an invalid debug level.\n", v8);
return 1;
}
debug = v8;
}
else
{
++debug;
}
break;
case 'h':
return func1(*argv);
case 'C':
result = parse_config(optarg);
if ( result )
return result;
break;
}
}
event_base = event_base_new();
v9 = dispatch_config(event_base);
result = 1;
if ( !v9 )
{
signal(15, (__sighandler_t)onSignal);
signal(2, (__sighandler_t)onSignal);
while ( 1 )
event_base_dispatch(event_base);
}
return result;
}

original_code:
int main(int argc, char** argv) {
  int arg, optindex;
  while ((arg = getopt_long(argc, argv, "hD::C:", options, &optindex)) != -1) {
    switch (arg) {
    case 'h':
      return usage(argv[0]);
    case 'D':
      if (optarg) {
        (*__errno_location ()) = 0;
        long tmp = strtol(optarg, ((void *)0), 0);
        if ((*__errno_location ()) == 0 && tmp < 256 && tmp >= 0)
          debug = (unsigned char) tmp;
        else {
          fprintf(stderr, "%ld is an invalid debug level.\n", tmp);
          return 1;
        }
      } else
        debug++;
      break;
    case 'C': {
      int result = parse_config(optarg);
      if (result)
        return result;
      break;
    }
    }
  }
  event_base = event_base_new();
  if (dispatch_config(event_base))
    return 1;
  signal(15, onSignal);
  signal(2, onSignal);
  for (;;)
    event_base_dispatch(event_base);
  return 0;
}

canonical_original_code:
int main(int argc, char **argv) {
  int arg; int optindex;
  while ((arg = getopt_long(argc, argv, "hD::C:", options, &optindex)) != -1) {
    switch (arg) {
    case 'h':
      return usage(argv[0]);
    case 'D':
      if (optarg) {
        (*__errno_location ()) = 0;
        long tmp = strtol(optarg, ((void *)0), 0);
        if ((*__errno_location ()) == 0 && tmp < 256 && tmp >= 0)
          debug = (unsigned char) tmp;
        else {
          fprintf(stderr, "%ld is an invalid debug level.\n", tmp);
          return 1;
        }
      } else
        debug++;
      break;
    case 'C': {
      int result = parse_config(optarg);
      if (result)
        return result;
      break;
    }
    }
  }
  event_base = event_base_new();
  if (dispatch_config(event_base))
    return 1;
  signal(15, onSignal);
  signal(2, onSignal);
  for (;;)
    event_base_dispatch(event_base);
  return 0;
}

variable_types: argc int

variable_types:
argv
char **

variable_types: arg int

variable_types: optindex int

variable_types: tmp long

variable_types: result int


listAliases

decompiled_code:
_QWORD *listAliases()
{
_QWORD *v0; // r13
int v1; // eax
__int64 v2; // r12
__int64 i; // rbx
char v5[8232]; // [rsp+0h] [rbp-2028h] BYREF

v0 = 0LL;
v1 = count_cpus();
v2 = v1;
if ( v1 >= 0 )
{
v0 = calloc(8LL * (v1 + 1), 1uLL);
if ( (_DWORD)v2 )
{
for ( i = 0LL; i != v2; ++i )
{
snprintf(v5, 0x2000uLL, "cpu%d", (unsigned int)i);
v0[i] = strdup(v5);
}
}
}
return v0;
}

canonical_decompiled_code:
_QWORD *func9()
{
_QWORD *v0; // r13
int v1; // eax
__int64 v2; // r12
__int64 i; // rbx
char v5[8232]; // [rsp+0h] [rbp-2028h] BYREF

v0 = 0LL;
v1 = func8();
v2 = v1;
if ( v1 >= 0 )
{
v0 = calloc(8LL * (v1 + 1), 1uLL);
if ( (_DWORD)v2 )
{
for ( i = 0LL; i != v2; ++i )
{
snprintf(v5, 0x2000uLL, "cpu%d", (unsigned int)i);
v0[i] = strdup(v5);
}
}
}
return v0;
}

original_code:
char** listAliases() {
  int cpu_count = count_cpus();
  if (cpu_count < 0)
    return ((void *)0);
  char** output = malloc(sizeof(char*) * (cpu_count + 1));
  memset(output, 0, sizeof(char*) * (cpu_count + 1));
  int i;
  char buf[8192];
  for (i = 0; i < cpu_count; i++) {
    if (snprintf(buf, sizeof(buf), "cpu%d", i))
      output[i] = strdup(buf);
  };
  return output;
}

canonical_original_code:
char **listAliases() {
  int cpu_count = count_cpus();
  if (cpu_count < 0)
    return ((void *)0);
  char **output = malloc(sizeof(char*) * (cpu_count + 1));
  memset(output, 0, sizeof(char *) * (cpu_count + 1));
  int i;
  char buf[8192];
  for (i = 0; i < cpu_count; i++) {
    if (snprintf(buf, sizeof(buf), "cpu%d", i))
      output[i] = strdup(buf);
  };
  return output;
}

variable_types:
output
char **

variable_types: i int

variable_types:
buf
char [8192]

return_type: char **


freeContext

decompiled_code:
// attributes: thunk
void freeContext(void *ptr)
{
free(ptr);
}

canonical_decompiled_code:
void func11(void *ptr)
{
free(ptr);
}

original_code:
void freeContext(void* context) {
  free(context);
}

canonical_original_code:
void freeContext(void *context) {
  free(context);
}

variable_types:
context
void *


getMaxFloat

decompiled_code:
float getMaxFloat()
{
return 100.0;
}

canonical_decompiled_code:
float func13()
{
return 100.0;
}

original_code:
float getMaxFloat(void* context, size_t i) {
  return 100.0f;
}

canonical_original_code:
float getMaxFloat(void *context, unsigned long i) {
  return 100.0f;
}

variable_types:
i
unsigned long

return_type: float


getMinFloat

decompiled_code:
double getMinFloat()
{
return 0.0;
}

canonical_decompiled_code:
double func14()
{
return 0.0;
}

original_code:
float getMinFloat(void* context, size_t i) {
  return 0.0f;
}

canonical_original_code:
float getMinFloat(void *context, unsigned long i) {
  return 0.0f;
}


getFloat

decompiled_code:
__int64 __fastcall getFloat(__int64 a1, unsigned __int64 a2)
{
FILE *v2; // rbx
__int64 result; // rax
int v4; // [rsp+Ch] [rbp-7Ch]
int v5; // [rsp+2Ch] [rbp-5Ch]
__int64 v6; // [rsp+30h] [rbp-58h]
__int64 v7; // [rsp+38h] [rbp-50h]
__int64 v8; // [rsp+40h] [rbp-48h]
__int64 v9; // [rsp+48h] [rbp-40h]

v2 = fopen("/proc/stat", "r");
v4 = *(_DWORD *)a1;
if ( *(_DWORD *)a1 == -1 )
{
result = __isoc99_fscanf();
if ( (_DWORD)result != 4 )
return result;
}
else
{
while ( fgetc(v2) != 10 )
;
while ( (unsigned int)__isoc99_fscanf() == 5 && v4 != v5 )
{
while ( fgetc(v2) != 10 )
;
}
}
fclose(v2);
result = v9 + v8 + v6 + v7;
if ( a2 == 2 )
{
result = a1;
*(_QWORD *)(a1 + 24) = v8;
}
else if ( a2 > 2 )
{
if ( a2 == 3 )
{
*(_QWORD *)(a1 + 32) = v9;
*(_QWORD *)(a1 + 40) = result;
}
}
else if ( a2 )
{
result = a1;
*(_QWORD *)(a1 + 16) = v7;
}
else
{
result = a1;
*(_QWORD *)(a1 + 8) = v6;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func15(__int64 a1, unsigned __int64 a2)
{
FILE *v2; // rbx
__int64 result; // rax
int v4; // [rsp+Ch] [rbp-7Ch]
int v5; // [rsp+2Ch] [rbp-5Ch]
__int64 v6; // [rsp+30h] [rbp-58h]
__int64 v7; // [rsp+38h] [rbp-50h]
__int64 v8; // [rsp+40h] [rbp-48h]
__int64 v9; // [rsp+48h] [rbp-40h]

v2 = fopen("/proc/stat", "r");
v4 = *(_DWORD *)a1;
if ( *(_DWORD *)a1 == -1 )
{
result = __isoc99_fscanf();
if ( (_DWORD)result != 4 )
return result;
}
else
{
while ( fgetc(v2) != 10 )
;
while ( (unsigned int)__isoc99_fscanf() == 5 && v4 != v5 )
{
while ( fgetc(v2) != 10 )
;
}
}
fclose(v2);
result = v9 + v8 + v6 + v7;
if ( a2 == 2 )
{
result = a1;
*(_QWORD *)(a1 + 24) = v8;
}
else if ( a2 > 2 )
{
if ( a2 == 3 )
{
*(_QWORD *)(a1 + 32) = v9;
*(_QWORD *)(a1 + 40) = result;
}
}
else if ( a2 )
{
result = a1;
*(_QWORD *)(a1 + 16) = v7;
}
else
{
result = a1;
*(_QWORD *)(a1 + 8) = v6;
}
return result;
}

original_code:
float getFloat(void* context, size_t i) {
  return 0.0;
}

canonical_original_code:
float getFloat(void *context, unsigned long i) {
  return 0.0;
}


createContext

decompiled_code:
_DWORD *createContext()
{
_DWORD *v0; // r12

v0 = calloc(0x30uLL, 1uLL);
if ( (unsigned int)__isoc99_sscanf() != 1 )
*v0 = -1;
getFloat(v0, 0LL);
getFloat(v0, 1LL);
getFloat(v0, 2LL);
getFloat(v0, 3LL);
return v0;
}

canonical_decompiled_code:
_DWORD *func16()
{
_DWORD *v0; // r12

v0 = calloc(0x30uLL, 1uLL);
if ( (unsigned int)__isoc99_sscanf() != 1 )
*v0 = -1;
func15(v0, 0LL);
func15(v0, 1LL);
func15(v0, 2LL);
func15(v0, 3LL);
return v0;
}

original_code:
void* createContext(char* name) {
  struct CPUData* output = malloc(sizeof(struct CPUData));
  memset(output, 0, sizeof(struct CPUData));
  if (sscanf(name, "cpu%d", &output->cpu) != 1)
    output->cpu = -1;
  getFloat((void*) output, 0);
  getFloat((void*) output, 1);
  getFloat((void*) output, 2);
  getFloat((void*) output, 3);
  return output;
}

canonical_original_code:
void *createContext(char *name) {
  struct CPUData *output = malloc(sizeof(struct CPUData));
  memset(output, 0, sizeof(struct CPUData));
  if (sscanf(name, "cpu%d", &output->cpu) != 1)
    output->cpu = -1;
  getFloat((void *) output, 0);
  getFloat((void *) output, 1);
  getFloat((void *) output, 2);
  getFloat((void *) output, 3);
  return output;
}

variable_types:
name
char *

variable_types: struct CPUData { int cpu; unsigned long long userTime; unsigned long long niceTime; unsigned long long systemTime; unsigned long long idleTime; unsigned long long totalTime; } *

return_type: void *


maxInterval

decompiled_code:
__int64 maxInterval()
{
return 1LL;
}

canonical_decompiled_code:
__int64 func17()
{
return 1LL;
}

original_code:
unsigned char maxInterval(void* context) {
  return 1;
}

canonical_original_code:
unsigned char maxInterval(void *context) {
  return 1;
}

return_type: unsigned char


getItemName

decompiled_code:
const char *__fastcall getItemName(__int64 a1, unsigned __int64 a2)
{
const char *result; // rax

result = "system";
if ( a2 != 2 )
{
if ( a2 > 2 )
{
result = "idle";
if ( a2 != 3 )
result = 0LL;
}
else
{
result = "nice";
if ( !a2 )
result = "user";
}
}
return result;
}

canonical_decompiled_code:
const char *__fastcall func7(__int64 a1, unsigned __int64 a2)
{
const char *result; // rax

result = "system";
if ( a2 != 2 )
{
if ( a2 > 2 )
{
result = "idle";
if ( a2 != 3 )
result = 0LL;
}
else
{
result = "nice";
if ( !a2 )
result = "user";
}
}
return result;
}

original_code:
char* getItemName(void* context, size_t item) {
  switch (item) {
  case 0:
    return "user";
  case 1:
    return "nice";
  case 2:
    return "system";
  case 3:
    return "idle";
  };
  return ((void *)0);
}

canonical_original_code:
char *getItemName(void *context, unsigned long item) {
  switch (item) {
  case 0:
    return "user";
  case 1:
    return "nice";
  case 2:
    return "system";
  case 3:
    return "idle";
  };
  return ((void *)0);
}

variable_types:
item
unsigned long

return_type: char *


getArrayLength

decompiled_code:
__int64 getArrayLength()
{
return 4LL;
}

canonical_decompiled_code:
__int64 func10()
{
return 4LL;
}

original_code:
size_t getArrayLength(void* context) {
  return 4;
}

canonical_original_code:
unsigned long getArrayLength(void *context) {
  return 4;
}

return_type: unsigned long


decompiled_code:
__int64 __fastcall get_module(char *s1)
{
__int64 i; // r12

for ( i = *(_QWORD *)(config + 8); i; i = *(_QWORD *)(i + 72) )
{
if ( !strcmp(s1, *(const char **)(i + 16)) )
break;
}
return i;
}

canonical_decompiled_code:
__int64 __fastcall func3(char *s1)
{
__int64 i; // r12

for ( i = *(_QWORD *)(config + 8); i; i = *(_QWORD *)(i + 72) )
{
if ( !strcmp(s1, *(const char **)(i + 16)) )
break;
}
return i;
}

original_code:
struct module* get_module(char* name) {
  struct module* m = config->modules;
  while (m) {
    if (strcmp(name, m->name) == 0)
      return m;
    m = m->next;
  };
  return ((void *)0);
}

canonical_original_code:
struct module *get_module(char *name) {
  struct module *m = config->modules;
  while (m) {
    if (strcmp(name, m->name) == 0)
      return m;
    m = m->next;
  };
  return ((void *)0);
}

variable_types: struct module { void *handle; void *context; char *name; enum module_type { FLOAT=0, FLOAT_RANGE=1 } type; void *module_data; unsigned long array_length; void *update_function; unsigned char max_interval; long last_update; struct module *next; } *

user_defined_types: struct module { void *handle; void *context; char *name; enum module_type type; void *module_data; unsigned long array_length; void *update_function; unsigned char max_interval; long last_update; struct module *next; }


decompiled_code:
const char *__fastcall module_type_to_string(int a1)
{
const char *result; // rax

result = "FLOAT";
if ( a1 )
{
result = (const char *)&unk_812;
if ( a1 == 1 )
result = "FLOAT_RANGE";
}
return result;
}

canonical_decompiled_code:
const char *__fastcall func0(int a1)
{
const char *result; // rax

result = "FLOAT";
if ( a1 )
{
result = (const char *)&unk_812;
if ( a1 == 1 )
result = "FLOAT_RANGE";
}
return result;
}

original_code:
char* module_type_to_string(module_type type) {
  switch (type) {
  case FLOAT:
    return "FLOAT";
  case FLOAT_RANGE:
    return "FLOAT_RANGE";
  }
  return "";
}

canonical_original_code:
char *module_type_to_string(enum module_type type) {
  switch (type) {
  case FLOAT:
    return "FLOAT";
  case FLOAT_RANGE:
    return "FLOAT_RANGE";
  }
  return "";
}

variable_types: enum module_type { FLOAT=0, FLOAT_RANGE=1 }


decompiled_code:
void __fastcall free_module(void *ptr)
{
void (__fastcall *v2)(_QWORD); // rax
int v3; // eax
unsigned __int64 i; // rbx
void *v5; // rdi

if ( ptr )
{
if ( *((_QWORD *)ptr + 1) )
{
v2 = (void (__fastcall *)(_QWORD))dlsym(*(void **)ptr, "freeContext");
if ( v2 )
v2(*((_QWORD *)ptr + 1));
}
dlclose(*(void **)ptr);
free(*((void **)ptr + 2));
v3 = *((_DWORD *)ptr + 6);
if ( v3 )
{
if ( v3 != 1 )
{
LABEL_10:
free(ptr);
return;
}
for ( i = 0LL; *((_QWORD *)ptr + 5) > i; ++i )
{
v5 = *(void **)(*((_QWORD *)ptr + 4) + 8 * i);
free(v5);
}
}
free(*((void **)ptr + 4));
goto LABEL_10;
}
}

canonical_decompiled_code:
void __fastcall func1(void *ptr)
{
void (__fastcall *v2)(_QWORD); // rax
int v3; // eax
unsigned __int64 i; // rbx
void *v5; // rdi

if ( ptr )
{
if ( *((_QWORD *)ptr + 1) )
{
v2 = (void (__fastcall *)(_QWORD))dlsym(*(void **)ptr, "freeContext");
if ( v2 )
v2(*((_QWORD *)ptr + 1));
}
dlclose(*(void **)ptr);
free(*((void **)ptr + 2));
v3 = *((_DWORD *)ptr + 6);
if ( v3 )
{
if ( v3 != 1 )
{
LABEL_10:
free(ptr);
return;
}
for ( i = 0LL; *((_QWORD *)ptr + 5) > i; ++i )
{
v5 = *(void **)(*((_QWORD *)ptr + 4) + 8 * i);
free(v5);
}
}
free(*((void **)ptr + 4));
goto LABEL_10;
}
}

original_code:
void free_module(struct module* module) {
  if (module) {
    if (module->context) {
      mod_free_context* free_context = dlsym(module->handle, "freeContext");
      if (free_context)
        free_context(module->context);
    }
    dlclose(module->handle);
    free(module->name);
    switch (module->type) {
    case FLOAT_RANGE: {
      size_t i;
      for (i = 0; i < module->array_length; i++)
        free(((struct float_range_data**) module->module_data)[i]);
    }
    case FLOAT:
      free(module->module_data);
      break;
    };
    free(module);
  }
}

canonical_original_code:
void free_module(struct module *module) {
  if (module) {
    if (module->context) {
      void (*free_context)(void *context) = dlsym(module->handle, "freeContext");
      if (free_context)
        free_context(module->context);
    }
    dlclose(module->handle);
    free(module->name);
    switch (module->type) {
    case FLOAT_RANGE: {
      unsigned long i;
      for (i = 0; i < module->array_length; i++)
        free(((struct float_range_data **) module->module_data)[i]);
    }
    case FLOAT:
      free(module->module_data);
      break;
    };
    free(module);
  }
}

user_defined_types: enum module_type { FLOAT=0, FLOAT_RANGE=1 }

user_defined_types: struct float_range_data { float current_float; float max_value; float min_value; float (*mod_min_func)(void *context, unsigned long item); float (*mod_max_func)(void *context, unsigned long item); }


decompiled_code:
char *__fastcall get_module_item_names(__int64 a1, char *a2, __int64 a3)
{
__int64 (__fastcall *v4)(_QWORD, unsigned __int64); // r12
char *result; // rax
char *v6; // r14
char *v7; // rbx
unsigned __int64 i; // rbp
const char *v9; // rax
unsigned __int64 v10; // rax

v4 = (__int64 (__fastcall *)(_QWORD, unsigned __int64))dlsym(*(void **)a1, "getItemName");
result = 0LL;
if ( v4 )
{
result = *(char **)(a1 + 40);
if ( result )
{
v6 = &a2[a3];
v7 = a2;
for ( i = 0LL; i < v10; ++i )
{
v9 = (const char *)v4(*(_QWORD *)(a1 + 8), i);
v7 += snprintf(v7, v6 - v7, "%s", v9);
v10 = *(_QWORD *)(a1 + 40);
if ( v10 - 1 != i )
{
v7 += snprintf(v7, v6 - v7, ", ");
v10 = *(_QWORD *)(a1 + 40);
}
}
result = (char *)(v7 - a2);
}
}
return result;
}

canonical_decompiled_code:
char *__fastcall func4(__int64 a1, char *a2, __int64 a3)
{
__int64 (__fastcall *v4)(_QWORD, unsigned __int64); // r12
char *result; // rax
char *v6; // r14
char *v7; // rbx
unsigned __int64 i; // rbp
const char *v9; // rax
unsigned __int64 v10; // rax

v4 = (__int64 (__fastcall *)(_QWORD, unsigned __int64))dlsym(*(void **)a1, "getItemName");
result = 0LL;
if ( v4 )
{
result = *(char **)(a1 + 40);
if ( result )
{
v6 = &a2[a3];
v7 = a2;
for ( i = 0LL; i < v10; ++i )
{
v9 = (const char *)v4(*(_QWORD *)(a1 + 8), i);
v7 += snprintf(v7, v6 - v7, "%s", v9);
v10 = *(_QWORD *)(a1 + 40);
if ( v10 - 1 != i )
{
v7 += snprintf(v7, v6 - v7, ", ");
v10 = *(_QWORD *)(a1 + 40);
}
}
result = (char *)(v7 - a2);
}
}
return result;
}

original_code:
size_t get_module_item_names(struct module* module, char* buf, size_t buf_size) {
  char *s = buf;
  char *e = buf + buf_size;
  mod_item_name* item_name_func = dlsym(module->handle, "getItemName");
  if (item_name_func) {
    size_t i;
    for (i = 0; i < module->array_length; i++) {
      s += snprintf(s, e - s, "%s", item_name_func(module->context, i));
      if (i != (module->array_length - 1))
        s += snprintf(s, e - s, ", ");
    }
  }
  return s - buf;
}

canonical_original_code:
unsigned long get_module_item_names(struct module *module, char *buf, unsigned long buf_size) {
  char *s = buf;
  char *e = buf + buf_size;
  char *(*item_name_func)(void *context, unsigned long item) = dlsym(module->handle, "getItemName");
  if (item_name_func) {
    unsigned long i;
    for (i = 0; i < module->array_length; i++) {
      s += snprintf(s, e - s, "%s", item_name_func(module->context, i));
      if (i != (module->array_length - 1))
        s += snprintf(s, e - s, ", ");
    }
  }
  return s - buf;
}

variable_types:
buf
char *

variable_types:
s
char *

variable_types:
e
char *

variable_types: char *(*)(void *context, unsigned long item)


decompiled_code:
void *new_websocket()
{
return calloc(0x18uLL, 1uLL);
}

canonical_decompiled_code:
void *func0()
{
return calloc(0x18uLL, 1uLL);
}

original_code:
struct websocket* new_websocket() {
  struct websocket* output = malloc(sizeof(struct websocket));
  memset(output, 0, sizeof(struct websocket));
  return output;
}

canonical_original_code:
struct websocket *new_websocket() {
  struct websocket *output = malloc(sizeof(struct websocket));
  memset(output, 0, sizeof(struct websocket));
  return output;
}

variable_types: struct websocket { char *key; unsigned char is_get; unsigned char is_http_1_1; unsigned char has_upgrade; unsigned char connection_is_upgrade; unsigned char correct_version; unsigned char connected; unsigned char length_code; char mask[4]; unsigned char has_mask; unsigned long length; } *


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

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

original_code:
void free_websocket(struct websocket* websocket) {
  if (websocket) {
    free(websocket->key);
    free(websocket);
  };
}

canonical_original_code:
void free_websocket(struct websocket *websocket) {
  if (websocket) {
    free(websocket->key);
    free(websocket);
  };
}

user_defined_types: struct websocket { char *key; unsigned char is_get; unsigned char is_http_1_1; unsigned char has_upgrade; unsigned char connection_is_upgrade; unsigned char correct_version; unsigned char connected; unsigned char length_code; char mask[4]; unsigned char has_mask; unsigned long length; }


repo: schoentoon/smnl

original_code:
uint32_t eth_parse(struct pcap_pkthdr *header, uint8_t *packet,
                   eth_info * eth) {
    uint32_t pos = 0;
    if (header->len < 14) {
        fprintf(stderr, "Truncated Packet(eth)\n");
        return 0;
    }
    while (pos < 6) {
        eth->dstmac[pos] = packet[pos];
        eth->srcmac[pos] = packet[pos+6];
        pos++;
    }
    pos = pos + 6;
    if (packet[pos] == 0x81 && packet[pos+1] == 0) pos = pos + 4;
    eth->ethtype = (packet[pos] << 8) + packet[pos+1];
    pos = pos + 2;

    return pos;
}

canonical_original_code:
unsigned int eth_parse(struct pcap_pkthdr *header, unsigned char *packet, struct eth_info *eth) {
    unsigned int pos = 0;
    if (header->len < 14) {
        fprintf(stderr, "Truncated Packet(eth)\n");
        return 0;
    }
    while (pos < 6) {
        eth->dstmac[pos] = packet[pos];
        eth->srcmac[pos] = packet[pos+6];
        pos++;
    }
    pos = pos + 6;
    if (packet[pos] == 0x81 && packet[pos+1] == 0) pos = pos + 4;
    eth->ethtype = (packet[pos] << 8) + packet[pos+1];
    pos = pos + 2;

    return pos;
}

variable_types: struct pcap_pkthdr { struct timeval { long tv_sec; long tv_usec; } ts; unsigned int caplen; unsigned int len; } *

variable_types:
packet
unsigned char *

variable_types: struct eth_info { unsigned char dstmac[6]; unsigned char srcmac[6]; unsigned short ethtype; } *

variable_types:
pos
unsigned int

return_type: unsigned int

user_defined_types: struct pcap_pkthdr { struct timeval ts; unsigned int caplen; unsigned int len; }


decompiled_code:
__int64 __fastcall mpls_parse(unsigned int a1, __int64 a2, __int64 a3, __int64 a4)
{
unsigned int v4; // eax
__int64 result; // rax
char v6; // al

do
{
v4 = a1;
a1 += 4;
if ( *(_DWORD *)(a2 + 20) < a1 )
{
fwrite("Truncated Packet(mpls)\n", 1uLL, 0x17uLL, stderr);
return 0LL;
}
}
while ( (*(_BYTE *)(a3 + v4 + 2) & 1) == 0 );
v6 = *(_BYTE *)(a3 + a1) >> 4;
if ( v6 == 4 )
{
result = a1;
*(_WORD *)(a4 + 12) = 2048;
}
else if ( v6 == 6 )
{
result = a1;
*(_WORD *)(a4 + 12) = -31011;
}
else
{
*(_WORD *)(a4 + 12) = 0;
result = a1;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(unsigned int a1, __int64 a2, __int64 a3, __int64 a4)
{
unsigned int v4; // eax
__int64 result; // rax
char v6; // al

do
{
v4 = a1;
a1 += 4;
if ( *(_DWORD *)(a2 + 20) < a1 )
{
fwrite("Truncated Packet(mpls)\n", 1uLL, 0x17uLL, stderr);
return 0LL;
}
}
while ( (*(_BYTE *)(a3 + v4 + 2) & 1) == 0 );
v6 = *(_BYTE *)(a3 + a1) >> 4;
if ( v6 == 4 )
{
result = a1;
*(_WORD *)(a4 + 12) = 2048;
}
else if ( v6 == 6 )
{
result = a1;
*(_WORD *)(a4 + 12) = -31011;
}
else
{
*(_WORD *)(a4 + 12) = 0;
result = a1;
}
return result;
}

original_code:
uint32_t mpls_parse(uint32_t pos, struct pcap_pkthdr *header,
                    uint8_t *packet, eth_info * eth) {
    uint8_t bos;
    do {

        if (header->len < (pos + 4)) {
            fprintf(stderr, "Truncated Packet(mpls)\n");
            return 0;
        }
        bos = packet[pos + 2] & 0x01;
        pos += 4;

    } while (bos == 0);
    if (header->len < pos) {
        fprintf(stderr, "Truncated Packet(post mpls)\n");
        return 0;
    }
    uint8_t ip_ver = packet[pos] >> 4;
    switch (ip_ver) {
        case 0x04:
            eth->ethtype = 0x0800; break;
        case 0x06:
            eth->ethtype = 0x86DD; break;
        default:
            eth->ethtype = 0;
    }
    return pos;
}

canonical_original_code:
unsigned int mpls_parse(unsigned int pos, struct pcap_pkthdr *header, unsigned char *packet, struct eth_info *eth) {
    unsigned char bos;
    do {

        if (header->len < (pos + 4)) {
            fprintf(stderr, "Truncated Packet(mpls)\n");
            return 0;
        }
        bos = packet[pos + 2] & 0x01;
        pos += 4;

    } while (bos == 0);
    if (header->len < pos) {
        fprintf(stderr, "Truncated Packet(post mpls)\n");
        return 0;
    }
    unsigned char ip_ver = packet[pos] >> 4;
    switch (ip_ver) {
        case 0x04:
            eth->ethtype = 0x0800; break;
        case 0x06:
            eth->ethtype = 0x86DD; break;
        default:
            eth->ethtype = 0;
    }
    return pos;
}

variable_types:
bos
unsigned char

user_defined_types: struct eth_info { unsigned char dstmac[6]; unsigned char srcmac[6]; unsigned short ethtype; }

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


original_code:
ip_fragment * ip_frag_add(ip_fragment * this, config * conf) {
    ip_fragment ** curr = &(conf->ip_fragment_head);
    ip_fragment ** found = ((void *)0);

    while (*curr != ((void *)0)) {
        if ((*curr)->id == this->id &&
            (((*curr)->src.vers == this->src.vers) && ((*curr)->src.vers == 0x04 ? (*curr)->src.addr.v4.s_addr == this->src.addr.v4.s_addr : (((*curr)->src.addr.v6.__in6_u.__u6_addr32[0] == this->src.addr.v6.__in6_u.__u6_addr32[0]) && ((*curr)->src.addr.v6.__in6_u.__u6_addr32[1] == this->src.addr.v6.__in6_u.__u6_addr32[1]) && ((*curr)->src.addr.v6.__in6_u.__u6_addr32[2] == this->src.addr.v6.__in6_u.__u6_addr32[2]) && ((*curr)->src.addr.v6.__in6_u.__u6_addr32[3] == this->src.addr.v6.__in6_u.__u6_addr32[3])) )) &&
            (((*curr)->dst.vers == this->dst.vers) && ((*curr)->dst.vers == 0x04 ? (*curr)->dst.addr.v4.s_addr == this->dst.addr.v4.s_addr : (((*curr)->dst.addr.v6.__in6_u.__u6_addr32[0] == this->dst.addr.v6.__in6_u.__u6_addr32[0]) && ((*curr)->dst.addr.v6.__in6_u.__u6_addr32[1] == this->dst.addr.v6.__in6_u.__u6_addr32[1]) && ((*curr)->dst.addr.v6.__in6_u.__u6_addr32[2] == this->dst.addr.v6.__in6_u.__u6_addr32[2]) && ((*curr)->dst.addr.v6.__in6_u.__u6_addr32[3] == this->dst.addr.v6.__in6_u.__u6_addr32[3])) ))) {
            found = curr;

            break;
        }
        curr = &(*curr)->next;
    }
    if (found == ((void *)0)) {

        this->next = conf->ip_fragment_head;
        conf->ip_fragment_head = this;
        return ((void *)0);
    }
    while (*found != ((void *)0)) {

        if ((*found)->start >= this->end) {

            this->child = *found;
            this->next = (*found)->next;
            *found = this;
            break;
        } else if ((*found)->child == ((void *)0) &&
                    (*found)->end <= this->start) {

            (*found)->child = this;
            break;
        }

        found = &((*found)->child);
    }

    if (*found == ((void *)0)) {

        free(this);
        return ((void *)0);
    }
    found = curr;
    while ((*found != ((void *)0)) && (*found)->child != ((void *)0)) {
        ip_fragment * child = (*found)->child;
        if ((*found)->end == child->start) {

            uint32_t child_len = child->end - child->start;
            uint32_t fnd_len = (*found)->end - (*found)->start;
            uint8_t * buff = malloc(sizeof(uint8_t) * (fnd_len + child_len));
            memcpy(buff, (*found)->data, fnd_len);
            memcpy(buff + fnd_len, child->data, child_len);
            (*found)->end = (*found)->end + child_len;
            (*found)->islast = child->islast;
            (*found)->child = child->child;
            free((*found)->data);
            free(child->data);
            free(child);
            (*found)->data = buff;
        } else {
            found = &(*found)->child;
        }
    }

    if ((*curr)->islast != 0) {
        ip_fragment * ret = *curr;
        *curr = (*curr)->next;

        return ret;
    }
    return ((void *)0);
}

canonical_original_code:
struct ip_fragment *ip_frag_add(struct ip_fragment *this, struct config *conf) {
    struct ip_fragment **curr = &(conf->ip_fragment_head);
    struct ip_fragment **found = ((void *)0);

    while (*curr != ((void *)0)) {
        if ((*curr)->id == this->id &&
            (((*curr)->src.vers == this->src.vers) && ((*curr)->src.vers == 0x04 ? (*curr)->src.addr.v4.s_addr == this->src.addr.v4.s_addr : (((*curr)->src.addr.v6.__in6_u.__u6_addr32[0] == this->src.addr.v6.__in6_u.__u6_addr32[0]) && ((*curr)->src.addr.v6.__in6_u.__u6_addr32[1] == this->src.addr.v6.__in6_u.__u6_addr32[1]) && ((*curr)->src.addr.v6.__in6_u.__u6_addr32[2] == this->src.addr.v6.__in6_u.__u6_addr32[2]) && ((*curr)->src.addr.v6.__in6_u.__u6_addr32[3] == this->src.addr.v6.__in6_u.__u6_addr32[3])) )) &&
            (((*curr)->dst.vers == this->dst.vers) && ((*curr)->dst.vers == 0x04 ? (*curr)->dst.addr.v4.s_addr == this->dst.addr.v4.s_addr : (((*curr)->dst.addr.v6.__in6_u.__u6_addr32[0] == this->dst.addr.v6.__in6_u.__u6_addr32[0]) && ((*curr)->dst.addr.v6.__in6_u.__u6_addr32[1] == this->dst.addr.v6.__in6_u.__u6_addr32[1]) && ((*curr)->dst.addr.v6.__in6_u.__u6_addr32[2] == this->dst.addr.v6.__in6_u.__u6_addr32[2]) && ((*curr)->dst.addr.v6.__in6_u.__u6_addr32[3] == this->dst.addr.v6.__in6_u.__u6_addr32[3])) ))) {
            found = curr;

            break;
        }
        curr = &(*curr)->next;
    }
    if (found == ((void *)0)) {

        this->next = conf->ip_fragment_head;
        conf->ip_fragment_head = this;
        return ((void *)0);
    }
    while (*found != ((void *)0)) {

        if ((*found)->start >= this->end) {

            this->child = *found;
            this->next = (*found)->next;
            *found = this;
            break;
        } else if ((*found)->child == ((void *)0) &&
                    (*found)->end <= this->start) {

            (*found)->child = this;
            break;
        }

        found = &((*found)->child);
    }

    if (*found == ((void *)0)) {

        free(this);
        return ((void *)0);
    }
    found = curr;
    while ((*found != ((void *)0)) && (*found)->child != ((void *)0)) {
        struct ip_fragment *child = (*found)->child;
        if ((*found)->end == child->start) {

            unsigned int child_len = child->end - child->start;
            unsigned int fnd_len = (*found)->end - (*found)->start;
            unsigned char *buff = malloc(sizeof(uint8_t) * (fnd_len + child_len));
            memcpy(buff, (*found)->data, fnd_len);
            memcpy(buff + fnd_len, child->data, child_len);
            (*found)->end = (*found)->end + child_len;
            (*found)->islast = child->islast;
            (*found)->child = child->child;
            free((*found)->data);
            free(child->data);
            free(child);
            (*found)->data = buff;
        } else {
            found = &(*found)->child;
        }
    }

    if ((*curr)->islast != 0) {
        struct ip_fragment *ret = *curr;
        *curr = (*curr)->next;

        return ret;
    }
    return ((void *)0);
}

variable_types:
this
struct ip_fragment *

variable_types: struct config { unsigned short EXCLUDED[100]; unsigned short EXCLUDES; char SEP; char *RECORD_SEP; int AD_ENABLED; int NS_ENABLED; int COUNTS; int PRETTY_DATE; int PRINT_RR_NAME; int MISSING_TYPE_WARNINGS; char *TCP_STATE_PATH; unsigned int DEDUPS; struct tcp_info { struct timeval { long tv_sec; long tv_usec; } ts; struct ip_addr src; struct ip_addr dst; unsigned short srcport; unsigned short dstport; unsigned int sequence; unsigned int ack_num; unsigned int len; unsigned char syn; unsigned char ack; unsigned char fin; unsigned char rst; unsigned char *data; struct tcp_info *next_sess; struct tcp_info *next_pkt; struct tcp_info *prev_pkt; } *tcp_sessions_head; struct ip_fragment *ip_fragment_head; unsigned long long *dedup_hashes; unsigned int dedup_pos; } *

variable_types: struct ip_fragment { unsigned int id; struct ip_addr { unsigned char vers; union { struct in_addr { unsigned int s_addr; } v4; struct in6_addr { union { unsigned char __u6_addr8[16]; unsigned short __u6_addr16[8]; unsigned int __u6_addr32[4]; } __in6_u; } v6; } addr; } src; struct ip_addr dst; unsigned int start; unsigned int end; unsigned char *data; unsigned char islast; struct ip_fragment *next; struct ip_fragment *child; } **

variable_types:
buff
unsigned char *

user_defined_types: struct config { unsigned short EXCLUDED[100]; unsigned short EXCLUDES; char SEP; char *RECORD_SEP; int AD_ENABLED; int NS_ENABLED; int COUNTS; int PRETTY_DATE; int PRINT_RR_NAME; int MISSING_TYPE_WARNINGS; char *TCP_STATE_PATH; unsigned int DEDUPS; struct tcp_info *tcp_sessions_head; struct ip_fragment *ip_fragment_head; unsigned long long *dedup_hashes; unsigned int dedup_pos; }

user_defined_types: struct ip_fragment { unsigned int id; struct ip_addr src; struct ip_addr dst; unsigned int start; unsigned int end; unsigned char *data; unsigned char islast; struct ip_fragment *next; struct ip_fragment *child; }

user_defined_types: struct ip_addr { unsigned char vers; union { struct in_addr v4; struct in6_addr v6; } addr; }

user_defined_types: struct tcp_info { struct timeval ts; struct ip_addr src; struct ip_addr dst; unsigned short srcport; unsigned short dstport; unsigned int sequence; unsigned int ack_num; unsigned int len; unsigned char syn; unsigned char ack; unsigned char fin; unsigned char rst; unsigned char *data; struct tcp_info *next_sess; struct tcp_info *next_pkt; struct tcp_info *prev_pkt; }


original_code:
uint32_t ipv4_parse(uint32_t pos, struct pcap_pkthdr *header,
                    uint8_t ** p_packet, ip_info * ip, config * conf) {
    uint32_t h_len;
    ip_fragment * frag = ((void *)0);
    uint8_t frag_mf;
    uint16_t frag_offset;
    uint8_t * packet = *p_packet;
    if (header-> len - pos < 20) {
        fprintf(stderr, "Truncated Packet(ipv4)\n");
        p_packet = ((void *)0);
        return 0;
    }
    h_len = packet[pos] & 0x0f;
    ip->length = (packet[pos+2] << 8) + packet[pos+3] - h_len*4;
    ip->proto = packet[pos+9];
    ip->src.addr.v4.s_addr = *(in_addr_t *)(packet + pos + 12); ip->src.vers = 0x04;;
    ip->dst.addr.v4.s_addr = *(in_addr_t *)(packet + pos + 16); ip->dst.vers = 0x04;;
    frag_mf = (packet[pos+6] & 0x20) >> 5;
    frag_offset = ((packet[pos+6] & 0x1f) << 11) + (packet[pos+7] << 3);

    if (frag_mf == 1 || frag_offset != 0) {

        frag = malloc(sizeof(ip_fragment));
        frag->start = frag_offset;
        frag->islast = !frag_mf;
        frag->id = *((uint16_t *)(packet + pos + 4));
        frag->src = ip->src;
        frag->dst = ip->dst;
        frag->end = frag->start + ip->length;
        frag->data = malloc(sizeof(uint8_t) * ip->length);
        frag->next = frag->child = ((void *)0);
        memcpy(frag->data, packet + pos + 4*h_len, ip->length);
        frag = ip_frag_add(frag, conf);
        if (frag != ((void *)0)) {
            header->len = ip->length = frag->end - frag->start;
            p_packet = &(frag->data);
            free(frag);
            return 0;
        }
        p_packet = ((void *)0);
        return 0;
    }
    return pos + 4*h_len;
}

canonical_original_code:
unsigned int ipv4_parse(unsigned int pos, struct pcap_pkthdr *header, unsigned char **p_packet, struct ip_info *ip, struct config *conf) {
    unsigned int h_len;
    struct ip_fragment *frag = ((void *)0);
    unsigned char frag_mf;
    unsigned short frag_offset;
    unsigned char *packet = *p_packet;
    if (header-> len - pos < 20) {
        fprintf(stderr, "Truncated Packet(ipv4)\n");
        p_packet = ((void *)0);
        return 0;
    }
    h_len = packet[pos] & 0x0f;
    ip->length = (packet[pos+2] << 8) + packet[pos+3] - h_len*4;
    ip->proto = packet[pos+9];
    ip->src.addr.v4.s_addr = *(unsigned int *)(packet + pos + 12); ip->src.vers = 0x04;;
    ip->dst.addr.v4.s_addr = *(unsigned int *)(packet + pos + 16); ip->dst.vers = 0x04;;
    frag_mf = (packet[pos+6] & 0x20) >> 5;
    frag_offset = ((packet[pos+6] & 0x1f) << 11) + (packet[pos+7] << 3);

    if (frag_mf == 1 || frag_offset != 0) {

        frag = malloc(sizeof(ip_fragment));
        frag->start = frag_offset;
        frag->islast = !frag_mf;
        frag->id = *((unsigned short *)(packet + pos + 4));
        frag->src = ip->src;
        frag->dst = ip->dst;
        frag->end = frag->start + ip->length;
        frag->data = malloc(sizeof(unsigned char) * ip->length);
        frag->next = frag->child = ((void *)0);
        memcpy(frag->data, packet + pos + 4*h_len, ip->length);
        frag = ip_frag_add(frag, conf);
        if (frag != ((void *)0)) {
            header->len = ip->length = frag->end - frag->start;
            p_packet = &(frag->data);
            free(frag);
            return 0;
        }
        p_packet = ((void *)0);
        return 0;
    }
    return pos + 4*h_len;
}

variable_types: struct ip_info { struct ip_addr { unsigned char vers; union { struct in_addr { unsigned int s_addr; } v4; struct in6_addr { union { unsigned char __u6_addr8[16]; unsigned short __u6_addr16[8]; unsigned int __u6_addr32[4]; } __in6_u; } v6; } addr; } src; struct ip_addr dst; unsigned int length; unsigned char proto; } *

variable_types: struct config { unsigned short EXCLUDED[100]; unsigned short EXCLUDES; char SEP; char *RECORD_SEP; int AD_ENABLED; int NS_ENABLED; int COUNTS; int PRETTY_DATE; int PRINT_RR_NAME; int MISSING_TYPE_WARNINGS; char *TCP_STATE_PATH; unsigned int DEDUPS; struct tcp_info { struct timeval ts; struct ip_addr src; struct ip_addr dst; unsigned short srcport; unsigned short dstport; unsigned int sequence; unsigned int ack_num; unsigned int len; unsigned char syn; unsigned char ack; unsigned char fin; unsigned char rst; unsigned char *data; struct tcp_info *next_sess; struct tcp_info *next_pkt; struct tcp_info *prev_pkt; } *tcp_sessions_head; struct ip_fragment { unsigned int id; struct ip_addr src; struct ip_addr dst; unsigned int start; unsigned int end; unsigned char *data; unsigned char islast; struct ip_fragment *next; struct ip_fragment *child; } *ip_fragment_head; unsigned long long *dedup_hashes; unsigned int dedup_pos; } *

variable_types: struct ip_fragment { unsigned int id; struct ip_addr { unsigned char vers; union { struct in_addr { unsigned int s_addr; } v4; struct in6_addr { union { unsigned char __u6_addr8[16]; unsigned short __u6_addr16[8]; unsigned int __u6_addr32[4]; } __in6_u; } v6; } addr; } src; struct ip_addr dst; unsigned int start; unsigned int end; unsigned char *data; unsigned char islast; struct ip_fragment *next; struct ip_fragment *child; } *

user_defined_types: struct ip_info { struct ip_addr src; struct ip_addr dst; unsigned int length; unsigned char proto; }


decompiled_code:
__int64 __fastcall ipv6_parse(unsigned int a1, __int64 a2, __int64 *a3, __int64 a4, __int64 a5)
{
unsigned int v5; // er12
__int64 v6; // rbp
int v8; // eax
int v9; // er14
bool v10; // zf
int v11; // er14
__m128i v12; // xmm0
__m128i v13; // xmm1
int v15; // edx
_DWORD *v16; // r9
unsigned __int8 v17; // r13
unsigned int v18; // esi
int v19; // eax
size_t v21; // r14
int v22; // eax
__m128i v23; // xmm2
__m128i v24; // xmm3
int v25; // eax
int v26; // eax
void *v27; // rax
_DWORD *v28; // rax
unsigned int v29; // eax
int v30; // esi
_DWORD *v31; // rax
__int64 v32; // r10
_BYTE *v33; // rdi
_QWORD *ptra; // [rsp+8h] [rbp-50h]
void *ptr; // [rsp+8h] [rbp-50h]
__int64 v36; // [rsp+10h] [rbp-48h]
int v37; // [rsp+10h] [rbp-48h]
__int64 v38; // [rsp+18h] [rbp-40h]

v5 = a1 + 40;
if ( *(_DWORD *)(a2 + 20) >= a1 + 40 )
{
v6 = *a3;
v8 = *(unsigned __int8 *)(*a3 + a1 + 5);
v9 = *(unsigned __int8 *)(*a3 + a1 + 4) << 8;
v10 = v8 + v9 == 0;
v11 = v8 + v9;
*(_DWORD *)(a4 + 40) = v11;
v12 = _mm_loadu_si128((const __m128i *)(v6 + a1 + 8));
*(_BYTE *)a4 = 6;
*(__m128i *)(a4 + 4) = v12;
v13 = _mm_loadu_si128((const __m128i *)(v6 + a1 + 24));
*(_BYTE *)(a4 + 20) = 6;
*(__m128i *)(a4 + 24) = v13;
if ( v10 )
{
v5 = 0;
fwrite("Zero Length IP packet, possible Jumbo Payload.\n", 1uLL, 0x2FuLL, stderr);
return v5;
}
v15 = 0;
v16 = 0LL;
v17 = *(_BYTE *)(v6 + a1 + 6);
while ( 1 )
{
switch ( v17 )
{
case 0u:
case 0x2Bu:
case 0x3Cu:
if ( *(_DWORD *)(a2 + 20) < v5 + 16 )
goto LABEL_8;
v15 += 16;
v17 = *(_BYTE *)(v6 + v5);
v5 += *(unsigned __int8 *)(v6 + v5 + 1) + 1;
continue;
case 1u:
case 2u:
case 3u:
case 4u:
case 5u:
case 7u:
case 8u:
case 9u:
case 0xAu:
case 0xBu:
case 0xCu:
case 0xDu:
case 0xEu:
case 0xFu:
case 0x10u:
case 0x12u:
case 0x13u:
case 0x14u:
case 0x15u:
case 0x16u:
case 0x17u:
case 0x18u:
case 0x19u:
case 0x1Au:
case 0x1Bu:
case 0x1Cu:
case 0x1Du:
case 0x1Eu:
case 0x1Fu:
case 0x20u:
case 0x21u:
case 0x22u:
case 0x23u:
case 0x24u:
case 0x25u:
case 0x26u:
case 0x27u:
case 0x28u:
case 0x29u:
case 0x2Au:
case 0x2Du:
case 0x2Eu:
case 0x2Fu:
case 0x30u:
case 0x31u:
case 0x34u:
case 0x35u:
case 0x36u:
case 0x37u:
case 0x38u:
case 0x39u:
case 0x3Au:
case 0x3Bu:
goto LABEL_9;
case 6u:
case 0x11u:
v21 = (unsigned int)(v11 - v15);
*(_BYTE *)(a4 + 44) = v17;
*(_DWORD *)(a4 + 40) = v21;
if ( !v16 )
return v5;
v22 = *(_DWORD *)(a4 + 16);
v23 = _mm_loadu_si128((const __m128i *)a4);
v36 = a5;
v24 = _mm_loadu_si128((const __m128i *)(a4 + 20));
*((_QWORD *)v16 + 10) = 0LL;
v16[5] = v22;
v25 = *(_DWORD *)(a4 + 36);
*((_QWORD *)v16 + 9) = 0LL;
v16[10] = v25;
v26 = v16[11];
*(__m128i *)(v16 + 1) = v23;
*(__m128i *)(v16 + 6) = v24;
v16[12] = v21 + v26;
ptra = v16;
v27 = malloc(v21);
ptra[7] = v27;
memcpy(v27, (const void *)(v6 + v5), v21);
v28 = (_DWORD *)ip_frag_add(ptra, v36);
if ( v28 )
{
*(_DWORD *)(a4 + 40) = v28[12] - v28[11];
free(v28);
}
return 0;
case 0x2Cu:
v38 = a5;
v37 = v15;
v17 = *(_BYTE *)(v6 + v5);
v31 = malloc(0x58uLL);
v32 = v5;
v16 = v31;
v33 = (_BYTE *)(v6 + v5 + 3);
a5 = v38;
LODWORD(v31) = *(unsigned __int8 *)(v6 + v5 + 2);
v15 = v37 + 8;
v5 += 8;
v16[11] = ((_DWORD)v31 << 8) + (*v33 & 0xF4);
*((_BYTE *)v16 + 64) = *v33 & 1;
*v16 = *(_DWORD *)(v6 + v32 + 4);
continue;
case 0x32u:
ptr = v16;
fwrite("Unsupported protocol: IPv6 ESP.\n", 1uLL, 0x20uLL, stderr);
if ( !ptr )
return 0;
v5 = 0;
free(ptr);
return v5;
case 0x33u:
v29 = *(_DWORD *)(a2 + 20);
if ( v29 < v5 + 2 )
goto LABEL_8;
v17 = *(_BYTE *)(v6 + v5);
v30 = 4 * *(unsigned __int8 *)(v6 + v5 + 1) + 8;
v5 += v30;
v15 += v30;
if ( v29 < v5 )
goto LABEL_8;
continue;
default:
if ( v17 != 0x87 )
{
LABEL_9:
v5 = 0;
fprintf(stderr, "Unsupported IPv6 proto(%u).\n", v17);
return v5;
}
v18 = *(_DWORD *)(a2 + 20);
if ( v18 < v5 + 2 )
goto LABEL_8;
v17 = *(_BYTE *)(v6 + v5);
v19 = 8 * *(unsigned __int8 *)(v6 + v5 + 1);
v5 += v19;
v15 += v19;
if ( v18 < v5 )
goto LABEL_8;
break;
}
}
}
LABEL_8:
v5 = 0;
fwrite("Truncated Packet(ipv6)\n", 1uLL, 0x17uLL, stderr);
return v5;
}

canonical_decompiled_code:
__int64 __fastcall func4(unsigned int a1, __int64 a2, __int64 *a3, __int64 a4, __int64 a5)
{
unsigned int v5; // er12
__int64 v6; // rbp
int v8; // eax
int v9; // er14
bool v10; // zf
int v11; // er14
__m128i v12; // xmm0
__m128i v13; // xmm1
int v15; // edx
_DWORD *v16; // r9
unsigned __int8 v17; // r13
unsigned int v18; // esi
int v19; // eax
size_t v21; // r14
int v22; // eax
__m128i v23; // xmm2
__m128i v24; // xmm3
int v25; // eax
int v26; // eax
void *v27; // rax
_DWORD *v28; // rax
unsigned int v29; // eax
int v30; // esi
_DWORD *v31; // rax
__int64 v32; // r10
_BYTE *v33; // rdi
_QWORD *ptra; // [rsp+8h] [rbp-50h]
void *ptr; // [rsp+8h] [rbp-50h]
__int64 v36; // [rsp+10h] [rbp-48h]
int v37; // [rsp+10h] [rbp-48h]
__int64 v38; // [rsp+18h] [rbp-40h]

v5 = a1 + 40;
if ( *(_DWORD *)(a2 + 20) >= a1 + 40 )
{
v6 = *a3;
v8 = *(unsigned __int8 *)(*a3 + a1 + 5);
v9 = *(unsigned __int8 *)(*a3 + a1 + 4) << 8;
v10 = v8 + v9 == 0;
v11 = v8 + v9;
*(_DWORD *)(a4 + 40) = v11;
v12 = _mm_loadu_si128((const __m128i *)(v6 + a1 + 8));
*(_BYTE *)a4 = 6;
*(__m128i *)(a4 + 4) = v12;
v13 = _mm_loadu_si128((const __m128i *)(v6 + a1 + 24));
*(_BYTE *)(a4 + 20) = 6;
*(__m128i *)(a4 + 24) = v13;
if ( v10 )
{
v5 = 0;
fwrite("Zero Length IP packet, possible Jumbo Payload.\n", 1uLL, 0x2FuLL, stderr);
return v5;
}
v15 = 0;
v16 = 0LL;
v17 = *(_BYTE *)(v6 + a1 + 6);
while ( 1 )
{
switch ( v17 )
{
case 0u:
case 0x2Bu:
case 0x3Cu:
if ( *(_DWORD *)(a2 + 20) < v5 + 16 )
goto LABEL_8;
v15 += 16;
v17 = *(_BYTE *)(v6 + v5);
v5 += *(unsigned __int8 *)(v6 + v5 + 1) + 1;
continue;
case 1u:
case 2u:
case 3u:
case 4u:
case 5u:
case 7u:
case 8u:
case 9u:
case 0xAu:
case 0xBu:
case 0xCu:
case 0xDu:
case 0xEu:
case 0xFu:
case 0x10u:
case 0x12u:
case 0x13u:
case 0x14u:
case 0x15u:
case 0x16u:
case 0x17u:
case 0x18u:
case 0x19u:
case 0x1Au:
case 0x1Bu:
case 0x1Cu:
case 0x1Du:
case 0x1Eu:
case 0x1Fu:
case 0x20u:
case 0x21u:
case 0x22u:
case 0x23u:
case 0x24u:
case 0x25u:
case 0x26u:
case 0x27u:
case 0x28u:
case 0x29u:
case 0x2Au:
case 0x2Du:
case 0x2Eu:
case 0x2Fu:
case 0x30u:
case 0x31u:
case 0x34u:
case 0x35u:
case 0x36u:
case 0x37u:
case 0x38u:
case 0x39u:
case 0x3Au:
case 0x3Bu:
goto LABEL_9;
case 6u:
case 0x11u:
v21 = (unsigned int)(v11 - v15);
*(_BYTE *)(a4 + 44) = v17;
*(_DWORD *)(a4 + 40) = v21;
if ( !v16 )
return v5;
v22 = *(_DWORD *)(a4 + 16);
v23 = _mm_loadu_si128((const __m128i *)a4);
v36 = a5;
v24 = _mm_loadu_si128((const __m128i *)(a4 + 20));
*((_QWORD *)v16 + 10) = 0LL;
v16[5] = v22;
v25 = *(_DWORD *)(a4 + 36);
*((_QWORD *)v16 + 9) = 0LL;
v16[10] = v25;
v26 = v16[11];
*(__m128i *)(v16 + 1) = v23;
*(__m128i *)(v16 + 6) = v24;
v16[12] = v21 + v26;
ptra = v16;
v27 = malloc(v21);
ptra[7] = v27;
memcpy(v27, (const void *)(v6 + v5), v21);
v28 = (_DWORD *)func2(ptra, v36);
if ( v28 )
{
*(_DWORD *)(a4 + 40) = v28[12] - v28[11];
free(v28);
}
return 0;
case 0x2Cu:
v38 = a5;
v37 = v15;
v17 = *(_BYTE *)(v6 + v5);
v31 = malloc(0x58uLL);
v32 = v5;
v16 = v31;
v33 = (_BYTE *)(v6 + v5 + 3);
a5 = v38;
LODWORD(v31) = *(unsigned __int8 *)(v6 + v5 + 2);
v15 = v37 + 8;
v5 += 8;
v16[11] = ((_DWORD)v31 << 8) + (*v33 & 0xF4);
*((_BYTE *)v16 + 64) = *v33 & 1;
*v16 = *(_DWORD *)(v6 + v32 + 4);
continue;
case 0x32u:
ptr = v16;
fwrite("Unsupported protocol: IPv6 ESP.\n", 1uLL, 0x20uLL, stderr);
if ( !ptr )
return 0;
v5 = 0;
free(ptr);
return v5;
case 0x33u:
v29 = *(_DWORD *)(a2 + 20);
if ( v29 < v5 + 2 )
goto LABEL_8;
v17 = *(_BYTE *)(v6 + v5);
v30 = 4 * *(unsigned __int8 *)(v6 + v5 + 1) + 8;
v5 += v30;
v15 += v30;
if ( v29 < v5 )
goto LABEL_8;
continue;
default:
if ( v17 != 0x87 )
{
LABEL_9:
v5 = 0;
fprintf(stderr, "Unsupported IPv6 proto(%u).\n", v17);
return v5;
}
v18 = *(_DWORD *)(a2 + 20);
if ( v18 < v5 + 2 )
goto LABEL_8;
v17 = *(_BYTE *)(v6 + v5);
v19 = 8 * *(unsigned __int8 *)(v6 + v5 + 1);
v5 += v19;
v15 += v19;
if ( v18 < v5 )
goto LABEL_8;
break;
}
}
}
LABEL_8:
v5 = 0;
fwrite("Truncated Packet(ipv6)\n", 1uLL, 0x17uLL, stderr);
return v5;
}

original_code:
uint32_t ipv6_parse(uint32_t pos, struct pcap_pkthdr *header,
                    uint8_t ** p_packet, ip_info * ip, config * conf) {
    uint8_t * packet = *p_packet;
    ip_fragment * frag = ((void *)0);
    uint32_t header_len = 0;
    if (header->len < (pos + 40)) {
        fprintf(stderr, "Truncated Packet(ipv6)\n");
        p_packet=((void *)0); return 0;
    }
    ip->length = (packet[pos+4] << 8) + packet[pos+5];
    memcpy(ip->src.addr.v6.__in6_u.__u6_addr8, packet + pos + 8, 16); ip->src.vers = 0x06;;
    memcpy(ip->dst.addr.v6.__in6_u.__u6_addr8, packet + pos + 24, 16); ip->dst.vers = 0x06;;
    if (ip->length == 0) {
        fprintf(stderr, "Zero Length IP packet, possible Jumbo Payload.\n");
        p_packet=((void *)0); return 0;
    }
    uint8_t next_hdr = packet[pos+6];

    pos += 40;
    uint8_t done = 0;
    while (done == 0) {

        switch (next_hdr) {
            case IPPROTO_HOPOPTS:
            case IPPROTO_DSTOPTS:
            case IPPROTO_ROUTING:
                if (header->len < (pos + 16)) {
                    fprintf(stderr, "Truncated Packet(ipv6)\n");
                    p_packet = ((void *)0); return 0;
                }
                next_hdr = packet[pos];
                header_len += 16;
                pos += packet[pos+1] + 1;
                break;
            case 51:
                if (header->len < (pos + 2)) {
                    fprintf(stderr, "Truncated Packet(ipv6)\n");
                    p_packet = ((void *)0); return 0;
                }
                next_hdr = packet[pos];
                header_len += (packet[pos+1] + 2) * 4;
                pos += (packet[pos+1] + 2) * 4;
                if (header->len < pos) {
                    fprintf(stderr, "Truncated Packet(ipv6)\n");
                    p_packet = ((void *)0); return 0;
                }
                break;
            case 50:
                fprintf(stderr, "Unsupported protocol: IPv6 ESP.\n");
                if (frag != ((void *)0)) free(frag);
                p_packet = ((void *)0); return 0;
            case 135:
                if (header->len < (pos + 2)) {
                    fprintf(stderr, "Truncated Packet(ipv6)\n");
                    p_packet = ((void *)0); return 0;
                }
                next_hdr = packet[pos];
                header_len += packet[pos+1] * 8;
                pos += packet[pos+1] * 8;
                if (header->len < pos) {
                    fprintf(stderr, "Truncated Packet(ipv6)\n");
                    p_packet = ((void *)0); return 0;
                }
                break;
            case IPPROTO_FRAGMENT:
                next_hdr = packet[pos];
                frag = malloc(sizeof(ip_fragment));
                frag->start = (packet[pos+2] << 8) + (packet[pos+3] & 0xf4);
                frag->islast = packet[pos+3] & 0x01;
                frag->id = *(uint32_t *)(packet+pos+4);
                header_len += 8;
                pos += 8;
                break;
            case 0x06:
            case 0x11:
                done = 1;
                break;
            default:
                fprintf(stderr, "Unsupported IPv6 proto(%u).\n", next_hdr);
                p_packet = ((void *)0); return 0;
        }
    }
    ip->proto = next_hdr;
    ip->length = ip->length - header_len;
    if (frag != ((void *)0)) {
        frag->src = ip->src;
        frag->dst = ip->dst;
        frag->end = frag->start + ip->length;
        frag->next = frag->child = ((void *)0);
        frag->data = malloc(sizeof(uint8_t) * ip->length);

        memcpy(frag->data, packet+pos, ip->length);
        frag = ip_frag_add(frag, conf);
        if (frag != ((void *)0)) {
            ip->length = frag->end - frag->start;
            p_packet = &(frag->data);
            free(frag);
            return 0;
        }
        p_packet = ((void *)0);
        return 0;
    } else {
        return pos;
    }
}

canonical_original_code:
unsigned int ipv6_parse(unsigned int pos, struct pcap_pkthdr *header, unsigned char **p_packet, struct ip_info *ip, struct config *conf) {
    unsigned char *packet = *p_packet;
    struct ip_fragment *frag = ((void *)0);
    unsigned int header_len = 0;
    if (header->len < (pos + 40)) {
        fprintf(stderr, "Truncated Packet(ipv6)\n");
        p_packet=((void *)0); return 0;
    }
    ip->length = (packet[pos+4] << 8) + packet[pos+5];
    memcpy(ip->src.addr.v6.__in6_u.__u6_addr8, packet + pos + 8, 16); ip->src.vers = 0x06;;
    memcpy(ip->dst.addr.v6.__in6_u.__u6_addr8, packet + pos + 24, 16); ip->dst.vers = 0x06;;
    if (ip->length == 0) {
        fprintf(stderr, "Zero Length IP packet, possible Jumbo Payload.\n");
        p_packet=((void *)0); return 0;
    }
    unsigned char next_hdr = packet[pos+6];

    pos += 40;
    unsigned char done = 0;
    while (done == 0) {

        switch (next_hdr) {
            case IPPROTO_HOPOPTS:
            case IPPROTO_DSTOPTS:
            case IPPROTO_ROUTING:
                if (header->len < (pos + 16)) {
                    fprintf(stderr, "Truncated Packet(ipv6)\n");
                    p_packet = ((void *)0); return 0;
                }
                next_hdr = packet[pos];
                header_len += 16;
                pos += packet[pos+1] + 1;
                break;
            case 51:
                if (header->len < (pos + 2)) {
                    fprintf(stderr, "Truncated Packet(ipv6)\n");
                    p_packet = ((void *)0); return 0;
                }
                next_hdr = packet[pos];
                header_len += (packet[pos+1] + 2) * 4;
                pos += (packet[pos+1] + 2) * 4;
                if (header->len < pos) {
                    fprintf(stderr, "Truncated Packet(ipv6)\n");
                    p_packet = ((void *)0); return 0;
                }
                break;
            case 50:
                fprintf(stderr, "Unsupported protocol: IPv6 ESP.\n");
                if (frag != ((void *)0)) free(frag);
                p_packet = ((void *)0); return 0;
            case 135:
                if (header->len < (pos + 2)) {
                    fprintf(stderr, "Truncated Packet(ipv6)\n");
                    p_packet = ((void *)0); return 0;
                }
                next_hdr = packet[pos];
                header_len += packet[pos+1] * 8;
                pos += packet[pos+1] * 8;
                if (header->len < pos) {
                    fprintf(stderr, "Truncated Packet(ipv6)\n");
                    p_packet = ((void *)0); return 0;
                }
                break;
            case IPPROTO_FRAGMENT:
                next_hdr = packet[pos];
                frag = malloc(sizeof(ip_fragment));
                frag->start = (packet[pos+2] << 8) + (packet[pos+3] & 0xf4);
                frag->islast = packet[pos+3] & 0x01;
                frag->id = *(unsigned int *)(packet+pos+4);
                header_len += 8;
                pos += 8;
                break;
            case 0x06:
            case 0x11:
                done = 1;
                break;
            default:
                fprintf(stderr, "Unsupported IPv6 proto(%u).\n", next_hdr);
                p_packet = ((void *)0); return 0;
        }
    }
    ip->proto = next_hdr;
    ip->length = ip->length - header_len;
    if (frag != ((void *)0)) {
        frag->src = ip->src;
        frag->dst = ip->dst;
        frag->end = frag->start + ip->length;
        frag->next = frag->child = ((void *)0);
        frag->data = malloc(sizeof(unsigned char) * ip->length);

        memcpy(frag->data, packet+pos, ip->length);
        frag = ip_frag_add(frag, conf);
        if (frag != ((void *)0)) {
            ip->length = frag->end - frag->start;
            p_packet = &(frag->data);
            free(frag);
            return 0;
        }
        p_packet = ((void *)0);
        return 0;
    } else {
        return pos;
    }
}

variable_types:
done
unsigned char

user_defined_types: struct in6_addr { union { unsigned char __u6_addr8[16]; unsigned short __u6_addr16[8]; unsigned int __u6_addr32[4]; } __in6_u; }


original_code:
void ip_frag_free(config * conf) {
    ip_fragment * curr;
    ip_fragment * child;
    while (conf->ip_fragment_head != ((void *)0)) {
        curr = conf->ip_fragment_head;
        conf->ip_fragment_head = curr->next;
        while (curr != ((void *)0)) {
            child = curr->child;
            free(curr->data);
            free(curr);
            curr = child;
        }
    }
}

canonical_original_code:
void ip_frag_free(struct config *conf) {
    struct ip_fragment *curr;
    struct ip_fragment *child;
    while (conf->ip_fragment_head != ((void *)0)) {
        curr = conf->ip_fragment_head;
        conf->ip_fragment_head = curr->next;
        while (curr != ((void *)0)) {
            child = curr->child;
            free(curr->data);
            free(curr);
            curr = child;
        }
    }
}

variable_types: struct config { unsigned short EXCLUDED[100]; unsigned short EXCLUDES; char SEP; char *RECORD_SEP; int AD_ENABLED; int NS_ENABLED; int COUNTS; int PRETTY_DATE; int PRINT_RR_NAME; int MISSING_TYPE_WARNINGS; char *TCP_STATE_PATH; unsigned int DEDUPS; struct tcp_info { struct timeval { long tv_sec; long tv_usec; } ts; struct ip_addr { unsigned char vers; union { struct in_addr { unsigned int s_addr; } v4; struct in6_addr { union { unsigned char __u6_addr8[16]; unsigned short __u6_addr16[8]; unsigned int __u6_addr32[4]; } __in6_u; } v6; } addr; } src; struct ip_addr dst; unsigned short srcport; unsigned short dstport; unsigned int sequence; unsigned int ack_num; unsigned int len; unsigned char syn; unsigned char ack; unsigned char fin; unsigned char rst; unsigned char *data; struct tcp_info *next_sess; struct tcp_info *next_pkt; struct tcp_info *prev_pkt; } *tcp_sessions_head; struct ip_fragment { unsigned int id; struct ip_addr src; struct ip_addr dst; unsigned int start; unsigned int end; unsigned char *data; unsigned char islast; struct ip_fragment *next; struct ip_fragment *child; } *ip_fragment_head; unsigned long long *dedup_hashes; unsigned int dedup_pos; } *


original_code:
uint32_t udp_parse(uint32_t pos, struct pcap_pkthdr *header,
                   uint8_t *packet, transport_info * udp,
                   config * conf) {
    if (header->len - pos < 8) {
        fprintf(stderr, "Truncated Packet(udp)\n");
        return 0;
    }
    udp->srcport = (packet[pos] << 8) + packet[pos+1];
    udp->dstport = (packet[pos+2] << 8) + packet[pos+3];
    udp->length = (packet[pos+4] << 8) + packet[pos+5];
    udp->transport = 0x11;

    return pos + 8;
}

canonical_original_code:
unsigned int udp_parse(unsigned int pos, struct pcap_pkthdr *header, unsigned char *packet, struct transport_info *udp, struct config *conf) {
    if (header->len - pos < 8) {
        fprintf(stderr, "Truncated Packet(udp)\n");
        return 0;
    }
    udp->srcport = (packet[pos] << 8) + packet[pos+1];
    udp->dstport = (packet[pos+2] << 8) + packet[pos+3];
    udp->length = (packet[pos+4] << 8) + packet[pos+5];
    udp->transport = 0x11;

    return pos + 8;
}

variable_types: struct transport_info { unsigned short srcport; unsigned short dstport; unsigned short length; unsigned char transport; } *

variable_types: struct config { unsigned short EXCLUDED[100]; unsigned short EXCLUDES; char SEP; char *RECORD_SEP; int AD_ENABLED; int NS_ENABLED; int COUNTS; int PRETTY_DATE; int PRINT_RR_NAME; int MISSING_TYPE_WARNINGS; char *TCP_STATE_PATH; unsigned int DEDUPS; struct tcp_info { struct timeval ts; struct ip_addr { unsigned char vers; union { struct in_addr { unsigned int s_addr; } v4; struct in6_addr { union { unsigned char __u6_addr8[16]; unsigned short __u6_addr16[8]; unsigned int __u6_addr32[4]; } __in6_u; } v6; } addr; } src; struct ip_addr dst; unsigned short srcport; unsigned short dstport; unsigned int sequence; unsigned int ack_num; unsigned int len; unsigned char syn; unsigned char ack; unsigned char fin; unsigned char rst; unsigned char *data; struct tcp_info *next_sess; struct tcp_info *next_pkt; struct tcp_info *prev_pkt; } *tcp_sessions_head; struct ip_fragment { unsigned int id; struct ip_addr src; struct ip_addr dst; unsigned int start; unsigned int end; unsigned char *data; unsigned char islast; struct ip_fragment *next; struct ip_fragment *child; } *ip_fragment_head; unsigned long long *dedup_hashes; unsigned int dedup_pos; } *


iptostr

decompiled_code:
char *__fastcall iptostr(_BYTE *a1)
{
const void *v1; // rsi

v1 = a1 + 4;
if ( *a1 == 4 )
inet_ntop(2, v1, IP_STR_BUFF, 0x2Eu);
else
inet_ntop(10, v1, IP_STR_BUFF, 0x2Eu);
return IP_STR_BUFF;
}

canonical_decompiled_code:
char *__fastcall func7(_BYTE *a1)
{
const void *v1; // rsi

v1 = a1 + 4;
if ( *a1 == 4 )
inet_ntop(2, v1, IP_STR_BUFF, 0x2Eu);
else
inet_ntop(10, v1, IP_STR_BUFF, 0x2Eu);
return IP_STR_BUFF;
}

original_code:
char * iptostr(ip_addr * ip) {
    if (ip->vers == 0x04) {
        inet_ntop(2, (const void *) &(ip->addr.v4),
                  IP_STR_BUFF, 46);
    } else {
        inet_ntop(10, (const void *) &(ip->addr.v6),
                  IP_STR_BUFF, 46);
    }
    return IP_STR_BUFF;
}

canonical_original_code:
char *iptostr(struct ip_addr *ip) {
    if (ip->vers == 0x04) {
        inet_ntop(2, (void *) &(ip->addr.v4),
                  IP_STR_BUFF, 46);
    } else {
        inet_ntop(10, (void *) &(ip->addr.v6),
                  IP_STR_BUFF, 46);
    }
    return IP_STR_BUFF;
}

variable_types: struct ip_addr { unsigned char vers; union { struct in_addr { unsigned int s_addr; } v4; struct in6_addr { union { unsigned char __u6_addr8[16]; unsigned short __u6_addr16[8]; unsigned int __u6_addr32[4]; } __in6_u; } v6; } addr; } *


getIpVersion

decompiled_code:
__int64 __fastcall getIpVersion(__int64 a1)
{
int v1; // eax

LOWORD(v1) = _bswap_16(*(_WORD *)(a1 + 12));
if ( (_WORD)v1 == 0x86DD )
return 6LL;
LOBYTE(v1) = (_WORD)v1 == 2048;
return (unsigned int)(4 * v1);
}

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

LOWORD(v1) = func0(*(_WORD *)(a1 + 12));
if ( (_WORD)v1 == 0x86DD )
return 6LL;
LOBYTE(v1) = (_WORD)v1 == 2048;
return (unsigned int)(4 * v1);
}

original_code:
char getIpVersion(const unsigned char *packet) {
  struct ethernet_header *ethernet = (struct ethernet_header*) packet;
  if (ntohs(ethernet->ether_type) == 0x86DD)
    return 6;
  else if (ntohs(ethernet->ether_type) == 0x800)
    return 4;
  return 0;
}

canonical_original_code:
char getIpVersion(unsigned char *packet) {
  struct ethernet_header *ethernet = (struct ethernet_header*) packet;
  if (ntohs(ethernet->ether_type) == 0x86DD)
    return 6;
  else if (ntohs(ethernet->ether_type) == 0x800)
    return 4;
  return 0;
}

variable_types: struct ethernet_header { unsigned char ether_dhost[6]; unsigned char ether_shost[6]; unsigned short ether_type; } *

return_type: char


getEthernetHeader

decompiled_code:
__int64 __fastcall getEthernetHeader(__int64 a1)
{
return a1;
}

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

original_code:
struct ethernet_header* getEthernetHeader(const unsigned char *packet) {
  return (struct ethernet_header*) packet;
}

canonical_original_code:
struct ethernet_header *getEthernetHeader(unsigned char *packet) {
  return (struct ethernet_header *) packet;
}

variable_types:
packet
unsigned char *

return_type: struct ethernet_header { unsigned char ether_dhost[6]; unsigned char ether_shost[6]; unsigned short ether_type; } *


decompiled_code:
__int64 __fastcall getIPv4Header(__int64 a1)
{
__int64 v1; // rdx
char v2; // r8
__int64 result; // rax
unsigned __int8 v4; // cl
__int64 v5; // rdx

v2 = getIpVersion(a1);
result = 0LL;
if ( v2 == 4 )
{
v4 = *(_BYTE *)(v1 + 14);
v5 = v1 + 14;
if ( v4 >> 4 == 4 )
result = v5;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1)
{
__int64 v1; // rdx
char v2; // r8
__int64 result; // rax
unsigned __int8 v4; // cl
__int64 v5; // rdx

v2 = func1(a1);
result = 0LL;
if ( v2 == 4 )
{
v4 = *(_BYTE *)(v1 + 14);
v5 = v1 + 14;
if ( v4 >> 4 == 4 )
result = v5;
}
return result;
}

original_code:
struct ipv4_header* getIPv4Header(const unsigned char *packet) {
  if (getIpVersion(packet) == 4) {
    struct ipv4_header* output = (struct ipv4_header*) (packet + 14);
    if ((((output)->ip_vhl) >> 4) == 4)
      return output;
  }
  return ((void *)0);
}

canonical_original_code:
struct ipv4_header *getIPv4Header(unsigned char *packet) {
  if (getIpVersion(packet) == 4) {
    struct ipv4_header *output = (struct ipv4_header*) (packet + 14);
    if ((((output)->ip_vhl) >> 4) == 4)
      return output;
  }
  return ((void *)0);
}

variable_types: struct ipv4_header { unsigned char ip_vhl; unsigned char ip_tos; unsigned short ip_len; unsigned short ip_id; unsigned short ip_off; unsigned char ip_ttl; unsigned char ip_p; unsigned short ip_sum; struct in_addr { unsigned int s_addr; } ip_src; } *

user_defined_types: struct ipv4_header { unsigned char ip_vhl; unsigned char ip_tos; unsigned short ip_len; unsigned short ip_id; unsigned short ip_off; unsigned char ip_ttl; unsigned char ip_p; unsigned short ip_sum; struct in_addr ip_src; }


decompiled_code:
__int64 __fastcall getUDPHeaderFromIPv4(__int64 a1, _BYTE *a2)
{
__int64 result; // rax

result = 0LL;
if ( a2[9] == 17 )
result = a1 + 4LL * (*a2 & 0xF) + 14;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1, _BYTE *a2)
{
__int64 result; // rax

result = 0LL;
if ( a2[9] == 17 )
result = a1 + 4LL * (*a2 & 0xF) + 14;
return result;
}

original_code:
struct udp_header* getUDPHeaderFromIPv4(const unsigned char *packet, struct ipv4_header* ipv4) {
  if (ipv4->ip_p == 17)
    return (struct udp_header*) (packet + 14 + ((((ipv4)->ip_vhl) & 0x0f) * 4));
  return ((void *)0);
}

canonical_original_code:
struct udp_header *getUDPHeaderFromIPv4(unsigned char *packet, struct ipv4_header *ipv4) {
  if (ipv4->ip_p == 17)
    return (struct udp_header *) (packet + 14 + ((((ipv4)->ip_vhl) & 0x0f) * 4));
  return ((void *)0);
}

return_type: struct udp_header { unsigned short sport; unsigned short dport; unsigned short udp_length; unsigned short udp_sum; } *


initContext

decompiled_code:
__int64 initContext()
{
fwrite("initContext();\n", 1uLL, 0xFuLL, stderr);
return 3735928559LL;
}

canonical_decompiled_code:
__int64 func6()
{
fwrite("initContext();\n", 1uLL, 0xFuLL, stderr);
return 3735928559LL;
}

original_code:
void* initContext() {
  fprintf(stderr, "initContext();\n");
  return (void*) 0xDEADBEEF;
}

canonical_original_code:
void *initContext() {
  fprintf(stderr, "initContext();\n");
  return (void *) 0xDEADBEEF;
}


parseConfig

decompiled_code:
int __fastcall parseConfig(const char *a1, const char *a2, const void *a3)
{
return fprintf(stderr, "parseConfig('%s', '%s', %p);\n", a1, a2, a3);
}

canonical_decompiled_code:
int __fastcall func7(const char *a1, const char *a2, const void *a3)
{
return fprintf(stderr, "parseConfig('%s', '%s', %p);\n", a1, a2, a3);
}

original_code:
void parseConfig(char* key, char* value, void* context) {
  fprintf(stderr, "parseConfig('%s', '%s', %p);\n", key, value, context);
}

canonical_original_code:
void parseConfig(char *key, char *value, void *context) {
  fprintf(stderr, "parseConfig('%s', '%s', %p);\n", key, value, context);
}

variable_types:
key
char *

variable_types:
value
char *

variable_types:
context
void *


decompiled_code:
int __fastcall IPv4Callback(const void *a1, const void *a2, const void *a3, const void *a4, __int64 a5, __int64 a6, char a7)
{
return fprintf(stderr, "IPv4Callback(%p, %p, %p, %p, %p);\n", a1, a2, a3, &a7, a4);
}

canonical_decompiled_code:
int __fastcall func10(const void *a1, const void *a2, const void *a3, const void *a4, __int64 a5, __int64 a6, char a7)
{
return fprintf(stderr, "IPv4Callback(%p, %p, %p, %p, %p);\n", a1, a2, a3, &a7, a4);
}

original_code:
void IPv4Callback(struct ethernet_header* ethernet, struct ipv4_header* ipv4, const unsigned char *packet, struct pcap_pkthdr pkthdr, void* context) {
  fprintf(stderr, "IPv4Callback(%p, %p, %p, %p, %p);\n", ethernet, ipv4, packet, &pkthdr, context);
}

canonical_original_code:
void IPv4Callback(struct ethernet_header *ethernet, struct ipv4_header *ipv4, unsigned char *packet, struct pcap_pkthdr pkthdr, void *context) {
  fprintf(stderr, "IPv4Callback(%p, %p, %p, %p, %p);\n", ethernet, ipv4, packet, &pkthdr, context);
}

variable_types: struct pcap_pkthdr { struct timeval { long tv_sec; long tv_usec; } ts; unsigned int caplen; unsigned int len; }

user_defined_types: struct ethernet_header { unsigned char ether_dhost[6]; unsigned char ether_shost[6]; unsigned short ether_type; }


decompiled_code:
int __fastcall IPv4UDPCallback(const void *a1, const void *a2, const void *a3, const void *a4)
{
return fprintf(stderr, "IPv4UDPCallback(%p, %p, %p, %p);\n", a1, a2, a3, a4);
}

canonical_decompiled_code:
int __fastcall func11(const void *a1, const void *a2, const void *a3, const void *a4)
{
return fprintf(stderr, "IPv4UDPCallback(%p, %p, %p, %p);\n", a1, a2, a3, a4);
}

original_code:
void IPv4UDPCallback(struct ethernet_header* ethernet, struct ipv4_header* ipv4, struct udp_header* udp, void* context) {
  fprintf(stderr, "IPv4UDPCallback(%p, %p, %p, %p);\n", ethernet, ipv4, udp, context);
}

canonical_original_code:
void IPv4UDPCallback(struct ethernet_header *ethernet, struct ipv4_header *ipv4, struct udp_header *udp, void *context) {
  fprintf(stderr, "IPv4UDPCallback(%p, %p, %p, %p);\n", ethernet, ipv4, udp, context);
}

variable_types: struct udp_header { unsigned short sport; unsigned short dport; unsigned short udp_length; unsigned short udp_sum; } *


rawPacketCallback

decompiled_code:
int __fastcall rawPacketCallback(const void *a1, const void *a2, __int64 a3, __int64 a4, __int64 a5, __int64 a6, char a7)
{
return fprintf(stderr, "packetCallback(%p, %p, %p);\n", a1, &a7, a2);
}

canonical_decompiled_code:
int __fastcall func12(const void *a1, const void *a2, __int64 a3, __int64 a4, __int64 a5, __int64 a6, char a7)
{
return fprintf(stderr, "packetCallback(%p, %p, %p);\n", a1, &a7, a2);
}

original_code:
void rawPacketCallback(const unsigned char *packet, struct pcap_pkthdr pkthdr, void* context) {
  fprintf(stderr, "packetCallback(%p, %p, %p);\n", packet, &pkthdr, context);
}

canonical_original_code:
void rawPacketCallback(unsigned char *packet, struct pcap_pkthdr pkthdr, void *context) {
  fprintf(stderr, "packetCallback(%p, %p, %p);\n", packet, &pkthdr, context);
}


getPcapRule

decompiled_code:
char *__fastcall getPcapRule(const void *a1)
{
fprintf(stderr, "getPcapRule(%p);\n", a1);
return "";
}

canonical_decompiled_code:
char *__fastcall func8(const void *a1)
{
fprintf(stderr, "getPcapRule(%p);\n", a1);
return "";
}

original_code:
char* getPcapRule(void* context) {
  fprintf(stderr, "getPcapRule(%p);\n", context);
  return "";
}

canonical_original_code:
char *getPcapRule(void *context) {
  fprintf(stderr, "getPcapRule(%p);\n", context);
  return "";
}


decompiled_code:
__int64 __fastcall ip2ui(char *a1)
{
int v1; // ebp
char *v2; // rax
int v3; // er12
int v4; // ebx
char *v5; // rdi

v1 = 0;
v2 = strtok(a1, ".");
if ( v2 )
{
v3 = 2;
v1 = (int)((double)atoi(v2) * 16777216.0 + 0.0);
while ( 1 )
{
v5 = strtok(0LL, ".");
if ( !v5 )
break;
v4 = atoi(v5);
v1 = (int)((double)v4 * pow(256.0, (double)v3) + (double)v1);
if ( !v3 )
break;
--v3;
}
}
return (unsigned int)v1;
}

canonical_decompiled_code:
__int64 __fastcall func0(char *a1)
{
int v1; // ebp
char *v2; // rax
int v3; // er12
int v4; // ebx
char *v5; // rdi

v1 = 0;
v2 = strtok(a1, ".");
if ( v2 )
{
v3 = 2;
v1 = (int)((double)atoi(v2) * 16777216.0 + 0.0);
while ( 1 )
{
v5 = strtok(0LL, ".");
if ( !v5 )
break;
v4 = atoi(v5);
v1 = (int)((double)v4 * pow(256.0, (double)v3) + (double)v1);
if ( !v3 )
break;
--v3;
}
}
return (unsigned int)v1;
}

original_code:
unsigned int ip2ui(char *ip) {
  long ipAsUInt = 0;
  char *cPtr = strtok(ip, ".");
  if(cPtr)
    ipAsUInt += atoi(cPtr) * pow(256, 3);
  int exponent = 2;
  while(cPtr && exponent >= 0) {
    cPtr = strtok(((void *)0), ".\0");
    if(cPtr)
      ipAsUInt += atoi(cPtr) * pow(256, exponent--);
  }
  return ipAsUInt;
}

variable_types:
ip
char *

variable_types: ipAsUInt long

variable_types:
cPtr
char *

variable_types: exponent int


createBitmask

decompiled_code:
__int64 __fastcall createBitmask(const char *a1)
{
int v1; // ecx
__int64 result; // rax
unsigned int v3; // esi
int i; // edx
unsigned int v5; // edx

v1 = atol(a1) - 1;
LODWORD(result) = 1;
v3 = 31 - v1;
if ( !v1 )
goto LABEL_5;
for ( i = 0; i != v1; ++i )
result = (unsigned int)(2 * result + 1);
if ( v3 )
{
LABEL_5:
v5 = 0;
do
{
++v5;
result = (unsigned int)(2 * result);
}
while ( v5 < v3 );
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(const char *a1)
{
int v1; // ecx
__int64 result; // rax
unsigned int v3; // esi
int i; // edx
unsigned int v5; // edx

v1 = atol(a1) - 1;
LODWORD(result) = 1;
v3 = 31 - v1;
if ( !v1 )
goto LABEL_5;
for ( i = 0; i != v1; ++i )
result = (unsigned int)(2 * result + 1);
if ( v3 )
{
LABEL_5:
v5 = 0;
do
{
++v5;
result = (unsigned int)(2 * result);
}
while ( v5 < v3 );
}
return result;
}

original_code:
unsigned int createBitmask(const char *bitmask) {
  unsigned int times = (unsigned int) atol(bitmask) - 1;
  unsigned int i;
  unsigned int bitmaskAsUInt = 1;
  for (i = 0; i < times; ++i) {
    bitmaskAsUInt <<= 1;
    bitmaskAsUInt |= 1;
  }
  for(i = 0; i < 32 - times - 1; ++i)
    bitmaskAsUInt <<= 1;
  return bitmaskAsUInt;
}

canonical_original_code:
unsigned int createBitmask(char *bitmask) {
  unsigned int times = (unsigned int) atol(bitmask) - 1;
  unsigned int i;
  unsigned int bitmaskAsUInt = 1;
  for (i = 0; i < times; ++i) {
    bitmaskAsUInt <<= 1;
    bitmaskAsUInt |= 1;
  }
  for(i = 0; i < 32 - times - 1; ++i)
    bitmaskAsUInt <<= 1;
  return bitmaskAsUInt;
}

variable_types:
bitmask
char *

variable_types:
times
unsigned int

variable_types:
i
unsigned int

variable_types:
bitmaskAsUInt
unsigned int


cidrToIpRange

decompiled_code:
__int64 __fastcall cidrToIpRange(char *a1, _DWORD *a2, _DWORD *a3)
{
char *v4; // rax
char *v5; // rbp
char *v6; // r13
int v7; // ebp
int v8; // eax

v4 = strtok(a1, "/");
if ( !v4 )
return 0LL;
v5 = v4;
v6 = strtok(0LL, byte_1A6);
if ( !v6 )
return 0LL;
v7 = ip2ui(v5);
v8 = createBitmask(v6);
*a2 = (v8 & v7) + 1;
*a3 = (v7 | ~v8) - 1;
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func2(char *a1, _DWORD *a2, _DWORD *a3)
{
char *v4; // rax
char *v5; // rbp
char *v6; // r13
int v7; // ebp
int v8; // eax

v4 = strtok(a1, "/");
if ( !v4 )
return 0LL;
v5 = v4;
v6 = strtok(0LL, byte_1A6);
if ( !v6 )
return 0LL;
v7 = func0(v5);
v8 = func1(v6);
*a2 = (v8 & v7) + 1;
*a3 = (v7 | ~v8) - 1;
return 1LL;
}

original_code:
int cidrToIpRange(char* cidr, unsigned int *startIp, unsigned int *endIp) {
  char* ip = strtok(cidr, "/");
  if (!ip)
    return 0;
  char* bitmask = strtok(((void *)0), "\0");
  if (!bitmask)
    return 0;
  unsigned int ipAsUInt = ip2ui(ip);
  unsigned int bitmaskAsUInt = createBitmask(bitmask);
  *startIp = (ipAsUInt & bitmaskAsUInt) + 1;
  *endIp = (ipAsUInt | ~bitmaskAsUInt) - 1;
  return 1;
}

canonical_original_code:
int cidrToIpRange(char *cidr, unsigned int *startIp, unsigned int *endIp) {
  char *ip = strtok(cidr, "/");
  if (!ip)
    return 0;
  char *bitmask = strtok(((void *)0), "\0");
  if (!bitmask)
    return 0;
  unsigned int ipAsUInt = ip2ui(ip);
  unsigned int bitmaskAsUInt = createBitmask(bitmask);
  *startIp = (ipAsUInt & bitmaskAsUInt) + 1;
  *endIp = (ipAsUInt | ~bitmaskAsUInt) - 1;
  return 1;
}

variable_types:
cidr
char *

variable_types:
startIp
unsigned int *

variable_types:
endIp
unsigned int *

variable_types:
ipAsUInt
unsigned int


usage

decompiled_code:
__int64 __fastcall usage(const char *a1)
{
fprintf(stderr, "USAGE: %s [options]\n", a1);
fwrite("-h, --help\tShow this help.\n", 1uLL, 0x1BuLL, stderr);
fwrite("-C, --config\tUse this configuration file.\n", 1uLL, 0x2AuLL, stderr);
fwrite("-f, --file\tUse this file instead of actual data.\n", 1uLL, 0x31uLL, stderr);
fwrite("-T, --test-config\tTest the configuration file.\n", 1uLL, 0x2FuLL, stderr);
fwrite("-S, --sql-schema\tShow the sql schema assumed by this module.\n", 1uLL, 0x3DuLL, stderr);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func0(const char *a1)
{
fprintf(stderr, "USAGE: %s [options]\n", a1);
fwrite("-h, --help\tShow this help.\n", 1uLL, 0x1BuLL, stderr);
fwrite("-C, --config\tUse this configuration file.\n", 1uLL, 0x2AuLL, stderr);
fwrite("-f, --file\tUse this file instead of actual data.\n", 1uLL, 0x31uLL, stderr);
fwrite("-T, --test-config\tTest the configuration file.\n", 1uLL, 0x2FuLL, stderr);
fwrite("-S, --sql-schema\tShow the sql schema assumed by this module.\n", 1uLL, 0x3DuLL, stderr);
return 0LL;
}

original_code:
int usage(char* program) {
  fprintf(stderr, "USAGE: %s [options]\n", program);
  fprintf(stderr, "-h, --help\tShow this help.\n");
  fprintf(stderr, "-C, --config\tUse this configuration file.\n");
  fprintf(stderr, "-f, --file\tUse this file instead of actual data.\n");
  fprintf(stderr, "-T, --test-config\tTest the configuration file.\n");
  fprintf(stderr, "-S, --sql-schema\tShow the sql schema assumed by this module.\n");
  return 0;
}

canonical_original_code:
int usage(char *program) {
  fprintf(stderr, "USAGE: %s [options]\n", program);
  fprintf(stderr, "-h, --help\tShow this help.\n");
  fprintf(stderr, "-C, --config\tUse this configuration file.\n");
  fprintf(stderr, "-f, --file\tUse this file instead of actual data.\n");
  fprintf(stderr, "-T, --test-config\tTest the configuration file.\n");
  fprintf(stderr, "-S, --sql-schema\tShow the sql schema assumed by this module.\n");
  return 0;
}

variable_types:
program
char *


hex

repo: scholarly/kbsum

decompiled_code:
__int64 __fastcall hex(char a1)
{
int v1; // edi
__int64 result; // rax

v1 = a1 & 0xF;
result = (unsigned int)(v1 + 87);
if ( (char)v1 <= 9 )
result = (unsigned int)(v1 + 48);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func8(char a1)
{
int v1; // edi
__int64 result; // rax

v1 = a1 & 0xF;
result = (unsigned int)(v1 + 87);
if ( (char)v1 <= 9 )
result = (unsigned int)(v1 + 48);
return result;
}

original_code:
char hex(char c) {
 c &= 0xf;
 return c < 10 ? c + '0' : c + 'a' - 10;
}

variable_types: c char


hexlify

decompiled_code:
__int64 __fastcall hexlify(_BYTE *a1, unsigned __int64 a2, char *a3, __int64 a4)
{
char v5; // cl
char v6; // al
__int64 v7; // r8
char v8; // cl
char v9; // al
__int64 v10; // r9
__int64 v11; // r11
__int64 v12; // r8
char *v13; // r10
__int64 result; // rax

if ( 2 * a4 > a2 )
__assert_fail("outlen >= bytes * 2", "genpass.c", 0x16u, "hexlify");
if ( a4 )
{
do
{
v5 = *a3++;
v6 = hex(v5 >> 4);
*(_BYTE *)(v7 - 3) = v6;
v9 = hex(v8);
*(_BYTE *)(v12 - 2) = v9;
}
while ( a3 != v13 );
result = v11;
*(_BYTE *)(v11 + v10) = 0;
}
else
{
*a1 = 0;
result = 0LL;
}
return result;
}

original_code:
size_t hexlify(char *out, size_t outlen, char *subject, size_t bytes) {
 ((void) sizeof ((outlen >= bytes * 2) ? 1 : 0), __extension__ ({ if (outlen >= bytes * 2) ; else __assert_fail ("outlen >= bytes * 2", "genpass.c", 22, __extension__ __PRETTY_FUNCTION__); }));
 size_t j = 0;
 for (size_t i = 0; i < bytes;) {
  char c = subject[i++];
  out[j++] = hex(c >> 4);
  out[j++] = hex(c);
 }
 out[j] = '\0';
 return j;
}

canonical_original_code:
unsigned long hexlify(char *out, unsigned long outlen, char *subject, unsigned long bytes) {
 ((void) sizeof ((outlen >= bytes * 2) ? 1 : 0), __extension__ ({ if (outlen >= bytes * 2) ; else __assert_fail ("outlen >= bytes * 2", "genpass.c", 22, __extension__ __PRETTY_FUNCTION__); }));
 unsigned long j = 0;
 for (unsigned long i = 0; i < bytes;) {
  char c = subject[i++];
  out[j++] = hex(c >> 4);
  out[j++] = hex(c);
 }
 out[j] = '\0';
 return j;
}

variable_types:
out
char *

variable_types:
outlen
unsigned long

variable_types:
subject
char *

variable_types:
bytes
unsigned long

variable_types:
j
unsigned long

variable_types:
i
unsigned long


bigdivide

decompiled_code:
__int64 __fastcall bigdivide(unsigned __int8 *a1, __int64 a2, unsigned int a3, unsigned int *a4)
{
unsigned __int8 *v5; // r9
unsigned int v6; // er8
unsigned int v7; // ecx
int v8; // eax
unsigned int v9; // eax
int v10; // ecx
int v11; // eax
__int64 result; // rax

if ( a2 )
{
v5 = &a1[a2];
v6 = 0;
v7 = 0;
do
{
v8 = *a1++;
v9 = v8 + v7;
v10 = v9 << 8;
v11 = v9 / a3;
*(a1 - 1) = v11;
v6 |= v11;
v7 = v10 - a3 * (v11 << 8);
}
while ( v5 != a1 );
result = v6;
*a4 = v7 >> 8;
}
else
{
*a4 = 0;
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func10(unsigned __int8 *a1, __int64 a2, unsigned int a3, unsigned int *a4)
{
unsigned __int8 *v5; // r9
unsigned int v6; // er8
unsigned int v7; // ecx
int v8; // eax
unsigned int v9; // eax
int v10; // ecx
int v11; // eax
__int64 result; // rax

if ( a2 )
{
v5 = &a1[a2];
v6 = 0;
v7 = 0;
do
{
v8 = *a1++;
v9 = v8 + v7;
v10 = v9 << 8;
v11 = v9 / a3;
*(a1 - 1) = v11;
v6 |= v11;
v7 = v10 - a3 * (v11 << 8);
}
while ( v5 != a1 );
result = v6;
*a4 = v7 >> 8;
}
else
{
*a4 = 0;
result = 0LL;
}
return result;
}

original_code:
char bigdivide(char *big, size_t bytes, unsigned int small, unsigned int *remainder) {
 unsigned int c = 0;
 char nonzero = 0;
 for (size_t i = 0; i < bytes; ++i) {
  unsigned int v = (big[i] & 0xff) + c;
  unsigned int r = v / small;
  c = (v << 8) - ((r << 8) * small);
  big[i] = r & 0xff;
  nonzero |= big[i];
 }
 *remainder = c >> 8;
 return nonzero;
}

canonical_original_code:
char bigdivide(char *big, unsigned long bytes, unsigned int small, unsigned int *remainder) {
 unsigned int c = 0;
 char nonzero = 0;
 for (unsigned long i = 0; i < bytes; ++i) {
  unsigned int v = (big[i] & 0xff) + c;
  unsigned int r = v / small;
  c = (v << 8) - ((r << 8) * small);
  big[i] = r & 0xff;
  nonzero |= big[i];
 }
 *remainder = c >> 8;
 return nonzero;
}

variable_types:
big
char *

variable_types:
small
unsigned int

variable_types:
remainder
unsigned int *

variable_types:
c
unsigned int

variable_types: nonzero char

variable_types:
v
unsigned int

variable_types:
r
unsigned int


gvAcquireReadLock

repo: schumajs/egl-gles-remoting

decompiled_code:
__int64 __fastcall gvAcquireReadLock(pthread_rwlock_t *a1)
{
return (unsigned int)-(pthread_rwlock_rdlock(a1) != 0);
}

canonical_decompiled_code:
__int64 __fastcall func0(pthread_rwlock_t *a1)
{
return (unsigned int)-(pthread_rwlock_rdlock(a1) != 0);
}

original_code:
int
gvAcquireReadLock(GVrwlockptr lock)
{

    {
 if (pthread_rwlock_rdlock(lock) != 0)
 {
     goto e0;
 }
    }
    while (0) e0:
    {
 return -1;
    }
    return 0;
}

canonical_original_code:
int gvAcquireReadLock(union pthread_rwlock_t *lock)
{

    {
 if (pthread_rwlock_rdlock(lock) != 0)
 {
     goto e0;
 }
    }
    while (0) e0:
    {
 return -1;
    }
    return 0;
}

variable_types: union pthread_rwlock_t { struct __pthread_rwlock_arch_t { unsigned int __readers; unsigned int __writers; unsigned int __wrphase_futex; unsigned int __writers_futex; unsigned int __pad3; unsigned int __pad4; int __cur_writer; int __shared; char __rwelision; unsigned char __pad1[7]; unsigned long __pad2; unsigned int __flags; } __data; char __size[56]; long __align; } *

user_defined_types: union pthread_rwlock_t { struct __pthread_rwlock_arch_t __data; char __size[56]; long __align; }


gvAcquireWriteLock

decompiled_code:
__int64 __fastcall gvAcquireWriteLock(pthread_rwlock_t *a1)
{
return (unsigned int)-(pthread_rwlock_wrlock(a1) != 0);
}

canonical_decompiled_code:
__int64 __fastcall func1(pthread_rwlock_t *a1)
{
return (unsigned int)-(pthread_rwlock_wrlock(a1) != 0);
}

original_code:
int
gvAcquireWriteLock(GVrwlockptr lock)
{

    {
 if (pthread_rwlock_wrlock(lock) != 0)
 {
     goto e0;
 }
    }
    while (0) e0:
    {
 return -1;
    }
    return 0;
}

canonical_original_code:
int gvAcquireWriteLock(union pthread_rwlock_t *lock)
{

    {
 if (pthread_rwlock_wrlock(lock) != 0)
 {
     goto e0;
 }
    }
    while (0) e0:
    {
 return -1;
    }
    return 0;
}

user_defined_types: struct __pthread_rwlock_arch_t { unsigned int __readers; unsigned int __writers; unsigned int __wrphase_futex; unsigned int __writers_futex; unsigned int __pad3; unsigned int __pad4; int __cur_writer; int __shared; char __rwelision; unsigned char __pad1[7]; unsigned long __pad2; unsigned int __flags; }


gvReleaseRwLock

decompiled_code:
__int64 __fastcall gvReleaseRwLock(pthread_rwlock_t *a1)
{
return (unsigned int)-(pthread_rwlock_unlock(a1) != 0);
}

canonical_decompiled_code:
__int64 __fastcall func2(pthread_rwlock_t *a1)
{
return (unsigned int)-(pthread_rwlock_unlock(a1) != 0);
}

original_code:
int
gvReleaseRwLock(GVrwlockptr lock)
{

    {
 if (pthread_rwlock_unlock(lock) != 0)
 {
     goto e0;
 }
    }
    while (0) e0:
    {
 return -1;
    }
    return 0;
}

canonical_original_code:
int gvReleaseRwLock(union pthread_rwlock_t *lock)
{

    {
 if (pthread_rwlock_unlock(lock) != 0)
 {
     goto e0;
 }
    }
    while (0) e0:
    {
 return -1;
    }
    return 0;
}


gvDestroyRwLock

decompiled_code:
__int64 __fastcall gvDestroyRwLock(void *ptr)
{
unsigned int v1; // er12

if ( pthread_rwlock_destroy((pthread_rwlock_t *)ptr) )
return (unsigned int)-1;
v1 = 0;
free(ptr);
return v1;
}

canonical_decompiled_code:
__int64 __fastcall func3(void *ptr)
{
unsigned int v1; // er12

if ( pthread_rwlock_destroy((pthread_rwlock_t *)ptr) )
return (unsigned int)-1;
v1 = 0;
free(ptr);
return v1;
}

original_code:
int
gvDestroyRwLock(GVrwlockptr lock)
{

    {
 if (pthread_rwlock_destroy(lock) != 0)
 {
     goto e0;
 }
 free(lock);
    }
    while (0) e0:
    {
 return -1;
    }
    return 0;
}

canonical_original_code:
int gvDestroyRwLock(union pthread_rwlock_t *lock)
{

    {
 if (pthread_rwlock_destroy(lock) != 0)
 {
     goto e0;
 }
 free(lock);
    }
    while (0) e0:
    {
 return -1;
    }
    return 0;
}


gvAttachShm

decompiled_code:
__int64 __fastcall gvAttachShm(void *a1, int *a2, __off_t a3, size_t a4)
{
return (unsigned int)-((char *)mmap(a1, a4, 3, 17, *a2, a3) + 1 == 0LL);
}

canonical_decompiled_code:
__int64 __fastcall func0(void *a1, int *a2, __off_t a3, size_t a4)
{
return (unsigned int)-((char *)mmap(a1, a4, 3, 17, *a2, a3) + 1 == 0LL);
}

original_code:
int
gvAttachShm(void *toAddr, GVshmptr shm, size_t offset, size_t length)
{

    {
 if (mmap(toAddr, length, 0x1 | 0x2,
   0x10 | 0x01, shm->id, offset) == ((void *) -1))
 {
     goto e0;
 }
    }
    while (0) e0:
    {
 return -1;
    }
    return 0;
}

canonical_original_code:
int gvAttachShm(void *toAddr, struct GVshm *shm, unsigned long offset, unsigned long length)
{

    {
 if (mmap(toAddr, length, 0x1 | 0x2,
   0x10 | 0x01, shm->id, offset) == ((void *) -1))
 {
     goto e0;
 }
    }
    while (0) e0:
    {
 return -1;
    }
    return 0;
}

variable_types:
toAddr
void *

variable_types: struct GVshm { int id; unsigned long size; } *

variable_types:
offset
unsigned long

variable_types:
length
unsigned long


gvDetachShm

decompiled_code:
__int64 __fastcall gvDetachShm(void *a1, __int64 a2, __int64 a3, size_t a4)
{
return (unsigned int)-(munmap(a1, a4) == -1);
}

canonical_decompiled_code:
__int64 __fastcall func1(void *a1, __int64 a2, __int64 a3, size_t a4)
{
return (unsigned int)-(munmap(a1, a4) == -1);
}

original_code:
int
gvDetachShm(void *fromAddr, GVshmptr shm, size_t offset, size_t length)
{

    {
 if (munmap(fromAddr, length) == -1)
 {
     goto e0;
 }
    }
    while (0) e0:
    {
 return -1;
    }
    return 0;
}

canonical_original_code:
int gvDetachShm(void *fromAddr, struct GVshm *shm, unsigned long offset, unsigned long length)
{

    {
 if (munmap(fromAddr, length) == -1)
 {
     goto e0;
 }
    }
    while (0) e0:
    {
 return -1;
    }
    return 0;
}

variable_types:
fromAddr
void *

user_defined_types: struct GVshm { int id; unsigned long size; }


gvDestroyShm

decompiled_code:
int __fastcall gvDestroyShm(void *ptr)
{
int result; // eax

result = close(*(_DWORD *)ptr);
if ( result != -1 )
{
free(ptr);
result = 0;
}
return result;
}

canonical_decompiled_code:
int __fastcall func2(void *ptr)
{
int result; // eax

result = close(*(_DWORD *)ptr);
if ( result != -1 )
{
free(ptr);
result = 0;
}
return result;
}

original_code:
int
gvDestroyShm(GVshmptr shm)
{

    {
 if (close(shm->id) == -1)
 {
     goto e0;
 }
 free(shm);
    }
    while (0) e0:
    {
 return -1;
    }
    return 0;
}

canonical_original_code:
int gvDestroyShm(struct GVshm *shm)
{

    {
 if (close(shm->id) == -1)
 {
     goto e0;
 }
 free(shm);
    }
    while (0) e0:
    {
 return -1;
    }
    return 0;
}