decompiled_code:
__int64 __fastcall PND_OpenEventDeviceByName(char *s2)
{
unsigned int v1; // ebp
int v3; // eax
int v4; // ebx

for ( i = 0; ; ++i )
{
snprintf(event_name, 0x1EuLL, "/dev/input/event%d", i);
printf("Device: %s\n", event_name);
v3 = open(event_name, 2048);
v4 = v3;
if ( v3 < 0 )
{
perror("ERROR: Could not open device");
return 0;
}
ioctl(v3, 0x81004506uLL, dev_name);
v1 = strcmp(dev_name, s2);
if ( !v1 )
break;
close(v4);
}
if ( ioctl(v4, 0x80044501uLL, version) )
{
perror("evtest: can't get version");
}
else
{
printf("Input driver version is %d.%d.%d\n", (unsigned int)*(__int16 *)&version[2], version[1], version[0]);
ioctl(v4, 0x80084502uLL, id);
printf("Input device ID: bus 0x%x vendor 0x%x product 0x%x version 0x%x\n", id[0], id[1], id[2], id[3]);
ioctl(v4, 0x81004506uLL, dev_name);
printf("Input device name: \"%s\"\n", dev_name);
v1 = v4;
}
return v1;
}

canonical_decompiled_code:
__int64 __fastcall func5(char *s2)
{
unsigned int v1; // ebp
int v3; // eax
int v4; // ebx

for ( i = 0; ; ++i )
{
snprintf(event_name, 0x1EuLL, "/dev/input/event%d", i);
printf("Device: %s\n", event_name);
v3 = open(event_name, 2048);
v4 = v3;
if ( v3 < 0 )
{
perror("ERROR: Could not open device");
return 0;
}
ioctl(v3, 0x81004506uLL, dev_name);
v1 = strcmp(dev_name, s2);
if ( !v1 )
break;
close(v4);
}
if ( ioctl(v4, 0x80044501uLL, version) )
{
perror("evtest: can't get version");
}
else
{
printf("Input driver version is %d.%d.%d\n", (unsigned int)*(__int16 *)&version[2], version[1], version[0]);
ioctl(v4, 0x80084502uLL, id);
printf("Input device ID: bus 0x%x vendor 0x%x product 0x%x version 0x%x\n", id[0], id[1], id[2], id[3]);
ioctl(v4, 0x81004506uLL, dev_name);
printf("Input device name: \"%s\"\n", dev_name);
v1 = v4;
}
return v1;
}

original_code:
int PND_OpenEventDeviceByName ( char device_name[] ) {
  int fd;
  for (i = 0; 1; i++) {
    snprintf( event_name, sizeof(event_name), "/dev/input/event%d", i );
    printf( "Device: %s\n", event_name );
    if ((fd = open(event_name, 00 | 04000)) < 0) {
      perror("ERROR: Could not open device");
      return 0;
    }
    if (fd < 0) break;
    ioctl(fd, (((2U) << (((0 +8)+8)+14)) | (('E') << (0 +8)) | ((0x06) << 0) | ((sizeof(dev_name)) << ((0 +8)+8))), dev_name);
    if (strcmp(dev_name, device_name) == 0) {
      if (ioctl(fd, (((2U) << (((0 +8)+8)+14)) | ((('E')) << (0 +8)) | (((0x01)) << 0) | ((((sizeof(int)))) << ((0 +8)+8))), &version)) {
 perror("evtest: can't get version");
 return 0;
      }
      printf("Input driver version is %d.%d.%d\n",
      version >> 16, (version >> 8) & 0xff, version & 0xff);
      ioctl(fd, (((2U) << (((0 +8)+8)+14)) | ((('E')) << (0 +8)) | (((0x02)) << 0) | ((((sizeof(struct input_id)))) << ((0 +8)+8))), id);
      printf("Input device ID: bus 0x%x vendor 0x%x product 0x%x version 0x%x\n",
      id[0], id[1], id[2], id[3]);
      ioctl(fd, (((2U) << (((0 +8)+8)+14)) | (('E') << (0 +8)) | ((0x06) << 0) | ((sizeof(dev_name)) << ((0 +8)+8))), dev_name);
      printf("Input device name: \"%s\"\n", dev_name);
      return fd;
    }
    close(fd);
  }
  return 0;
}

canonical_original_code:
int PND_OpenEventDeviceByName(char device_name[]) {
  int fd;
  for (i = 0; 1; i++) {
    snprintf( event_name, sizeof(event_name), "/dev/input/event%d", i );
    printf( "Device: %s\n", event_name );
    if ((fd = open(event_name, 00 | 04000)) < 0) {
      perror("ERROR: Could not open device");
      return 0;
    }
    if (fd < 0) break;
    ioctl(fd, (((2U) << (((0 +8)+8)+14)) | (('E') << (0 +8)) | ((0x06) << 0) | ((sizeof(dev_name)) << ((0 +8)+8))), dev_name);
    if (strcmp(dev_name, device_name) == 0) {
      if (ioctl(fd, (((2U) << (((0 +8)+8)+14)) | ((('E')) << (0 +8)) | (((0x01)) << 0) | ((((sizeof(int)))) << ((0 +8)+8))), &version)) {
 perror("evtest: can't get version");
 return 0;
      }
      printf("Input driver version is %d.%d.%d\n",
      version >> 16, (version >> 8) & 0xff, version & 0xff);
      ioctl(fd, (((2U) << (((0 +8)+8)+14)) | ((('E')) << (0 +8)) | (((0x02)) << 0) | ((((sizeof(struct input_id)))) << ((0 +8)+8))), id);
      printf("Input device ID: bus 0x%x vendor 0x%x product 0x%x version 0x%x\n",
      id[0], id[1], id[2], id[3]);
      ioctl(fd, (((2U) << (((0 +8)+8)+14)) | (('E') << (0 +8)) | ((0x06) << 0) | ((sizeof(dev_name)) << ((0 +8)+8))), dev_name);
      printf("Input device name: \"%s\"\n", dev_name);
      return fd;
    }
    close(fd);
  }
  return 0;
}


repo: skeezix/libpnd-clone

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

fd_pndk = PND_OpenEventDeviceByName(pnd_key);
fd_gpio = PND_OpenEventDeviceByName(pnd_gpio);
fd_nub1 = PND_OpenEventDeviceByName(pnd_nub1);
result = PND_OpenEventDeviceByName(pnd_nub2);
fd_nub2 = result;
return result;
}

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

fd_pndk = func5(pnd_key);
fd_gpio = func5(pnd_gpio);
fd_nub1 = func5(pnd_nub1);
result = func5(pnd_nub2);
fd_nub2 = result;
return result;
}

original_code:
void PND_Setup_Controls ( void ) {
  fd_pndk = PND_OpenEventDeviceByName(pnd_key);
  fd_gpio = PND_OpenEventDeviceByName(pnd_gpio);
  fd_nub1 = PND_OpenEventDeviceByName(pnd_nub1);
  fd_nub2 = PND_OpenEventDeviceByName(pnd_nub2);
}

canonical_original_code:
void PND_Setup_Controls() {
  fd_pndk = PND_OpenEventDeviceByName(pnd_key);
  fd_gpio = PND_OpenEventDeviceByName(pnd_gpio);
  fd_nub1 = PND_OpenEventDeviceByName(pnd_nub1);
  fd_nub2 = PND_OpenEventDeviceByName(pnd_nub2);
}

return_type: void


decompiled_code:
__int64 __fastcall PND_Pad_RecentlyPressed(int a1)
{
int v1; // eax
unsigned int v2; // edx

if ( !GLES2D_Pad_old_0[a1] && (LOBYTE(v1) = GLES2D_Pad[a1], (_BYTE)v1) )
{
v1 = (unsigned __int8)v1;
v2 = 1;
}
else
{
v1 = (unsigned __int8)GLES2D_Pad[a1];
v2 = 0;
}
GLES2D_Pad_old_0[a1] = v1;
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func7(int a1)
{
int v1; // eax
unsigned int v2; // edx

if ( !GLES2D_Pad_old_0[a1] && (LOBYTE(v1) = GLES2D_Pad[a1], (_BYTE)v1) )
{
v1 = (unsigned __int8)v1;
v2 = 1;
}
else
{
v1 = (unsigned __int8)GLES2D_Pad[a1];
v2 = 0;
}
GLES2D_Pad_old_0[a1] = v1;
return v2;
}

original_code:
int PND_Pad_RecentlyPressed ( pnd_keytype_e num ) {
  static int GLES2D_Pad_old [ pke_pad_max ];
  if ( !GLES2D_Pad_old[num] && GLES2D_Pad[num] ) {
    GLES2D_Pad_old[num] = GLES2D_Pad[num];
    return 1;
  }
  GLES2D_Pad_old[num] = GLES2D_Pad[num];
  return 0;
}

canonical_original_code:
int PND_Pad_RecentlyPressed(enum pnd_keytype_e num) {
  static int GLES2D_Pad_old[-1];
  if ( !GLES2D_Pad_old[num] && GLES2D_Pad[num] ) {
    GLES2D_Pad_old[num] = GLES2D_Pad[num];
    return 1;
  }
  GLES2D_Pad_old[num] = GLES2D_Pad[num];
  return 0;
}

variable_types: enum pnd_keytype_e { pke_pad_up=0, pke_pad_down=1, pke_pad_left=2, pke_pad_right=3, pke_pad_menu=4, pke_pad_x=5, pke_pad_y=6, pke_pad_a=7, pke_pad_b=8, pke_pad_l=9, pke_pad_r=10, pke_pad_max=11 }

return_type: int


decompiled_code:
int *pnd_dbusnotify_init()
{
int *v0; // rax
int *v1; // rbx
__pid_t v2; // eax

v0 = (int *)malloc(0xCuLL);
v1 = v0;
if ( v0 )
{
*(_QWORD *)v0 = 0LL;
v0[2] = 0;
if ( pipe(v0 + 1) == -1 || (v2 = fork(), *v1 = v2, v2 == -1) )
{
free(v1);
v1 = 0LL;
}
else
{
if ( !v2 )
{
close(v1[1]);
dup2(v1[2], 1);
close(v1[2]);
execlp(
"/usr/bin/dbus-monitor",
"/usr/bin/dbus-monitor",
"--system",
"interface=org.freedesktop.Hal.Device",
0LL);
exit(1);
}
close(v1[2]);
}
}
return v1;
}

canonical_decompiled_code:
int *func7()
{
int *v0; // rax
int *v1; // rbx
__pid_t v2; // eax

v0 = (int *)malloc(0xCuLL);
v1 = v0;
if ( v0 )
{
*(_QWORD *)v0 = 0LL;
v0[2] = 0;
if ( pipe(v0 + 1) == -1 || (v2 = fork(), *v1 = v2, v2 == -1) )
{
free(v1);
v1 = 0LL;
}
else
{
if ( !v2 )
{
close(v1[1]);
dup2(v1[2], 1);
close(v1[2]);
execlp(
"/usr/bin/dbus-monitor",
"/usr/bin/dbus-monitor",
"--system",
"interface=org.freedesktop.Hal.Device",
0LL);
exit(1);
}
close(v1[2]);
}
}
return v1;
}

original_code:
pnd_dbusnotify_handle pnd_dbusnotify_init ( void ) {
  pnd_dbusnotify_t *p;
  p = malloc ( sizeof(pnd_dbusnotify_t) );
  if ( ! p ) {
    return ( ((void *)0) );
  }
  bzero ( p, sizeof(pnd_dbusnotify_t) );
  if ( pipe ( p -> fd ) == -1 ) {
    free ( p );
    return ( ((void *)0) );
  }
  p -> child_pid = fork();
  if ( p -> child_pid == -1 ) {
    free ( p );
    return ( ((void *)0) );
  } else if ( p -> child_pid == 0 ) {
    close ( p -> fd [ 0 ] );
    dup2 ( p -> fd [ 1 ], 1 );
    close ( p -> fd [ 1 ] );
    execlp ( "/usr/bin/dbus-monitor", "/usr/bin/dbus-monitor", "--system", "interface=org.freedesktop.Hal.Device", ((void *)0) );
    exit ( 1 );
  } else {
    close ( p -> fd [ 1 ] );
  }
  return ( p );
}

canonical_original_code:
void *pnd_dbusnotify_init() {
  struct pnd_dbusnotify_t *p;
  p = malloc ( sizeof(pnd_dbusnotify_t) );
  if ( ! p ) {
    return ( ((void *)0) );
  }
  bzero ( p, sizeof(pnd_dbusnotify_t) );
  if ( pipe ( p -> fd ) == -1 ) {
    free ( p );
    return ( ((void *)0) );
  }
  p -> child_pid = fork();
  if ( p -> child_pid == -1 ) {
    free ( p );
    return ( ((void *)0) );
  } else if ( p -> child_pid == 0 ) {
    close ( p -> fd [ 0 ] );
    dup2 ( p -> fd [ 1 ], 1 );
    close ( p -> fd [ 1 ] );
    execlp ( "/usr/bin/dbus-monitor", "/usr/bin/dbus-monitor", "--system", "interface=org.freedesktop.Hal.Device", ((void *)0) );
    exit ( 1 );
  } else {
    close ( p -> fd [ 1 ] );
  }
  return ( p );
}

variable_types: struct pnd_dbusnotify_t { int child_pid; int fd[2]; } *

return_type: void *


decompiled_code:
void __fastcall pnd_dbusnotify_shutdown(void *ptr)
{
close(*((_DWORD *)ptr + 1));
kill(*(_DWORD *)ptr, 9);
free(ptr);
}

canonical_decompiled_code:
void __fastcall func8(void *ptr)
{
close(*((_DWORD *)ptr + 1));
kill(*(_DWORD *)ptr, 9);
free(ptr);
}

original_code:
void pnd_dbusnotify_shutdown ( pnd_dbusnotify_handle h ) {
  pnd_dbusnotify_t *p = (pnd_dbusnotify_t*) h;
  close ( p -> fd [ 0 ] );
  kill ( p -> child_pid, 9 );
  free ( p );
  return;
}

canonical_original_code:
void pnd_dbusnotify_shutdown(void *h) {
  struct pnd_dbusnotify_t *p = (pnd_dbusnotify_t*) h;
  close ( p -> fd [ 0 ] );
  kill ( p -> child_pid, 9 );
  free ( p );
  return;
}

variable_types:
h
void *

user_defined_types: struct pnd_dbusnotify_t { int child_pid; int fd[2]; }


decompiled_code:
bool __fastcall pnd_dbusnotify_rediscover_p(__int64 a1)
{
int v1; // edx
bool result; // al
int v3; // edx
char v4[4104]; // [rsp+0h] [rbp-1018h] BYREF
struct pollfd fds; // [rsp+1008h] [rbp-10h] BYREF

fds.fd = *(_DWORD *)(a1 + 4);
fds.events = 3;
fds.revents = 0;
v1 = poll(&fds, 1uLL, 0);
result = 0;
if ( v1 > 0 && (fds.revents & 0x18) == 0 )
{
v3 = read(fds.fd, v4, 0xFA0uLL);
result = 0;
if ( v3 >= 0 )
{
v4[v3 + 1] = 0;
result = strstr(v4, "volume.is_mounted") != 0LL;
}
}
return result;
}

canonical_decompiled_code:
bool __fastcall func9(__int64 a1)
{
int v1; // edx
bool result; // al
int v3; // edx
char v4[4104]; // [rsp+0h] [rbp-1018h] BYREF
struct pollfd fds; // [rsp+1008h] [rbp-10h] BYREF

fds.fd = *(_DWORD *)(a1 + 4);
fds.events = 3;
fds.revents = 0;
v1 = poll(&fds, 1uLL, 0);
result = 0;
if ( v1 > 0 && (fds.revents & 0x18) == 0 )
{
v3 = read(fds.fd, v4, 0xFA0uLL);
result = 0;
if ( v3 >= 0 )
{
v4[v3 + 1] = 0;
result = strstr(v4, "volume.is_mounted") != 0LL;
}
}
return result;
}

original_code:
unsigned char pnd_dbusnotify_rediscover_p ( pnd_dbusnotify_handle h ) {
  pnd_dbusnotify_t *p = (pnd_dbusnotify_t*) h;
  int r;
  struct pollfd fds [ 1 ];
  fds [ 0 ].fd = p -> fd [ 0 ];
  fds [ 0 ].events = 0x001 | 0x002 ;
  fds [ 0 ].revents = 0;
  r = poll ( fds, 1, 0 );
  if ( r < 0 ) {
    return ( 0 );
  } else if ( r == 0 ) {
    return ( 0 );
  }
  if ( fds [ 0 ].revents & ( 0x008|0x010 ) ) {
    return ( 0 );
  }
  char buf [ 4096 ];
  int readcount;
  readcount = read ( fds [ 0 ].fd, buf, 4000 );
  if ( readcount < 0 ) {
    return ( 0 );
  }
  *( buf + readcount + 1 ) = '\0';
  if ( strstr ( buf, "volume.is_mounted" ) != ((void *)0) ) {
    return ( 1 );
  }
  return ( 0 );
}

canonical_original_code:
unsigned char pnd_dbusnotify_rediscover_p(void *h) {
  struct pnd_dbusnotify_t *p = (pnd_dbusnotify_t*) h;
  int r;
  struct pollfd fds[1];
  fds [ 0 ].fd = p -> fd [ 0 ];
  fds [ 0 ].events = 0x001 | 0x002 ;
  fds [ 0 ].revents = 0;
  r = poll ( fds, 1, 0 );
  if ( r < 0 ) {
    return ( 0 );
  } else if ( r == 0 ) {
    return ( 0 );
  }
  if ( fds [ 0 ].revents & ( 0x008|0x010 ) ) {
    return ( 0 );
  }
  char buf[4096];
  int readcount;
  readcount = read ( fds [ 0 ].fd, buf, 4000 );
  if ( readcount < 0 ) {
    return ( 0 );
  }
  *( buf + readcount + 1 ) = '\0';
  if ( strstr ( buf, "volume.is_mounted" ) != ((void *)0) ) {
    return ( 1 );
  }
  return ( 0 );
}

variable_types: r int

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

variable_types:
buf
char [4096]

variable_types: readcount int

return_type: unsigned char


decompiled_code:
int __fastcall pnd_exec_no_wait_1(char *arg, __int64 a2)
{
int result; // eax

result = fork();
if ( result < 0 )
return puts("ERROR: Couldn't fork()");
if ( !result )
{
if ( a2 )
execl(arg, arg, a2, 0LL);
else
execl(arg, arg, 0LL);
exit(-1);
}
return result;
}

canonical_decompiled_code:
int __fastcall func2(char *arg, __int64 a2)
{
int result; // eax

result = fork();
if ( result < 0 )
return puts("ERROR: Couldn't fork()");
if ( !result )
{
if ( a2 )
execl(arg, arg, a2, 0LL);
else
execl(arg, arg, 0LL);
exit(-1);
}
return result;
}

original_code:
void pnd_exec_no_wait_1 ( char *fullpath, char *arg1 ) {
  int i;
  if ( ( i = fork() ) < 0 ) {
    printf ( "ERROR: Couldn't fork()\n" );
    return;
  }
  if ( i ) {
    return;
  }
  if ( arg1 ) {
    execl ( fullpath, fullpath, arg1, (char*) ((void *)0) );
  } else {
    execl ( fullpath, fullpath, (char*) ((void *)0) );
  }
  exit ( -1 );
  return;
}

canonical_original_code:
void pnd_exec_no_wait_1(char *fullpath, char *arg1) {
  int i;
  if ( ( i = fork() ) < 0 ) {
    printf ( "ERROR: Couldn't fork()\n" );
    return;
  }
  if ( i ) {
    return;
  }
  if ( arg1 ) {
    execl ( fullpath, fullpath, arg1, (char *) ((void *)0) );
  } else {
    execl ( fullpath, fullpath, (char *) ((void *)0) );
  }
  exit ( -1 );
  return;
}

variable_types:
fullpath
char *

variable_types: i int


decompiled_code:
__time_t __fastcall pnd_is_locked(const char *a1)
{
int v1; // eax
__time_t result; // rax
struct stat v3; // [rsp+0h] [rbp-1098h] BYREF
char s[4104]; // [rsp+90h] [rbp-1008h] BYREF

snprintf(s, 0x1000uLL, "%s/%s", "/tmp", a1);
v1 = stat(s, &v3);
if ( v1 < 0 || v1 == 2 )
result = 0LL;
else
result = v3.st_mtim.tv_sec;
return result;
}

canonical_decompiled_code:
__time_t __fastcall func6(const char *a1)
{
int v1; // eax
__time_t result; // rax
struct stat v3; // [rsp+0h] [rbp-1098h] BYREF
char s[4104]; // [rsp+90h] [rbp-1008h] BYREF

snprintf(s, 0x1000uLL, "%s/%s", "/tmp", a1);
v1 = stat(s, &v3);
if ( v1 < 0 || v1 == 2 )
result = 0LL;
else
result = v3.st_mtim.tv_sec;
return result;
}

original_code:
time_t pnd_is_locked ( char *lockname ) {
  char fullpath [ 4096 ];
  int rv;
  snprintf ( fullpath, 4096, "%s/%s", "/tmp", lockname );
  struct stat statbuf;
  rv = stat ( fullpath, &statbuf );
  if ( rv == 2 ) {
    return ( 0 );
  } else if ( rv < 0 ) {
    return ( 0 );
  }
  return ( statbuf.st_mtim.tv_sec );
}

canonical_original_code:
long pnd_is_locked(char *lockname) {
  char fullpath[4096];
  int rv;
  snprintf ( fullpath, 4096, "%s/%s", "/tmp", lockname );
  struct stat statbuf;
  rv = stat ( fullpath, &statbuf );
  if ( rv == 2 ) {
    return ( 0 );
  } else if ( rv < 0 ) {
    return ( 0 );
  }
  return ( statbuf.st_mtim.tv_sec );
}

variable_types:
lockname
char *

variable_types:
fullpath
char [4096]

variable_types: rv int

variable_types: struct stat { unsigned long st_dev; unsigned long st_ino; unsigned long st_nlink; unsigned int st_mode; unsigned int st_uid; unsigned int st_gid; int __pad0; unsigned long st_rdev; long st_size; long st_blksize; long st_blocks; struct timespec { long tv_sec; long tv_nsec; } st_atim; struct timespec st_mtim; struct timespec st_ctim; long __glibc_reserved[3]; }

return_type: long

user_defined_types: struct stat { unsigned long st_dev; unsigned long st_ino; unsigned long st_nlink; unsigned int st_mode; unsigned int st_uid; unsigned int st_gid; int __pad0; unsigned long st_rdev; long st_size; long st_blksize; long st_blocks; struct timespec st_atim; struct timespec st_mtim; struct timespec st_ctim; long __glibc_reserved[3]; }


decompiled_code:
__int64 __fastcall pnd_lock(const char *a1)
{
__time_t v1; // rdx
__int64 result; // rax
int v3; // edx
char v4[4120]; // [rsp+0h] [rbp-1018h] BYREF

v1 = pnd_is_locked(a1);
result = 0LL;
if ( !v1 )
{
snprintf(v4, 0x1000uLL, "%s/%s", "/tmp", a1);
v3 = creat(v4, 0x124u);
result = 0LL;
if ( v3 >= 0 )
{
close(0);
result = 1LL;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func7(const char *a1)
{
__time_t v1; // rdx
__int64 result; // rax
int v3; // edx
char v4[4120]; // [rsp+0h] [rbp-1018h] BYREF

v1 = func6(a1);
result = 0LL;
if ( !v1 )
{
snprintf(v4, 0x1000uLL, "%s/%s", "/tmp", a1);
v3 = creat(v4, 0x124u);
result = 0LL;
if ( v3 >= 0 )
{
close(0);
result = 1LL;
}
}
return result;
}

original_code:
unsigned char pnd_lock ( char *lockname ) {
  if ( pnd_is_locked ( lockname ) ) {
    return ( 0 );
  }
  char fullpath [ 4096 ];
  int fd;
  snprintf ( fullpath, 4096, "%s/%s", "/tmp", lockname );
  if ( ( fd = creat ( fullpath, 0444 ) < 0 ) ) {
    return ( 0 );
  }
  close ( fd );
  return ( 1 );
}

canonical_original_code:
unsigned char pnd_lock(char *lockname) {
  if ( pnd_is_locked ( lockname ) ) {
    return ( 0 );
  }
  char fullpath[4096];
  int fd;
  snprintf ( fullpath, 4096, "%s/%s", "/tmp", lockname );
  if ( ( fd = creat ( fullpath, 0444 ) < 0 ) ) {
    return ( 0 );
  }
  close ( fd );
  return ( 1 );
}

variable_types: fd int


decompiled_code:
int __fastcall pnd_unlock(const char *a1)
{
char v2[4104]; // [rsp+0h] [rbp-1008h] BYREF

snprintf(v2, 0x1000uLL, "%s/%s", "/tmp", a1);
return unlink(v2);
}

canonical_decompiled_code:
int __fastcall func8(const char *a1)
{
char v2[4104]; // [rsp+0h] [rbp-1008h] BYREF

snprintf(v2, 0x1000uLL, "%s/%s", "/tmp", a1);
return unlink(v2);
}

original_code:
void pnd_unlock ( char *lockname ) {
  char fullpath [ 4096 ];
  snprintf ( fullpath, 4096, "%s/%s", "/tmp", lockname );
  unlink ( fullpath );
  return;
}

canonical_original_code:
void pnd_unlock(char *lockname) {
  char fullpath[4096];
  snprintf ( fullpath, 4096, "%s/%s", "/tmp", lockname );
  unlink ( fullpath );
  return;
}


decompiled_code:
__int64 __fastcall pnd_wait_for_unlock(const char *a1, __int16 a2, __useconds_t a3)
{
__time_t v4; // rdx
__int64 result; // rax
int v6; // ebx

v4 = pnd_is_locked(a1);
result = 1LL;
if ( v4 )
{
if ( a2 )
{
v6 = 0;
while ( pnd_is_locked(a1) )
{
usleep(a3);
if ( a2 == (_WORD)++v6 )
return 0LL;
}
result = 1LL;
}
else
{
result = 0LL;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func9(const char *a1, __int16 a2, __useconds_t a3)
{
__time_t v4; // rdx
__int64 result; // rax
int v6; // ebx

v4 = func6(a1);
result = 1LL;
if ( v4 )
{
if ( a2 )
{
v6 = 0;
while ( func6(a1) )
{
usleep(a3);
if ( a2 == (_WORD)++v6 )
return 0LL;
}
result = 1LL;
}
else
{
result = 0LL;
}
}
return result;
}

original_code:
unsigned char pnd_wait_for_unlock ( char *lockname, unsigned short int max, unsigned int usec_delta ) {
  if ( ! pnd_is_locked ( lockname ) ) {
    return ( 1 );
  }
  unsigned short int count = 0;
  while ( count < max ) {
    if ( ! pnd_is_locked ( lockname ) ) {
      return ( 1 );
    }
    usleep ( usec_delta );
    count++;
  }
  return ( 0 );
}

canonical_original_code:
unsigned char pnd_wait_for_unlock(char *lockname, unsigned short max, unsigned int usec_delta) {
  if ( ! pnd_is_locked ( lockname ) ) {
    return ( 1 );
  }
  unsigned short count = 0;
  while ( count < max ) {
    if ( ! pnd_is_locked ( lockname ) ) {
      return ( 1 );
    }
    usleep ( usec_delta );
    count++;
  }
  return ( 0 );
}

variable_types:
max
unsigned short

variable_types:
count
unsigned short


decompiled_code:
void __fastcall pnd_box_delete(void *ptr)
{
__int64 v1; // rbx
__int64 v2; // rbp

v1 = *((_QWORD *)ptr + 1);
if ( v1 )
{
while ( 1 )
{
if ( *(_QWORD *)v1 )
free(*(void **)v1);
v2 = *(_QWORD *)(v1 + 8);
free((void *)v1);
if ( !v2 )
break;
v1 = v2;
}
}
if ( *(_QWORD *)ptr )
free(*(void **)ptr);
free(ptr);
}

canonical_decompiled_code:
void __fastcall func0(void *ptr)
{
__int64 v1; // rbx
__int64 v2; // rbp

v1 = *((_QWORD *)ptr + 1);
if ( v1 )
{
while ( 1 )
{
if ( *(_QWORD *)v1 )
free(*(void **)v1);
v2 = *(_QWORD *)(v1 + 8);
free((void *)v1);
if ( !v2 )
break;
v1 = v2;
}
}
if ( *(_QWORD *)ptr )
free(*(void **)ptr);
free(ptr);
}

original_code:
void pnd_box_delete ( pnd_box_handle box ) {
  pnd_box_t *p = (pnd_box_t*) box;
  pnd_box_node_t *n, *next;
  n = p -> head;
  while ( n ) {
    if ( n -> key ) {
      free ( n -> key );
    }
    next = n -> next;
    free ( n );
    n = next;
  }
  if ( p -> name ) {
    free ( p -> name );
  }
  p -> head = (void*)123;
  free ( p );
  return;
}

canonical_original_code:
void pnd_box_delete(void *box) {
  struct pnd_box_t *p = (pnd_box_t*) box;
  struct _pnd_box_node_t *n; struct _pnd_box_node_t *next;
  n = p -> head;
  while ( n ) {
    if ( n -> key ) {
      free ( n -> key );
    }
    next = n -> next;
    free ( n );
    n = next;
  }
  if ( p -> name ) {
    free ( p -> name );
  }
  p -> head = (void *)123;
  free ( p );
  return;
}

variable_types:
box
void *

variable_types: struct pnd_box_t { char *name; struct _pnd_box_node_t { char *key; struct _pnd_box_node_t *next; } *head; } *

user_defined_types: struct pnd_box_t { char *name; struct _pnd_box_node_t *head; }


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

v2 = *(_QWORD *)(a1 + 8);
if ( v2 )
{
while ( strcasecmp(*(const char **)v2, a2) )
{
v2 = *(_QWORD *)(v2 + 8);
if ( !v2 )
return v2;
}
v2 += 16LL;
}
return v2;
}

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

v2 = *(_QWORD *)(a1 + 8);
if ( v2 )
{
while ( strcasecmp(*(const char **)v2, a2) )
{
v2 = *(_QWORD *)(v2 + 8);
if ( !v2 )
return v2;
}
v2 += 16LL;
}
return v2;
}

original_code:
void *pnd_box_find_by_key ( pnd_box_handle box, char *key ) {
  pnd_box_t *p = (pnd_box_t*) box;
  pnd_box_node_t *n;
  n = p -> head;
  while ( n ) {
    if ( strcasecmp ( n -> key, key ) == 0 ) {
      return ( ( ((unsigned char *)(n)) + sizeof(pnd_box_node_t) ) );
    }
    n = n -> next;
  }
  return ( ((void *)0) );
}

canonical_original_code:
void *pnd_box_find_by_key(void *box, char *key) {
  struct pnd_box_t *p = (pnd_box_t*) box;
  struct _pnd_box_node_t *n;
  n = p -> head;
  while ( n ) {
    if ( strcasecmp ( n -> key, key ) == 0 ) {
      return ( ( ((unsigned char *)(n)) + sizeof(pnd_box_node_t) ) );
    }
    n = n -> next;
  }
  return ( ((void *)0) );
}

variable_types:
key
char *

variable_types: struct _pnd_box_node_t { char *key; struct _pnd_box_node_t *next; } *


decompiled_code:
__int64 __fastcall pnd_box_get_name(__int64 a1)
{
return *(_QWORD *)a1;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1)
{
return *(_QWORD *)a1;
}

original_code:
char *pnd_box_get_name ( pnd_box_handle box ) {
  pnd_box_t *p = (pnd_box_t*) box;
  return ( p -> name );
}

canonical_original_code:
char *pnd_box_get_name(void *box) {
  struct pnd_box_t *p = (pnd_box_t*) box;
  return ( p -> name );
}

return_type: char *

user_defined_types: struct _pnd_box_node_t { char *key; struct _pnd_box_node_t *next; }


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

if ( !a1 )
return 0LL;
result = *(_QWORD *)(a1 + 8);
if ( result )
result += 16LL;
return result;
}

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

if ( !a1 )
return 0LL;
result = *(_QWORD *)(a1 + 8);
if ( result )
result += 16LL;
return result;
}

original_code:
void *pnd_box_get_head ( pnd_box_handle box ) {
  pnd_box_t *p = (pnd_box_t*) box;
  if ( ! p ) {
    return ( ((void *)0) );
  }
  if ( ! p -> head ) {
    return ( ((void *)0) );
  }
  return ( ( ((unsigned char *)(p -> head)) + sizeof(pnd_box_node_t) ) );
}

canonical_original_code:
void *pnd_box_get_head(void *box) {
  struct pnd_box_t *p = (pnd_box_t*) box;
  if ( ! p ) {
    return ( ((void *)0) );
  }
  if ( ! p -> head ) {
    return ( ((void *)0) );
  }
  return ( ( ((unsigned char *)(p -> head)) + sizeof(pnd_box_node_t) ) );
}


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

result = *(_QWORD *)(a1 - 8);
if ( result )
result += 16LL;
return result;
}

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

result = *(_QWORD *)(a1 - 8);
if ( result )
result += 16LL;
return result;
}

original_code:
void *pnd_box_get_next ( void *node ) {
  pnd_box_node_t *p = ((pnd_box_node_t*)( ((unsigned char *)(node)) - sizeof(pnd_box_node_t) ));
  p = p -> next;
  if ( ! p ) {
    return ( ((void *)0) );
  }
  return ( ( ((unsigned char *)(p)) + sizeof(pnd_box_node_t) ) );
}

canonical_original_code:
void *pnd_box_get_next(void *node) {
  struct _pnd_box_node_t *p = ((pnd_box_node_t*)( ((unsigned char *)(node)) - sizeof(pnd_box_node_t) ));
  p = p -> next;
  if ( ! p ) {
    return ( ((void *)0) );
  }
  return ( ( ((unsigned char *)(p)) + sizeof(pnd_box_node_t) ) );
}

variable_types:
node
void *


decompiled_code:
__int64 __fastcall pnd_box_get_key(__int64 a1)
{
return *(_QWORD *)(a1 - 16);
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1)
{
return *(_QWORD *)(a1 - 16);
}

original_code:
char *pnd_box_get_key ( void *node ) {
  pnd_box_node_t *p = ((pnd_box_node_t*)( ((unsigned char *)(node)) - sizeof(pnd_box_node_t) ));
  return ( p -> key );
}

canonical_original_code:
char *pnd_box_get_key(void *node) {
  struct _pnd_box_node_t *p = ((pnd_box_node_t*)( ((unsigned char *)(node)) - sizeof(pnd_box_node_t) ));
  return ( p -> key );
}


decompiled_code:
__int64 __fastcall pnd_box_get_size(__int64 a1)
{
__int64 v1; // rax
unsigned int v2; // edx

if ( !a1 )
return 0;
v1 = *(_QWORD *)(a1 + 8);
if ( !v1 )
return 0;
v2 = 0;
do
{
++v2;
v1 = *(_QWORD *)(v1 + 8);
}
while ( v1 );
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1)
{
__int64 v1; // rax
unsigned int v2; // edx

if ( !a1 )
return 0;
v1 = *(_QWORD *)(a1 + 8);
if ( !v1 )
return 0;
v2 = 0;
do
{
++v2;
v1 = *(_QWORD *)(v1 + 8);
}
while ( v1 );
return v2;
}

original_code:
unsigned int pnd_box_get_size ( pnd_box_handle box ) {
  pnd_box_t *p = (pnd_box_t*) box;
  pnd_box_node_t *n;
  unsigned int count = 0;
  if ( ! p ) {
    return ( 0 );
  }
  n = p -> head;
  while ( n ) {
    count++;
    n = n -> next;
  }
  return ( count );
}

canonical_original_code:
unsigned int pnd_box_get_size(void *box) {
  struct pnd_box_t *p = (pnd_box_t*) box;
  struct _pnd_box_node_t *n;
  unsigned int count = 0;
  if ( ! p ) {
    return ( 0 );
  }
  n = p -> head;
  while ( n ) {
    count++;
    n = n -> next;
  }
  return ( count );
}

variable_types:
count
unsigned int

return_type: unsigned int


original_code:
unsigned char pnd_box_append ( pnd_box_handle box, pnd_box_handle append ) {
  pnd_box_t *pbox = (pnd_box_t*) box;
  pnd_box_t *pappend = (pnd_box_t*) append;
  if ( pbox -> head ) {
    pnd_box_node_t *n = pbox -> head;
    while ( n -> next ) {
      n = n -> next;
    }
    n -> next = pappend -> head;
  } else {
    pbox -> head = pappend -> head;
  }
  return ( 1 );
}

canonical_original_code:
unsigned char pnd_box_append(void *box, void *append) {
  struct pnd_box_t *pbox = (pnd_box_t*) box;
  struct pnd_box_t *pappend = (pnd_box_t*) append;
  if ( pbox -> head ) {
    struct _pnd_box_node_t *n = pbox -> head;
    while ( n -> next ) {
      n = n -> next;
    }
    n -> next = pappend -> head;
  } else {
    pbox -> head = pappend -> head;
  }
  return ( 1 );
}

variable_types:
append
void *


original_code:
void pnd_box_delete_node ( pnd_box_handle box, void *value ) {
  pnd_box_t *pbox = (pnd_box_t*) box;
  pnd_box_node_t *p = ((pnd_box_node_t*)( ((unsigned char *)(value)) - sizeof(pnd_box_node_t) ));
  if ( pbox -> head == p ) {
    pbox -> head = p -> next;
    free ( p );
  } else {
    pnd_box_node_t *i = pbox -> head;
    while ( i && i -> next != p ) {
      i = i -> next;
    }
    if ( i -> next == p ) {
      i -> next = p -> next;
      free ( p );
    }
  }
  return;
}

canonical_original_code:
void pnd_box_delete_node(void *box, void *value) {
  struct pnd_box_t *pbox = (pnd_box_t*) box;
  struct _pnd_box_node_t *p = ((pnd_box_node_t*)( ((unsigned char *)(value)) - sizeof(pnd_box_node_t) ));
  if ( pbox -> head == p ) {
    pbox -> head = p -> next;
    free ( p );
  } else {
    struct _pnd_box_node_t *i = pbox -> head;
    while ( i && i -> next != p ) {
      i = i -> next;
    }
    if ( i -> next == p ) {
      i -> next = p -> next;
      free ( p );
    }
  }
  return;
}

variable_types:
value
void *


decompiled_code:
char **__fastcall freedesktop_category_query(char *s2, char *a2)
{
const char *v3; // rdi
char **v4; // rbx
const char *v5; // rdi

v3 = freedesktop_complete;
if ( freedesktop_complete )
{
v4 = &freedesktop_complete;
do
{
if ( !strcasecmp(v3, s2) )
{
if ( a2 )
{
v5 = v4[1];
if ( v5 && !strcasecmp(v5, a2) )
return v4;
}
else if ( !v4[1] )
{
return v4;
}
}
v4 += 3;
v3 = *v4;
}
while ( *v4 );
}
return (char **)v3;
}

canonical_decompiled_code:
char **__fastcall func0(char *s2, char *a2)
{
const char *v3; // rdi
char **v4; // rbx
const char *v5; // rdi

v3 = freedesktop_complete;
if ( freedesktop_complete )
{
v4 = &freedesktop_complete;
do
{
if ( !strcasecmp(v3, s2) )
{
if ( a2 )
{
v5 = v4[1];
if ( v5 && !strcasecmp(v5, a2) )
return v4;
}
else if ( !v4[1] )
{
return v4;
}
}
v4 += 3;
v3 = *v4;
}
while ( *v4 );
}
return (char **)v3;
}

original_code:
freedesktop_cat_t *freedesktop_category_query ( char *name, char *parentcatname ) {
  freedesktop_cat_t *p = freedesktop_complete;
  while ( p -> cat ) {
    if ( strcasecmp ( p -> cat, name ) == 0 ) {
      if ( parentcatname == ((void *)0) && p -> parent_cat == ((void *)0) ) {
 return ( p );
      } else if ( parentcatname && p -> parent_cat && strcasecmp ( p -> parent_cat, parentcatname ) == 0 ) {
 return ( p );
      }
    }
    p++;
  }
  return ( ((void *)0) );
}

canonical_original_code:
struct freedesktop_cat_t *freedesktop_category_query(char *name, char *parentcatname) {
  struct freedesktop_cat_t *p = freedesktop_complete;
  while ( p -> cat ) {
    if ( strcasecmp ( p -> cat, name ) == 0 ) {
      if ( parentcatname == ((void *)0) && p -> parent_cat == ((void *)0) ) {
 return ( p );
      } else if ( parentcatname && p -> parent_cat && strcasecmp ( p -> parent_cat, parentcatname ) == 0 ) {
 return ( p );
      }
    }
    p++;
  }
  return ( ((void *)0) );
}

variable_types:
name
char *

variable_types:
parentcatname
char *

variable_types: struct freedesktop_cat_t { char *cat; char *parent_cat; char *desc; } *


decompiled_code:
__int64 freedesktop_count()
{
char **v0; // rax
unsigned int v1; // edx

if ( !freedesktop_complete )
return 0;
v0 = &freedesktop_complete + 3;
v1 = 0;
do
{
++v1;
v0 += 3;
}
while ( *(v0 - 3) );
return v1;
}

canonical_decompiled_code:
__int64 func1()
{
char **v0; // rax
unsigned int v1; // edx

if ( !freedesktop_complete )
return 0;
v0 = &freedesktop_complete + 3;
v1 = 0;
do
{
++v1;
v0 += 3;
}
while ( *(v0 - 3) );
return v1;
}

original_code:
unsigned int freedesktop_count ( void ) {
  unsigned int i = 0;
  while ( freedesktop_complete [ i ].cat ) {
    i++;
  }
  return ( i );
}

canonical_original_code:
unsigned int freedesktop_count() {
  unsigned int i = 0;
  while ( freedesktop_complete [ i ].cat ) {
    i++;
  }
  return ( i );
}

variable_types:
i
unsigned int


decompiled_code:
__int64 __fastcall pnd_conf_fetch_by_name(const char *a1, const char *a2)
{
char *v3; // r12
char v4; // r13
char *v5; // rbx
char **v6; // r14
__int64 v7; // rbx
__int64 v9; // [rsp+0h] [rbp-20F8h]
wordexp_t pwordexp; // [rsp+10h] [rbp-20E8h] BYREF
struct stat v11; // [rsp+30h] [rbp-20C8h] BYREF
char file[4096]; // [rsp+C0h] [rbp-2038h] BYREF
char dest[4152]; // [rsp+10C0h] [rbp-1038h] BYREF

while ( 1 )
{
v3 = strchr(a2, 58);
v4 = (v3 != 0LL) & (v3 < &a2[strlen(a2)]);
if ( v4 )
{
memset(dest, 0, 0x1000uLL);
strncpy(dest, a2, v3 - a2);
}
else
{
strncpy(dest, a2, 0xFFFuLL);
}
pathiter_depthlimit = 0xFFFF;
v5 = strchr(dest, 60);
if ( v5 )
{
if ( ((*_ctype_b_loc())[v5[1]] & 0x800) != 0 )
pathiter_depthlimit = atoi(v5 + 1);
*v5 = 0;
}
if ( !wordexp(dest, &pwordexp, 0) )
break;
LABEL_5:
if ( !v4 )
return 0LL;
a2 = v3 + 1;
}
v6 = pwordexp.we_wordv;
if ( !pwordexp.we_wordc )
{
LABEL_19:
wordfree(&pwordexp);
goto LABEL_5;
}
v7 = 0LL;
while ( 1 )
{
strcpy(file, v6[v7]);
if ( !stat(file, &v11) && (v11.st_mode & 0xF000) == 0x4000 )
{
*(_WORD *)&file[strlen(file)] = 47;
strncat(file, a1, 0xFFFuLL);
v9 = pnd_conf_fetch_by_path(file);
if ( v9 )
break;
}
if ( pwordexp.we_wordc <= ++v7 )
goto LABEL_19;
}
wordfree(&pwordexp);
return v9;
}

canonical_decompiled_code:
__int64 __fastcall func1(const char *a1, const char *a2)
{
char *v3; // r12
char v4; // r13
char *v5; // rbx
char **v6; // r14
__int64 v7; // rbx
__int64 v9; // [rsp+0h] [rbp-20F8h]
wordexp_t pwordexp; // [rsp+10h] [rbp-20E8h] BYREF
struct stat v11; // [rsp+30h] [rbp-20C8h] BYREF
char file[4096]; // [rsp+C0h] [rbp-2038h] BYREF
char dest[4152]; // [rsp+10C0h] [rbp-1038h] BYREF

while ( 1 )
{
v3 = strchr(a2, 58);
v4 = (v3 != 0LL) & (v3 < &a2[strlen(a2)]);
if ( v4 )
{
memset(dest, 0, 0x1000uLL);
strncpy(dest, a2, v3 - a2);
}
else
{
strncpy(dest, a2, 0xFFFuLL);
}
pathiter_depthlimit = 0xFFFF;
v5 = strchr(dest, 60);
if ( v5 )
{
if ( ((*_ctype_b_loc())[v5[1]] & 0x800) != 0 )
pathiter_depthlimit = atoi(v5 + 1);
*v5 = 0;
}
if ( !wordexp(dest, &pwordexp, 0) )
break;
LABEL_5:
if ( !v4 )
return 0LL;
a2 = v3 + 1;
}
v6 = pwordexp.we_wordv;
if ( !pwordexp.we_wordc )
{
LABEL_19:
wordfree(&pwordexp);
goto LABEL_5;
}
v7 = 0LL;
while ( 1 )
{
strcpy(file, v6[v7]);
if ( !stat(file, &v11) && (v11.st_mode & 0xF000) == 0x4000 )
{
*(_WORD *)&file[strlen(file)] = 47;
strncat(file, a1, 0xFFFuLL);
v9 = func0(file);
if ( v9 )
break;
}
if ( pwordexp.we_wordc <= ++v7 )
goto LABEL_19;
}
wordfree(&pwordexp);
return v9;
}

original_code:
pnd_conf_handle pnd_conf_fetch_by_name ( char *filename, char *searchpath ) {
  pnd_conf_handle conf;
  char *end, *colon; char *head = searchpath; char chunk [ 4096 ]; char *lt; while ( 1 ) { colon = strchr ( head, ':' ); end = strchr ( head, '\0' ); if ( colon && colon < end ) { memset ( chunk, '\0', 4096 ); strncpy ( chunk, head, colon - head ); } else { strncpy ( chunk, head, 4096 - 1 ); } pathiter_depthlimit = 0xFFFF; if ( ( lt = strchr ( chunk, '<' ) ) ) { if ( ((*__ctype_b_loc ())[(int) ((*(lt+1)))] & (unsigned short int) _ISdigit) ) { pathiter_depthlimit = atoi ( lt + 1 ); } *lt = '\0'; } struct stat statbuf; wordexp_t _p; char **_w; int _i; char buffer [ 4096 ]; if ( wordexp ( chunk, &_p, 0 ) != 0 ) { } else { _w = _p.we_wordv; for ( _i=0; _i < _p.we_wordc; _i++ ) { strcpy ( buffer, _w [ _i ] ); if ( ( stat ( buffer, &statbuf ) == 0 ) && ( ((((statbuf.st_mode)) & 0170000) == (0040000)) ) ) {
  {
    strncat ( buffer, "/", 4096 - 1 );
    strncat ( buffer, filename, 4096 - 1 );
    conf = pnd_conf_fetch_by_path ( buffer );
    if ( conf ) {
      wordfree ( &_p );
      return ( conf );
    }
  }
  } } wordfree ( &_p ); } if ( colon && colon < end ) { head = colon + 1; } else { break; } }
  return ( ((void *)0) );
}

canonical_original_code:
void *pnd_conf_fetch_by_name(char *filename, char *searchpath) {
  void *conf;
  char *end; char *colon; char *head = searchpath; char chunk[4096]; char *lt; while ( 1 ) { colon = strchr ( head, ':' ); end = strchr ( head, '\0' ); if ( colon && colon < end ) { memset ( chunk, '\0', 4096 ); strncpy ( chunk, head, colon - head ); } else { strncpy ( chunk, head, 4096 - 1 ); } pathiter_depthlimit = 0xFFFF; if ( ( lt = strchr ( chunk, '<' ) ) ) { if ( ((*__ctype_b_loc ())[(int) ((*(lt+1)))] & (unsigned short) _ISdigit) ) { pathiter_depthlimit = atoi ( lt + 1 ); } *lt = '\0'; } struct stat statbuf; struct wordexp_t _p; char **_w; int _i; char buffer[4096]; if ( wordexp ( chunk, &_p, 0 ) != 0 ) { } else { _w = _p.we_wordv; for ( _i=0; _i < _p.we_wordc; _i++ ) { strcpy ( buffer, _w [ _i ] ); if ( ( stat ( buffer, &statbuf ) == 0 ) && ( ((((statbuf.st_mode)) & 0170000) == (0040000)) ) ) {
  {
    strncat ( buffer, "/", 4096 - 1 );
    strncat ( buffer, filename, 4096 - 1 );
    conf = pnd_conf_fetch_by_path ( buffer );
    if ( conf ) {
      wordfree ( &_p );
      return ( conf );
    }
  }
  } } wordfree ( &_p ); } if ( colon && colon < end ) { head = colon + 1; } else { break; } }
  return ( ((void *)0) );
}

variable_types:
filename
char *

variable_types:
searchpath
char *

variable_types:
conf
void *

variable_types:
end
char *

variable_types:
colon
char *

variable_types:
head
char *

variable_types:
chunk
char [4096]

variable_types:
lt
char *

variable_types: struct wordexp_t { unsigned long we_wordc; char **we_wordv; unsigned long we_offs; }

variable_types:
buffer
char [4096]

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


decompiled_code:
__int64 __fastcall pnd_conf_fetch_by_id(int a1, const char *a2)
{
char *v3; // rax
const char *v4; // rdi

v3 = (char *)&pnd_conf_filenames;
v4 = (const char *)*((_QWORD *)&pnd_conf_filenames + 1);
if ( !v4 )
return (__int64)v4;
while ( *(_DWORD *)v3 != a1 )
{
v3 += 16;
v4 = (const char *)*((_QWORD *)v3 + 1);
if ( !v4 )
return (__int64)v4;
}
return pnd_conf_fetch_by_name(v4, a2);
}

canonical_decompiled_code:
__int64 __fastcall func2(int a1, const char *a2)
{
char *v3; // rax
const char *v4; // rdi

v3 = (char *)&pnd_conf_filenames;
v4 = (const char *)*((_QWORD *)&pnd_conf_filenames + 1);
if ( !v4 )
return (__int64)v4;
while ( *(_DWORD *)v3 != a1 )
{
v3 += 16;
v4 = (const char *)*((_QWORD *)v3 + 1);
if ( !v4 )
return (__int64)v4;
}
return func1(v4, a2);
}

original_code:
pnd_conf_handle pnd_conf_fetch_by_id ( pnd_conf_filename_e id, char *searchpath ) {
  pnd_conf_filename_t *p = pnd_conf_filenames;
  while ( p -> filename ) {
    if ( p -> id == id ) {
      return ( pnd_conf_fetch_by_name ( p -> filename, searchpath ) );
    }
    p++;
  }
  return ( ((void *)0) );
}

canonical_original_code:
void *pnd_conf_fetch_by_id(enum pnd_conf_filename_e id, char *searchpath) {
  struct pnd_conf_filename_t *p = pnd_conf_filenames;
  while ( p -> filename ) {
    if ( p -> id == id ) {
      return ( pnd_conf_fetch_by_name ( p -> filename, searchpath ) );
    }
    p++;
  }
  return ( ((void *)0) );
}

variable_types: struct pnd_conf_filename_t { enum pnd_conf_filename_e { pnd_conf_nil=0, pnd_conf_conf=1, pnd_conf_apps=2, pnd_conf_startup=3, pnd_conf_desktop=4, pnd_conf_categories=5, pnd_conf_evmap=6 } id; char *filename; } *

user_defined_types: struct pnd_conf_filename_t { enum pnd_conf_filename_e id; char *filename; }


decompiled_code:
__int64 pnd_conf_get_as_char()
{
return pnd_box_find_by_key();
}

canonical_decompiled_code:
__int64 func3()
{
return pnd_box_find_by_key();
}

original_code:
char *pnd_conf_get_as_char ( pnd_conf_handle c, char *key ) {
  return ( pnd_box_find_by_key ( c, key ) );
}

canonical_original_code:
char *pnd_conf_get_as_char(void *c, char *key) {
  return ( pnd_box_find_by_key ( c, key ) );
}

variable_types:
c
void *

variable_types:
key
char *


decompiled_code:
char *pnd_conf_query_searchpath()
{
__int64 v0; // rax
const char *v1; // rdi
char *result; // rax

v0 = pnd_conf_fetch_by_id(1, "/media/*/pandora/conf:/etc/pandora/conf:./testdata/conf");
if ( v0 && (v1 = (const char *)pnd_conf_get_as_char(v0, "conf.searchpath")) != 0LL )
result = strdup(v1);
else
result = strdup("/media/*/pandora/conf:/etc/pandora/conf:./testdata/conf");
return result;
}

canonical_decompiled_code:
char *func4()
{
__int64 v0; // rax
const char *v1; // rdi
char *result; // rax

v0 = func2(1, "/media/*/pandora/conf:/etc/pandora/conf:./testdata/conf");
if ( v0 && (v1 = (const char *)func3(v0, "conf.searchpath")) != 0LL )
result = strdup(v1);
else
result = strdup("/media/*/pandora/conf:/etc/pandora/conf:./testdata/conf");
return result;
}

original_code:
char *pnd_conf_query_searchpath ( void ) {
  pnd_conf_handle ch;
  ch = pnd_conf_fetch_by_id ( pnd_conf_conf, "/media/*/pandora/conf:/etc/pandora/conf:./testdata/conf" );
  if ( ! ch ) {
    return ( strdup ( "/media/*/pandora/conf:/etc/pandora/conf:./testdata/conf" ) );
  }
  char *searchpath;
  char *temp;
  temp = pnd_conf_get_as_char ( ch, "conf.searchpath" );
  if ( temp ) {
    searchpath = strdup ( temp );
  } else {
    searchpath = strdup ( "/media/*/pandora/conf:/etc/pandora/conf:./testdata/conf" );
  }
  return ( searchpath );
}

canonical_original_code:
char *pnd_conf_query_searchpath() {
  void *ch;
  ch = pnd_conf_fetch_by_id ( pnd_conf_conf, "/media/*/pandora/conf:/etc/pandora/conf:./testdata/conf" );
  if ( ! ch ) {
    return ( strdup ( "/media/*/pandora/conf:/etc/pandora/conf:./testdata/conf" ) );
  }
  char *searchpath;
  char *temp;
  temp = pnd_conf_get_as_char ( ch, "conf.searchpath" );
  if ( temp ) {
    searchpath = strdup ( temp );
  } else {
    searchpath = strdup ( "/media/*/pandora/conf:/etc/pandora/conf:./testdata/conf" );
  }
  return ( searchpath );
}

variable_types:
ch
void *

variable_types:
temp
char *


decompiled_code:
int pnd_conf_get_as_int()
{
const char *v0; // rax
int result; // eax

v0 = (const char *)pnd_box_find_by_key();
if ( v0 )
result = atoi(v0);
else
result = -31337;
return result;
}

canonical_decompiled_code:
int func5()
{
const char *v0; // rax
int result; // eax

v0 = (const char *)pnd_box_find_by_key();
if ( v0 )
result = atoi(v0);
else
result = -31337;
return result;
}

original_code:
int pnd_conf_get_as_int ( pnd_conf_handle c, char *key ) {
  char *t = pnd_box_find_by_key ( c, key );
  if ( ! t ) {
    return ( (-31337) );
  }
  int i = atoi ( t );
  return ( i );
}

canonical_original_code:
int pnd_conf_get_as_int(void *c, char *key) {
  char *t = pnd_box_find_by_key ( c, key );
  if ( ! t ) {
    return ( (-31337) );
  }
  int i = atoi ( t );
  return ( i );
}

variable_types:
t
char *

variable_types: i int


decompiled_code:
int __fastcall pnd_conf_get_as_int_d(__int64 a1, __int64 a2, int a3)
{
const char *v4; // rax
int result; // eax

v4 = (const char *)pnd_box_find_by_key();
if ( v4 )
result = atoi(v4);
else
result = a3;
return result;
}

canonical_decompiled_code:
int __fastcall func6(__int64 a1, __int64 a2, int a3)
{
const char *v4; // rax
int result; // eax

v4 = (const char *)pnd_box_find_by_key();
if ( v4 )
result = atoi(v4);
else
result = a3;
return result;
}

original_code:
int pnd_conf_get_as_int_d ( pnd_conf_handle c, char *key, int def ) {
  char *t = pnd_box_find_by_key ( c, key );
  if ( ! t ) {
    return ( def );
  }
  int i = atoi ( t );
  return ( i );
}

canonical_original_code:
int pnd_conf_get_as_int_d(void *c, char *key, int def) {
  char *t = pnd_box_find_by_key ( c, key );
  if ( ! t ) {
    return ( def );
  }
  int i = atoi ( t );
  return ( i );
}

variable_types: def int


decompiled_code:
char *__fastcall pnd_conf_set_char(__int64 a1, __int64 a2, const char *a3)
{
__int64 v4; // rax
int v5; // eax
char *v6; // rax
char *v7; // rbx

v4 = pnd_box_find_by_key();
if ( v4 )
pnd_box_delete_node(a1, v4);
v5 = strlen(a3);
v6 = (char *)pnd_box_allocinsert(a1, a2, (unsigned int)(v5 + 1));
v7 = v6;
if ( v6 )
strcpy(v6, a3);
return v7;
}

canonical_decompiled_code:
char *__fastcall func7(__int64 a1, __int64 a2, const char *a3)
{
__int64 v4; // rax
int v5; // eax
char *v6; // rax
char *v7; // rbx

v4 = pnd_box_find_by_key();
if ( v4 )
pnd_box_delete_node(a1, v4);
v5 = strlen(a3);
v6 = (char *)pnd_box_allocinsert(a1, a2, (unsigned int)(v5 + 1));
v7 = v6;
if ( v6 )
strcpy(v6, a3);
return v7;
}

original_code:
char *pnd_conf_set_char ( pnd_conf_handle c, char *key, char *v ) {
  char *kv = pnd_box_find_by_key ( c, key );
  if ( kv ) {
    pnd_box_delete_node ( c, kv );
  }
  char *nv = pnd_box_allocinsert ( c, key, strlen ( v ) + 1 );
  if ( nv ) {
    strcpy ( nv, v );
    return ( nv );
  }
  return ( ((void *)0) );
}

canonical_original_code:
char *pnd_conf_set_char(void *c, char *key, char *v) {
  char *kv = pnd_box_find_by_key ( c, key );
  if ( kv ) {
    pnd_box_delete_node ( c, kv );
  }
  char *nv = pnd_box_allocinsert ( c, key, strlen ( v ) + 1 );
  if ( nv ) {
    strcpy ( nv, v );
    return ( nv );
  }
  return ( ((void *)0) );
}

variable_types:
v
char *

variable_types:
kv
char *

variable_types:
nv
char *


decompiled_code:
__int64 __fastcall pnd_pnd_mountie(char *path, char *a2, char *a3, char a4)
{
__int64 result; // rax
char *v5; // rax
__pid_t v6; // ebp
int stat_loc; // [rsp+0h] [rbp-BCh] BYREF
char *argv[6]; // [rsp+4h] [rbp-B8h] BYREF
char v9[112]; // [rsp+34h] [rbp-88h] BYREF

if ( a3 == 0LL || a2 == 0LL )
return 0LL;
result = 0LL;
if ( path )
{
memset(v9, 0, sizeof(v9));
argv[0] = path;
argv[1] = (char *)&LC2;
argv[2] = a2;
argv[3] = (char *)&LC3;
argv[4] = a3;
v5 = (char *)&LC0;
if ( !a4 )
v5 = (char *)&LC1;
argv[5] = v5;
v6 = fork();
if ( !v6 )
execv(path, argv);
stat_loc = 0;
waitpid(v6, &stat_loc, 0);
result = 1LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(char *path, char *a2, char *a3, char a4)
{
__int64 result; // rax
char *v5; // rax
__pid_t v6; // ebp
int stat_loc; // [rsp+0h] [rbp-BCh] BYREF
char *argv[6]; // [rsp+4h] [rbp-B8h] BYREF
char v9[112]; // [rsp+34h] [rbp-88h] BYREF

if ( a3 == 0LL || a2 == 0LL )
return 0LL;
result = 0LL;
if ( path )
{
memset(v9, 0, sizeof(v9));
argv[0] = path;
argv[1] = (char *)&LC2;
argv[2] = a2;
argv[3] = (char *)&LC3;
argv[4] = a3;
v5 = (char *)&LC0;
if ( !a4 )
v5 = (char *)&LC1;
argv[5] = v5;
v6 = fork();
if ( !v6 )
execv(path, argv);
stat_loc = 0;
waitpid(v6, &stat_loc, 0);
result = 1LL;
}
return result;
}

original_code:
static unsigned char pnd_pnd_mountie ( char *pndrun, char *fullpath, char *unique_id, unsigned char do_mount ) {
  char *argv [ 20 ];
  int f;
  if ( ! pndrun ) {
    return ( 0 );
  }
  if ( ! fullpath ) {
    return ( 0 );
  }
  if ( ! unique_id ) {
    return ( 0 );
  }
  memset ( argv, '\0', sizeof(char*) * 20 );
  f = 0;
  argv [ f++ ] = pndrun;
  argv [ f++ ] = "-p";
  argv [ f++ ] = fullpath;
  argv [ f++ ] = "-b";
  argv [ f++ ] = unique_id;
  if ( do_mount ) {
    argv [ f++ ] = "-m";
  } else {
    argv [ f++ ] = "-u";
  }
  argv [ f++ ] = ((void *)0);
  if ( ( f = fork() ) < 0 ) {
  } else if ( f > 0 ) {
  } else {
    execv ( pndrun, argv );
  }
  int status = 0;
  waitpid ( f, &status, 0 );
  return ( 1 );
}

canonical_original_code:
static unsigned char pnd_pnd_mountie(char *pndrun, char *fullpath, char *unique_id, unsigned char do_mount) {
  char *argv[20];
  int f;
  if ( ! pndrun ) {
    return ( 0 );
  }
  if ( ! fullpath ) {
    return ( 0 );
  }
  if ( ! unique_id ) {
    return ( 0 );
  }
  memset ( argv, '\0', sizeof(char *) * 20 );
  f = 0;
  argv [ f++ ] = pndrun;
  argv [ f++ ] = "-p";
  argv [ f++ ] = fullpath;
  argv [ f++ ] = "-b";
  argv [ f++ ] = unique_id;
  if ( do_mount ) {
    argv [ f++ ] = "-m";
  } else {
    argv [ f++ ] = "-u";
  }
  argv [ f++ ] = ((void *)0);
  if ( ( f = fork() ) < 0 ) {
  } else if ( f > 0 ) {
  } else {
    execv ( pndrun, argv );
  }
  int status = 0;
  waitpid ( f, &status, 0 );
  return ( 1 );
}

variable_types:
pndrun
char *

variable_types:
fullpath
char *

variable_types:
argv
char *[20]

variable_types: f int

variable_types: status int


decompiled_code:
char *__fastcall pnd_match_binbuf(char *s1, unsigned int a2, const char *a3)
{
char *v3; // rbx
size_t v5; // rax
char *v6; // rbp
unsigned int v7; // er13
const unsigned __int16 *v8; // r12

v3 = s1;
v5 = strlen(a3);
v6 = &s1[a2 - v5];
if ( s1 >= v6 )
return 0LL;
v7 = v5;
v8 = *_ctype_b_loc();
do
{
if ( (v8[*v3] & 0x4000) != 0 && !strncasecmp(v3, a3, v7) )
return v3;
++v3;
}
while ( v6 != v3 );
return 0LL;
}

canonical_decompiled_code:
char *__fastcall func2(char *s1, unsigned int a2, const char *a3)
{
char *v3; // rbx
size_t v5; // rax
char *v6; // rbp
unsigned int v7; // er13
const unsigned __int16 *v8; // r12

v3 = s1;
v5 = strlen(a3);
v6 = &s1[a2 - v5];
if ( s1 >= v6 )
return 0LL;
v7 = v5;
v8 = *_ctype_b_loc();
do
{
if ( (v8[*v3] & 0x4000) != 0 && !strncasecmp(v3, a3, v7) )
return v3;
++v3;
}
while ( v6 != v3 );
return 0LL;
}

original_code:
char *pnd_match_binbuf ( char *haystack, unsigned int maxlen, char *needle ) {
  char *end = haystack + maxlen - strlen ( needle );
  unsigned int needlelen = strlen ( needle );
  while ( haystack < end ) {
    if ( ((*__ctype_b_loc ())[(int) ((*haystack))] & (unsigned short int) _ISprint) ) {
      if ( strncasecmp ( haystack, needle, needlelen ) == 0 ) {
 return ( haystack );
      }
    }
    haystack += 1;
  }
  return ( ((void *)0) );
}

canonical_original_code:
char *pnd_match_binbuf(char *haystack, unsigned int maxlen, char *needle) {
  char *end = haystack + maxlen - strlen ( needle );
  unsigned int needlelen = strlen ( needle );
  while ( haystack < end ) {
    if ( ((*__ctype_b_loc ())[(int) ((*haystack))] & (unsigned short) _ISprint) ) {
      if ( strncasecmp ( haystack, needle, needlelen ) == 0 ) {
 return ( haystack );
      }
    }
    haystack += 1;
  }
  return ( ((void *)0) );
}

variable_types:
haystack
char *

variable_types:
maxlen
unsigned int

variable_types:
needle
char *

variable_types:
end
char *

variable_types:
needlelen
unsigned int


decompiled_code:
__int64 __fastcall pnd_pnd_mount(char *a1, char *a2, char *a3)
{
return pnd_pnd_mountie(a1, a2, a3, 1);
}

canonical_decompiled_code:
__int64 __fastcall func4(char *a1, char *a2, char *a3)
{
return func0(a1, a2, a3, 1);
}

original_code:
unsigned char pnd_pnd_mount ( char *pndrun, char *fullpath, char *unique_id ) {
  return ( pnd_pnd_mountie ( pndrun, fullpath, unique_id, 1 ) );
}

canonical_original_code:
unsigned char pnd_pnd_mount(char *pndrun, char *fullpath, char *unique_id) {
  return ( pnd_pnd_mountie ( pndrun, fullpath, unique_id, 1 ) );
}


decompiled_code:
__int64 __fastcall pnd_pnd_unmount(char *a1, char *a2, char *a3)
{
return pnd_pnd_mountie(a1, a2, a3, 0);
}

canonical_decompiled_code:
__int64 __fastcall func5(char *a1, char *a2, char *a3)
{
return func0(a1, a2, a3, 0);
}

original_code:
unsigned char pnd_pnd_unmount ( char *pndrun, char *fullpath, char *unique_id ) {
  return ( pnd_pnd_mountie ( pndrun, fullpath, unique_id, 0 ) );
}

canonical_original_code:
unsigned char pnd_pnd_unmount(char *pndrun, char *fullpath, char *unique_id) {
  return ( pnd_pnd_mountie ( pndrun, fullpath, unique_id, 0 ) );
}


decompiled_code:
__int64 __fastcall pnd_is_key_down(int fd, int a2)
{
int v2; // edx
__int64 result; // rax
char v4[104]; // [rsp+0h] [rbp-68h] BYREF

memset(v4, 0, 0x60uLL);
v2 = ioctl(fd, 0x80604518uLL);
result = 0xFFFFFFFFLL;
if ( v2 >= 0 )
result = ((int)(unsigned __int8)v4[a2 / 8] >> (a2 % 8)) & 1;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(int fd, int a2)
{
int v2; // edx
__int64 result; // rax
char v4[104]; // [rsp+0h] [rbp-68h] BYREF

memset(v4, 0, 0x60uLL);
v2 = ioctl(fd, 0x80604518uLL);
result = 0xFFFFFFFFLL;
if ( v2 >= 0 )
result = ((int)(unsigned __int8)v4[a2 / 8] >> (a2 % 8)) & 1;
return result;
}

variable_types: fd int

variable_types: key int

variable_types:
size
unsigned int

variable_types:
buf
unsigned char [-1]


decompiled_code:
int *__fastcall pnd_evdev_close(int a1)
{
int *result; // rax
int v3; // edi

result = evmap;
v3 = evmap[3 * a1];
if ( v3 >= 0 )
{
close(v3);
result = evmap;
evmap[3 * a1] = -1;
}
return result;
}

canonical_decompiled_code:
int *__fastcall func0(int a1)
{
int *result; // rax
int v3; // edi

result = evmap;
v3 = evmap[3 * a1];
if ( v3 >= 0 )
{
close(v3);
result = evmap;
evmap[3 * a1] = -1;
}
return result;
}

original_code:
void pnd_evdev_close ( pnd_evdev_e device ) {
  if ( evmap [ device ].fd >= 0 ) {
    close ( evmap [ device ].fd );
    evmap [ device ].fd = -1;
  }
  return;
}

canonical_original_code:
void pnd_evdev_close(enum pnd_evdev_e device) {
  if ( evmap [ device ].fd >= 0 ) {
    close ( evmap [ device ].fd );
    evmap [ device ].fd = -1;
  }
  return;
}

variable_types: enum pnd_evdev_e { pnd_evdev_dpads=0, pnd_evdev_nub1=1, pnd_evdev_nub2=2, pnd_evdev_power=3, pnd_evdev_max=4 }


decompiled_code:
int *pnd_evdev_closeall()
{
pnd_evdev_close(0);
pnd_evdev_close(1);
pnd_evdev_close(2);
return pnd_evdev_close(3);
}

canonical_decompiled_code:
int *func1()
{
func0(0);
func0(1);
func0(2);
return func0(3);
}

original_code:
void pnd_evdev_closeall ( void ) {
  unsigned char i;
  for ( i = 0; i < pnd_evdev_max; i++ ) {
    pnd_evdev_close ( i );
  }
  return;
}

canonical_original_code:
void pnd_evdev_closeall() {
  unsigned char i;
  for ( i = 0; i < pnd_evdev_max; i++ ) {
    pnd_evdev_close ( i );
  }
  return;
}

variable_types:
i
unsigned char


decompiled_code:
__int64 __fastcall pnd_evdev_get_fd(unsigned __int8 a1)
{
return (unsigned int)evmap[3 * a1];
}

canonical_decompiled_code:
__int64 __fastcall func2(unsigned __int8 a1)
{
return (unsigned int)evmap[3 * a1];
}

original_code:
int pnd_evdev_get_fd ( unsigned char device ) {
  return ( evmap [ device ].fd );
}

canonical_original_code:
int pnd_evdev_get_fd(unsigned char device) {
  return ( evmap [ device ].fd );
}

variable_types:
device
unsigned char


original_code:
int pnd_evdev_open_by_name ( char *devname ) {
  int fd;
  char fname [ 64 ];
  char name[256] = { 0, };
  unsigned char id;
  for ( id = 0; ; id++ ) {
    snprintf ( fname, sizeof ( fname ), "/dev/input/event%i", id );
    if ( ( fd = open ( fname, 00 | 04000 ) ) < 0 ) {
      return ( -1 );
    }
    if ( ioctl (fd, (((2U) << (((0 +8)+8)+14)) | (('E') << (0 +8)) | ((0x06) << 0) | ((sizeof(name)) << ((0 +8)+8))), name ) < 0 ) {
      close ( fd );
      continue;
    }
    if ( strcmp ( name, devname ) == 0 ) {
      return ( fd );
    }
    close ( fd );
  }
  return ( -1 );
}

canonical_original_code:
int pnd_evdev_open_by_name(char *devname) {
  int fd;
  char fname[64];
  char name[256] = { 0, };
  unsigned char id;
  for ( id = 0; ; id++ ) {
    snprintf ( fname, sizeof ( fname ), "/dev/input/event%i", id );
    if ( ( fd = open ( fname, 00 | 04000 ) ) < 0 ) {
      return ( -1 );
    }
    if ( ioctl (fd, (((2U) << (((0 +8)+8)+14)) | (('E') << (0 +8)) | ((0x06) << 0) | ((sizeof(name)) << ((0 +8)+8))), name ) < 0 ) {
      close ( fd );
      continue;
    }
    if ( strcmp ( name, devname ) == 0 ) {
      return ( fd );
    }
    close ( fd );
  }
  return ( -1 );
}

variable_types:
devname
char *

variable_types:
fname
char [64]

variable_types:
name
char [256]

variable_types:
id
unsigned char


decompiled_code:
__int64 __fastcall pnd_evdev_open(unsigned int a1)
{
int v1; // edx
__int64 result; // rax
int v3; // edx
int v4; // edx
int v5; // edx

if ( evmap_first )
{
evmap_first = 0;
evmap[0] = -1;
dword_7AC = -1;
dword_7B8 = -1;
dword_7C4 = -1;
}
if ( a1 == 2 )
{
v5 = pnd_evdev_open_by_name("nub1");
dword_7B8 = v5;
result = 0LL;
if ( v5 >= 0 )
{
evmapback[v5] = 2;
result = 1LL;
}
}
else if ( a1 > 2 )
{
result = 0LL;
if ( a1 == 3 )
{
v3 = pnd_evdev_open_by_name("power-button");
dword_7C4 = v3;
result = 0LL;
if ( v3 >= 0 )
{
evmapback[v3] = 3;
result = 1LL;
}
}
}
else if ( a1 )
{
v1 = pnd_evdev_open_by_name("nub0");
dword_7AC = v1;
result = 0LL;
if ( v1 >= 0 )
{
evmapback[v1] = 1;
result = 1LL;
}
}
else
{
v4 = pnd_evdev_open_by_name("gpio-keys");
evmap[0] = v4;
result = 0LL;
if ( v4 >= 0 )
{
evmapback[v4] = 0;
result = 1LL;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(unsigned int a1)
{
int v1; // edx
__int64 result; // rax
int v3; // edx
int v4; // edx
int v5; // edx

if ( evmap_first )
{
evmap_first = 0;
evmap[0] = -1;
dword_7AC = -1;
dword_7B8 = -1;
dword_7C4 = -1;
}
if ( a1 == 2 )
{
v5 = func3("nub1");
dword_7B8 = v5;
result = 0LL;
if ( v5 >= 0 )
{
evmapback[v5] = 2;
result = 1LL;
}
}
else if ( a1 > 2 )
{
result = 0LL;
if ( a1 == 3 )
{
v3 = func3("power-button");
dword_7C4 = v3;
result = 0LL;
if ( v3 >= 0 )
{
evmapback[v3] = 3;
result = 1LL;
}
}
}
else if ( a1 )
{
v1 = func3("nub0");
dword_7AC = v1;
result = 0LL;
if ( v1 >= 0 )
{
evmapback[v1] = 1;
result = 1LL;
}
}
else
{
v4 = func3("gpio-keys");
evmap[0] = v4;
result = 0LL;
if ( v4 >= 0 )
{
evmapback[v4] = 0;
result = 1LL;
}
}
return result;
}

original_code:
unsigned char pnd_evdev_open ( pnd_evdev_e device ) {
  if ( evmap_first ) {
    evmap_first = 0;
    unsigned char i;
    for ( i = 0; i < pnd_evdev_max; i++ ) {
      evmap [ i ].fd = -1;
    }
  }
  switch ( device ) {
  case pnd_evdev_dpads:
    if ( ( evmap [ pnd_evdev_dpads ].fd = pnd_evdev_open_by_name ( "gpio-keys" ) ) >= 0 ) {
      evmapback [ evmap [ pnd_evdev_dpads ].fd ] = pnd_evdev_dpads;
      return ( 1 );
    }
    break;
  case pnd_evdev_nub1:
    if ( ( evmap [ pnd_evdev_nub1 ].fd = pnd_evdev_open_by_name ( "nub0" ) ) >= 0 ) {
      evmapback [ evmap [ pnd_evdev_nub1 ].fd ] = pnd_evdev_nub1;
      return ( 1 );
    }
    break;
  case pnd_evdev_nub2:
    if ( ( evmap [ pnd_evdev_nub2 ].fd = pnd_evdev_open_by_name ( "nub1" ) ) >= 0 ) {
      evmapback [ evmap [ pnd_evdev_nub2 ].fd ] = pnd_evdev_nub2;
      return ( 1 );
    }
    break;
  case pnd_evdev_power:
    if ( ( evmap [ pnd_evdev_power ].fd = pnd_evdev_open_by_name ( "power-button" ) ) >= 0 ) {
      evmapback [ evmap [ pnd_evdev_power ].fd ] = pnd_evdev_power;
      return ( 1 );
    }
    break;
  case pnd_evdev_max:
    return ( 0 );
  }
  return ( 0 );
}

canonical_original_code:
unsigned char pnd_evdev_open(enum pnd_evdev_e device) {
  if ( evmap_first ) {
    evmap_first = 0;
    unsigned char i;
    for ( i = 0; i < pnd_evdev_max; i++ ) {
      evmap [ i ].fd = -1;
    }
  }
  switch ( device ) {
  case pnd_evdev_dpads:
    if ( ( evmap [ pnd_evdev_dpads ].fd = pnd_evdev_open_by_name ( "gpio-keys" ) ) >= 0 ) {
      evmapback [ evmap [ pnd_evdev_dpads ].fd ] = pnd_evdev_dpads;
      return ( 1 );
    }
    break;
  case pnd_evdev_nub1:
    if ( ( evmap [ pnd_evdev_nub1 ].fd = pnd_evdev_open_by_name ( "nub0" ) ) >= 0 ) {
      evmapback [ evmap [ pnd_evdev_nub1 ].fd ] = pnd_evdev_nub1;
      return ( 1 );
    }
    break;
  case pnd_evdev_nub2:
    if ( ( evmap [ pnd_evdev_nub2 ].fd = pnd_evdev_open_by_name ( "nub1" ) ) >= 0 ) {
      evmapback [ evmap [ pnd_evdev_nub2 ].fd ] = pnd_evdev_nub2;
      return ( 1 );
    }
    break;
  case pnd_evdev_power:
    if ( ( evmap [ pnd_evdev_power ].fd = pnd_evdev_open_by_name ( "power-button" ) ) >= 0 ) {
      evmapback [ evmap [ pnd_evdev_power ].fd ] = pnd_evdev_power;
      return ( 1 );
    }
    break;
  case pnd_evdev_max:
    return ( 0 );
  }
  return ( 0 );
}

user_defined_types: enum pnd_evdev_e { pnd_evdev_dpads=0, pnd_evdev_nub1=1, pnd_evdev_nub2=2, pnd_evdev_power=3, pnd_evdev_max=4 }


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

if ( evmap[3 * a1] < 0 )
result = 0xFFFFFFFFLL;
else
result = (unsigned int)evmap[3 * a1 + 1];
return result;
}

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

if ( evmap[3 * a1] < 0 )
result = 0xFFFFFFFFLL;
else
result = (unsigned int)evmap[3 * a1 + 1];
return result;
}

original_code:
unsigned int pnd_evdev_dpad_state ( pnd_evdev_e device ) {
  if ( evmap [ device ].fd < 0 ) {
    return ( -1 );
  }
  return ( evmap [ device ].state.buttons );
}

canonical_original_code:
unsigned int pnd_evdev_dpad_state(enum pnd_evdev_e device) {
  if ( evmap [ device ].fd < 0 ) {
    return ( -1 );
  }
  return ( evmap [ device ].state.buttons );
}


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

result = 0xFFFFFFFFLL;
if ( evmap[3 * a1] >= 0 )
{
*a2 = *(_QWORD *)&dword_7A4[3 * a1];
result = 1LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func7(int a1, _QWORD *a2)
{
__int64 result; // rax

result = 0xFFFFFFFFLL;
if ( evmap[3 * a1] >= 0 )
{
*a2 = *(_QWORD *)&dword_7A4[3 * a1];
result = 1LL;
}
return result;
}

original_code:
int pnd_evdev_nub_state ( pnd_evdev_e nubdevice, pnd_nubstate_t *r_nubstate ) {
  if ( evmap [ nubdevice ].fd < 0 ) {
    return ( -1 );
  }
  memcpy ( r_nubstate, &(evmap [ nubdevice ].state.nub), sizeof(pnd_nubstate_t) );
  return ( 1 );
}

canonical_original_code:
int pnd_evdev_nub_state(enum pnd_evdev_e nubdevice, struct pnd_nubstate_t *r_nubstate) {
  if ( evmap [ nubdevice ].fd < 0 ) {
    return ( -1 );
  }
  memcpy ( r_nubstate, &(evmap [ nubdevice ].state.nub), sizeof(pnd_nubstate_t) );
  return ( 1 );
}

variable_types: struct pnd_nubstate_t { int x; int y; } *


decompiled_code:
char *__fastcall pnd_locate_filename(char *s, const char *a2)
{
char *v3; // r12
char v4; // r13
char *v5; // rbx
char **v6; // r14
__int64 v7; // rbx
wordexp_t pwordexp; // [rsp+10h] [rbp-2178h] BYREF
struct stat v10; // [rsp+30h] [rbp-2158h] BYREF
char file[4096]; // [rsp+C0h] [rbp-20C8h] BYREF
char dest[4096]; // [rsp+10C0h] [rbp-10C8h] BYREF
struct stat v13; // [rsp+20C0h] [rbp-C8h] BYREF

while ( 1 )
{
v3 = strchr(s, 58);
v4 = (v3 != 0LL) & (v3 < &s[strlen(s)]);
if ( v4 )
{
memset(dest, 0, sizeof(dest));
strncpy(dest, s, v3 - s);
}
else
{
strncpy(dest, s, 0xFFFuLL);
}
pathiter_depthlimit = 0xFFFF;
v5 = strchr(dest, 60);
if ( v5 )
{
if ( ((*_ctype_b_loc())[v5[1]] & 0x800) != 0 )
pathiter_depthlimit = atoi(v5 + 1);
*v5 = 0;
}
if ( !wordexp(dest, &pwordexp, 0) )
break;
LABEL_5:
if ( !v4 )
return 0LL;
s = v3 + 1;
}
v6 = pwordexp.we_wordv;
if ( !pwordexp.we_wordc )
{
LABEL_19:
wordfree(&pwordexp);
goto LABEL_5;
}
v7 = 0LL;
while ( 1 )
{
strcpy(file, v6[v7]);
if ( !stat(file, &v10) && (v10.st_mode & 0xF000) == 0x4000 )
{
*(_WORD *)&file[strlen(file)] = 47;
strncat(file, a2, 0x1000uLL);
if ( !stat(file, &v13) )
break;
}
if ( pwordexp.we_wordc <= ++v7 )
goto LABEL_19;
}
strcpy(pnd_locate_buffer, file);
wordfree(&pwordexp);
return pnd_locate_buffer;
}

canonical_decompiled_code:
char *__fastcall func0(char *s, const char *a2)
{
char *v3; // r12
char v4; // r13
char *v5; // rbx
char **v6; // r14
__int64 v7; // rbx
wordexp_t pwordexp; // [rsp+10h] [rbp-2178h] BYREF
struct stat v10; // [rsp+30h] [rbp-2158h] BYREF
char file[4096]; // [rsp+C0h] [rbp-20C8h] BYREF
char dest[4096]; // [rsp+10C0h] [rbp-10C8h] BYREF
struct stat v13; // [rsp+20C0h] [rbp-C8h] BYREF

while ( 1 )
{
v3 = strchr(s, 58);
v4 = (v3 != 0LL) & (v3 < &s[strlen(s)]);
if ( v4 )
{
memset(dest, 0, sizeof(dest));
strncpy(dest, s, v3 - s);
}
else
{
strncpy(dest, s, 0xFFFuLL);
}
pathiter_depthlimit = 0xFFFF;
v5 = strchr(dest, 60);
if ( v5 )
{
if ( ((*_ctype_b_loc())[v5[1]] & 0x800) != 0 )
pathiter_depthlimit = atoi(v5 + 1);
*v5 = 0;
}
if ( !wordexp(dest, &pwordexp, 0) )
break;
LABEL_5:
if ( !v4 )
return 0LL;
s = v3 + 1;
}
v6 = pwordexp.we_wordv;
if ( !pwordexp.we_wordc )
{
LABEL_19:
wordfree(&pwordexp);
goto LABEL_5;
}
v7 = 0LL;
while ( 1 )
{
strcpy(file, v6[v7]);
if ( !stat(file, &v10) && (v10.st_mode & 0xF000) == 0x4000 )
{
*(_WORD *)&file[strlen(file)] = 47;
strncat(file, a2, 0x1000uLL);
if ( !stat(file, &v13) )
break;
}
if ( pwordexp.we_wordc <= ++v7 )
goto LABEL_19;
}
strcpy(pnd_locate_buffer, file);
wordfree(&pwordexp);
return pnd_locate_buffer;
}

original_code:
char *pnd_locate_filename ( char *searchpath, char *filename ) {
  struct stat foo;
  char *end, *colon; char *head = searchpath; char chunk [ 4096 ]; char *lt; while ( 1 ) { colon = strchr ( head, ':' ); end = strchr ( head, '\0' ); if ( colon && colon < end ) { memset ( chunk, '\0', 4096 ); strncpy ( chunk, head, colon - head ); } else { strncpy ( chunk, head, 4096 - 1 ); } pathiter_depthlimit = 0xFFFF; if ( ( lt = strchr ( chunk, '<' ) ) ) { if ( ((*__ctype_b_loc ())[(int) ((*(lt+1)))] & (unsigned short int) _ISdigit) ) { pathiter_depthlimit = atoi ( lt + 1 ); } *lt = '\0'; } struct stat statbuf; wordexp_t _p; char **_w; int _i; char buffer [ 4096 ]; if ( wordexp ( chunk, &_p, 0 ) != 0 ) { } else { _w = _p.we_wordv; for ( _i=0; _i < _p.we_wordc; _i++ ) { strcpy ( buffer, _w [ _i ] ); if ( ( stat ( buffer, &statbuf ) == 0 ) && ( ((((statbuf.st_mode)) & 0170000) == (0040000)) ) ) {
  {
    strncat ( buffer, "/", 4096 );
    strncat ( buffer, filename, 4096 );
    if ( stat ( buffer, &foo ) == 0 ) {
      strcpy ( pnd_locate_buffer, buffer );
      wordfree( &_p );
      return ( pnd_locate_buffer );
    }
  }
  } } wordfree ( &_p ); } if ( colon && colon < end ) { head = colon + 1; } else { break; } }
  return ( ((void *)0) );
}

canonical_original_code:
char *pnd_locate_filename(char *searchpath, char *filename) {
  struct stat foo;
  char *end; char *colon; char *head = searchpath; char chunk[4096]; char *lt; while ( 1 ) { colon = strchr ( head, ':' ); end = strchr ( head, '\0' ); if ( colon && colon < end ) { memset ( chunk, '\0', 4096 ); strncpy ( chunk, head, colon - head ); } else { strncpy ( chunk, head, 4096 - 1 ); } pathiter_depthlimit = 0xFFFF; if ( ( lt = strchr ( chunk, '<' ) ) ) { if ( ((*__ctype_b_loc ())[(int) ((*(lt+1)))] & (unsigned short) _ISdigit) ) { pathiter_depthlimit = atoi ( lt + 1 ); } *lt = '\0'; } struct stat statbuf; struct wordexp_t _p; char **_w; int _i; char buffer[4096]; if ( wordexp ( chunk, &_p, 0 ) != 0 ) { } else { _w = _p.we_wordv; for ( _i=0; _i < _p.we_wordc; _i++ ) { strcpy ( buffer, _w [ _i ] ); if ( ( stat ( buffer, &statbuf ) == 0 ) && ( ((((statbuf.st_mode)) & 0170000) == (0040000)) ) ) {
  {
    strncat ( buffer, "/", 4096 );
    strncat ( buffer, filename, 4096 );
    if ( stat ( buffer, &foo ) == 0 ) {
      strcpy ( pnd_locate_buffer, buffer );
      wordfree( &_p );
      return ( pnd_locate_buffer );
    }
  }
  } } wordfree ( &_p ); } if ( colon && colon < end ) { head = colon + 1; } else { break; } }
  return ( ((void *)0) );
}

variable_types:
searchpath
char *

variable_types:
filename
char *

variable_types: struct stat { unsigned long st_dev; unsigned long st_ino; unsigned long st_nlink; unsigned int st_mode; unsigned int st_uid; unsigned int st_gid; int __pad0; unsigned long st_rdev; long st_size; long st_blksize; long st_blocks; struct timespec { long tv_sec; long tv_nsec; } st_atim; struct timespec st_mtim; struct timespec st_ctim; long __glibc_reserved[3]; }

variable_types:
colon
char *

variable_types:
head
char *

variable_types:
chunk
char [4096]

variable_types:
lt
char *

variable_types: struct wordexp_t { unsigned long we_wordc; char **we_wordv; unsigned long we_offs; }

variable_types:
buffer
char [4096]


sign

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

result = 0xFFFFFFFFLL;
if ( a1 >= 0.0 )
result = a1 > 0.0;
return result;
}

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

result = 0xFFFFFFFFLL;
if ( a1 >= 0.0 )
result = a1 > 0.0;
return result;
}

original_code:
int sign(MyDataF val) {
    return (val < 0 ? -1 : (val > 0 ? 1 : 0));
}

canonical_original_code:
int sign(double val) {
    return (val < 0 ? -1 : (val > 0 ? 1 : 0));
}

variable_types: val double


decompiled_code:
double __fastcall Alpha_Nikonov(double a1, double a2)
{
double v2; // xmm0_8
double result; // xmm0_8

v2 = COERCE_DOUBLE(*(_QWORD *)&a1 & LC1) / a2;
if ( v2 >= 108.0 )
result = a2 * 14.5 * exp(-356.0 / v2);
else
result = a2 * 3.9 * exp(-213.0 / v2);
return result;
}

canonical_decompiled_code:
double __fastcall func1(double a1, double a2)
{
double v2; // xmm0_8
double result; // xmm0_8

v2 = COERCE_DOUBLE(*(_QWORD *)&a1 & LC1) / a2;
if ( v2 >= 108.0 )
result = a2 * 14.5 * exp(-356.0 / v2);
else
result = a2 * 3.9 * exp(-213.0 / v2);
return result;
}

original_code:
MyDataF Alpha_Nikonov(MyDataF E, MyDataF P) {
    MyDataF EDivP = fabs(E) / P;
    if (EDivP < 108.0) {
        return 3.9 * P * exp(-213.0 / EDivP);
    } else {
        return 14.5 * P * exp(-356.0 / EDivP);
    }
}

canonical_original_code:
double Alpha_Nikonov(double E, double P) {
    double EDivP = fabs(E) / P;
    if (EDivP < 108.0) {
        return 3.9 * P * exp(-213.0 / EDivP);
    } else {
        return 14.5 * P * exp(-356.0 / EDivP);
    }
}

variable_types: E double

variable_types: P double

variable_types: EDivP double

return_type: double


decompiled_code:
double __fastcall Eta_Nikonov(double a1, double a2)
{
double v2; // xmm0_8
double v3; // xmm2_8
double result; // xmm0_8
double v5; // xmm1_8
double x; // [rsp+8h] [rbp-10h]

v2 = COERCE_DOUBLE(*(_QWORD *)&a1 & LC1) / a2;
v3 = v2;
x = v2;
if ( v2 >= 50.0 )
{
if ( v2 < 0.0 )
v5 = sqrt(v2);
else
v5 = sqrt(v2);
if ( x > 90.0 )
result = 142.0 / v5;
else
result = v5 * 1.58;
}
else
{
result = v2 * 0.00447 * v2;
if ( v3 < 10.0 )
result = fmax(result, 4.47 / v3);
}
return result;
}

canonical_decompiled_code:
double __fastcall func2(double a1, double a2)
{
double v2; // xmm0_8
double v3; // xmm2_8
double result; // xmm0_8
double v5; // xmm1_8
double x; // [rsp+8h] [rbp-10h]

v2 = COERCE_DOUBLE(*(_QWORD *)&a1 & LC1) / a2;
v3 = v2;
x = v2;
if ( v2 >= 50.0 )
{
if ( v2 < 0.0 )
v5 = sqrt(v2);
else
v5 = sqrt(v2);
if ( x > 90.0 )
result = 142.0 / v5;
else
result = v5 * 1.58;
}
else
{
result = v2 * 0.00447 * v2;
if ( v3 < 10.0 )
result = fmax(result, 4.47 / v3);
}
return result;
}

original_code:
MyDataF Eta_Nikonov(MyDataF E, MyDataF P) {
    MyDataF EDivP;
    EDivP = fabs(E) / P;
    if (EDivP < 50.0) {
        MyDataF val1 = 4.47e-3 * (EDivP)*(EDivP);
        if (EDivP >= 10.0) {
            return val1;
        } else {
            MyDataF val2 = 4.47 / EDivP;
            return (val1 > val2 ? val1 : val2);
        }
    } else {
        MyDataF temp = sqrt(EDivP);
        return (EDivP <= 90 ? 1.58 * temp : 142 / temp);
    }
}

canonical_original_code:
double Eta_Nikonov(double E, double P) {
    double EDivP;
    EDivP = fabs(E) / P;
    if (EDivP < 50.0) {
        double val1 = 4.47e-3 * (EDivP)*(EDivP);
        if (EDivP >= 10.0) {
            return val1;
        } else {
            double val2 = 4.47 / EDivP;
            return (val1 > val2 ? val1 : val2);
        }
    } else {
        double temp = sqrt(EDivP);
        return (EDivP <= 90 ? 1.58 * temp : 142 / temp);
    }
}

variable_types: temp double


decompiled_code:
double __fastcall Niu_a_Nikonov(double a1, double a2)
{
double v3; // r14

v3 = Eta_Nikonov(a1, a2);
return COERCE_DOUBLE(We_Nikonov((__m128)*(unsigned __int64 *)&a1, a2) & LC1) * v3;
}

canonical_decompiled_code:
double __fastcall func3(double a1, double a2)
{
double v3; // r14

v3 = func2(a1, a2);
return COERCE_DOUBLE(We_Nikonov((__m128)*(unsigned __int64 *)&a1, a2) & LC1) * v3;
}

original_code:
MyDataF Niu_a_Nikonov(MyDataF E, MyDataF P) {
    return Eta_Nikonov(E, P) * fabs(We_Nikonov(E, P));
}

canonical_original_code:
double Niu_a_Nikonov(double E, double P) {
    return Eta_Nikonov(E, P) * fabs(We_Nikonov(E, P));
}


decompiled_code:
double __fastcall Niu_i_Nikonov(double a1, double a2)
{
double v3; // r14

v3 = Alpha_Nikonov(a1, a2);
return COERCE_DOUBLE(We_Nikonov((__m128)*(unsigned __int64 *)&a1, a2) & LC1) * v3;
}

canonical_decompiled_code:
double __fastcall func4(double a1, double a2)
{
double v3; // r14

v3 = func1(a1, a2);
return COERCE_DOUBLE(We_Nikonov((__m128)*(unsigned __int64 *)&a1, a2) & LC1) * v3;
}

original_code:
MyDataF Niu_i_Nikonov(MyDataF E, MyDataF P) {
    return Alpha_Nikonov(E, P) * fabs(We_Nikonov(E, P));
}

canonical_original_code:
double Niu_i_Nikonov(double E, double P) {
    return Alpha_Nikonov(E, P) * fabs(We_Nikonov(E, P));
}


decompiled_code:
double __fastcall Alpha_MorrowAndLowke(double a1, double a2)
{
double v2; // xmm0_8
double result; // xmm0_8

v2 = COERCE_DOUBLE(*(_QWORD *)&a1 & LC1) / a2 / 1.0e-15;
if ( v2 <= 1.5 )
result = a2 * 6.619e-17 * exp(-5.593 / v2);
else
result = a2 * 2.0e-16 * exp(-7.248 / v2);
return result;
}

canonical_decompiled_code:
double __fastcall func5(double a1, double a2)
{
double v2; // xmm0_8
double result; // xmm0_8

v2 = COERCE_DOUBLE(*(_QWORD *)&a1 & LC1) / a2 / 1.0e-15;
if ( v2 <= 1.5 )
result = a2 * 6.619e-17 * exp(-5.593 / v2);
else
result = a2 * 2.0e-16 * exp(-7.248 / v2);
return result;
}

original_code:
MyDataF Alpha_MorrowAndLowke(MyDataF E, MyDataF N) {
    MyDataF edn = fabs(E) / N / 1e-15;
    if (edn > 1.5) {
        return 2e-16 * N * exp(-7.248 / edn);
    } else {
        return 6.619e-17 * N * exp(-5.593 / edn);
    }
}

canonical_original_code:
double Alpha_MorrowAndLowke(double E, double N) {
    double edn = fabs(E) / N / 1e-15;
    if (edn > 1.5) {
        return 2e-16 * N * exp(-7.248 / edn);
    } else {
        return 6.619e-17 * N * exp(-5.593 / edn);
    }
}

variable_types: N double

variable_types: edn double


original_code:
MyDataF We_MorrowAndLowke(MyDataF E, MyDataF N) {
    MyDataF edn = fabs(E) / N / 1e-16;
    if (edn > 1.0) {
        if (edn <= 20.00)
            return -sign(E)*(1.03e6 * edn + 1.3e6);
        else
            return -sign(E)*(7.4e5 * edn + 7.1e6);
    } else {
        if (edn <= 0.26)
            return -sign(E)*(6.87e6 * edn + 3.38e4);
        else
            return -sign(E)*(7.2973e5 * edn + 1.63e6);
    }
}

canonical_original_code:
double We_MorrowAndLowke(double E, double N) {
    double edn = fabs(E) / N / 1e-16;
    if (edn > 1.0) {
        if (edn <= 20.00)
            return -sign(E)*(1.03e6 * edn + 1.3e6);
        else
            return -sign(E)*(7.4e5 * edn + 7.1e6);
    } else {
        if (edn <= 0.26)
            return -sign(E)*(6.87e6 * edn + 3.38e4);
        else
            return -sign(E)*(7.2973e5 * edn + 1.63e6);
    }
}


decompiled_code:
double __fastcall Niu_a_MorrowAndLowke(double a1, double a2)
{
double v3; // r14

v3 = Eta_MorrowAndLowke(a1, a2);
return COERCE_DOUBLE(COERCE_UNSIGNED_INT64(We_MorrowAndLowke(a1, a2)) & LC1) * v3;
}

canonical_decompiled_code:
double __fastcall func8(double a1, double a2)
{
double v3; // r14

v3 = func6(a1, a2);
return COERCE_DOUBLE(COERCE_UNSIGNED_INT64(We_MorrowAndLowke(a1, a2)) & LC1) * v3;
}

original_code:
MyDataF Niu_a_MorrowAndLowke(MyDataF E, MyDataF N) {
    return Eta_MorrowAndLowke(E, N) * fabs(We_MorrowAndLowke(E, N));
}

canonical_original_code:
double Niu_a_MorrowAndLowke(double E, double N) {
    return Eta_MorrowAndLowke(E, N) * fabs(We_MorrowAndLowke(E, N));
}


decompiled_code:
double __fastcall Niu_i_MorrowAndLowke(double a1, double a2)
{
double v3; // r14

v3 = Alpha_MorrowAndLowke(a1, a2);
return COERCE_DOUBLE(COERCE_UNSIGNED_INT64(We_MorrowAndLowke(a1, a2)) & LC1) * v3;
}

canonical_decompiled_code:
double __fastcall func9(double a1, double a2)
{
double v3; // r14

v3 = func5(a1, a2);
return COERCE_DOUBLE(COERCE_UNSIGNED_INT64(We_MorrowAndLowke(a1, a2)) & LC1) * v3;
}

original_code:
MyDataF Niu_i_MorrowAndLowke(MyDataF E, MyDataF N) {
    return Alpha_MorrowAndLowke(E, N) * fabs(We_MorrowAndLowke(E, N));
}

canonical_original_code:
double Niu_i_MorrowAndLowke(double E, double N) {
    return Alpha_MorrowAndLowke(E, N) * fabs(We_MorrowAndLowke(E, N));
}


decompiled_code:
double __fastcall Alpha_Kang(double a1)
{
return exp(-165000.0 / a1) * 3500.0;
}

canonical_decompiled_code:
double __fastcall func10(double a1)
{
return exp(-165000.0 / a1) * 3500.0;
}

original_code:
MyDataF Alpha_Kang(MyDataF E) {
    return 3.5e3 * exp(-1.65e5 / E);
}

canonical_original_code:
double Alpha_Kang(double E) {
    return 3.5e3 * exp(-1.65e5 / E);
}


decompiled_code:
double __fastcall Eta_Kang(double a1)
{
return exp(-25000.0 / a1) * 15.0;
}

canonical_decompiled_code:
double __fastcall func11(double a1)
{
return exp(-25000.0 / a1) * 15.0;
}

original_code:
MyDataF Eta_Kang(MyDataF E) {
    return 15.0 * exp(-2.5e4 / E);
}

canonical_original_code:
double Eta_Kang(double E) {
    return 15.0 * exp(-2.5e4 / E);
}


decompiled_code:
double __fastcall We_Kang(double a1)
{
return pow(a1, 0.75) * -6060.0;
}

canonical_decompiled_code:
double __fastcall func12(double a1)
{
return pow(a1, 0.75) * -6060.0;
}

original_code:
MyDataF We_Kang(MyDataF E) {
    return -6060.0 * pow(E, 0.75);
}

canonical_original_code:
double We_Kang(double E) {
    return -6060.0 * pow(E, 0.75);
}


decompiled_code:
double __fastcall Niu_a_Kang(double a1)
{
double v2; // r14

v2 = Eta_Kang(a1);
return COERCE_DOUBLE(COERCE_UNSIGNED_INT64(We_Kang(a1)) & LC1) * v2;
}

canonical_decompiled_code:
double __fastcall func13(double a1)
{
double v2; // r14

v2 = func11(a1);
return COERCE_DOUBLE(COERCE_UNSIGNED_INT64(We_Kang(a1)) & LC1) * v2;
}

original_code:
MyDataF Niu_a_Kang(MyDataF E) {
    return Eta_Kang(E) * fabs(We_Kang(E));
}

canonical_original_code:
double Niu_a_Kang(double E) {
    return Eta_Kang(E) * fabs(We_Kang(E));
}


decompiled_code:
double __fastcall Niu_i_Kang(double a1)
{
double v2; // r14

v2 = Alpha_Kang(a1);
return COERCE_DOUBLE(COERCE_UNSIGNED_INT64(We_Kang(a1)) & LC1) * v2;
}

canonical_decompiled_code:
double __fastcall func14(double a1)
{
double v2; // r14

v2 = func10(a1);
return COERCE_DOUBLE(COERCE_UNSIGNED_INT64(We_Kang(a1)) & LC1) * v2;
}

original_code:
MyDataF Niu_i_Kang(MyDataF E) {
    return Alpha_Kang(E) * fabs(We_Kang(E));
}

canonical_original_code:
double Niu_i_Kang(double E) {
    return Alpha_Kang(E) * fabs(We_Kang(E));
}


decompiled_code:
void __fastcall Niu_Kang(double *a1, double *a2, double a3)
{
double v4; // [rsp+8h] [rbp-20h]

*(_QWORD *)&v4 = COERCE_UNSIGNED_INT64(We_Kang(a3)) & LC1;
*a2 = Eta_Kang(a3) * v4;
*a1 = Alpha_Kang(a3) * v4;
}

canonical_decompiled_code:
void __fastcall func15(double *a1, double *a2, double a3)
{
double v4; // [rsp+8h] [rbp-20h]

*(_QWORD *)&v4 = COERCE_UNSIGNED_INT64(We_Kang(a3)) & LC1;
*a2 = func11(a3) * v4;
*a1 = func10(a3) * v4;
}

original_code:
void Niu_Kang(MyDataF *pNiu_i, MyDataF *pNiu_a, MyDataF E) {
    MyDataF We;
    We = fabs(We_Kang(E));
    *pNiu_a = Eta_Kang(E) * We;
    *pNiu_i = Alpha_Kang(E) * We;
}

canonical_original_code:
void Niu_Kang(double *pNiu_i, double *pNiu_a, double E) {
    double We;
    We = fabs(We_Kang(E));
    *pNiu_a = Eta_Kang(E) * We;
    *pNiu_i = Alpha_Kang(E) * We;
}

variable_types: We double


decompiled_code:
void __fastcall Niu_Nikonov(double *a1, double *a2, __m128 a3, double a4)
{
double v4; // rbx
double v5; // [rsp+8h] [rbp-30h]

v4 = *(double *)a3.m128_u64;
*(_QWORD *)&v5 = We_Nikonov(a3, a4) & LC1;
*a2 = Eta_Nikonov(v4, a4) * v5;
*a1 = Alpha_Nikonov(v4, a4) * v5;
}

canonical_decompiled_code:
void __fastcall func16(double *a1, double *a2, __m128 a3, double a4)
{
double v4; // rbx
double v5; // [rsp+8h] [rbp-30h]

v4 = *(double *)a3.m128_u64;
*(_QWORD *)&v5 = We_Nikonov(a3, a4) & LC1;
*a2 = func2(v4, a4) * v5;
*a1 = func1(v4, a4) * v5;
}

original_code:
void Niu_Nikonov(MyDataF *pNiu_i, MyDataF *pNiu_a, MyDataF E, MyDataF P) {
    MyDataF we;
    we = fabs(We_Nikonov(E, P));
    *pNiu_a = Eta_Nikonov(E, P) * we;
    *pNiu_i = Alpha_Nikonov(E, P) * we;
}

canonical_original_code:
void Niu_Nikonov(double *pNiu_i, double *pNiu_a, double E, double P) {
    double we;
    we = fabs(We_Nikonov(E, P));
    *pNiu_a = Eta_Nikonov(E, P) * we;
    *pNiu_i = Alpha_Nikonov(E, P) * we;
}

variable_types: we double


decompiled_code:
void __fastcall Niu_MorrowAndLowke(double *a1, double *a2, double a3, double a4)
{
double v5; // [rsp+8h] [rbp-30h]

*(_QWORD *)&v5 = COERCE_UNSIGNED_INT64(We_MorrowAndLowke(a3, a4)) & LC1;
*a2 = Eta_MorrowAndLowke(a3, a4) * v5;
*a1 = Alpha_MorrowAndLowke(a3, a4) * v5;
}

canonical_decompiled_code:
void __fastcall func17(double *a1, double *a2, double a3, double a4)
{
double v5; // [rsp+8h] [rbp-30h]

*(_QWORD *)&v5 = COERCE_UNSIGNED_INT64(We_MorrowAndLowke(a3, a4)) & LC1;
*a2 = func6(a3, a4) * v5;
*a1 = func5(a3, a4) * v5;
}

original_code:
void Niu_MorrowAndLowke(MyDataF *pNiu_i, MyDataF *pNiu_a, MyDataF E, MyDataF N) {
    MyDataF we;
    we = fabs(We_MorrowAndLowke(E, N));
    *pNiu_a = Eta_MorrowAndLowke(E, N) * we;
    *pNiu_i = Alpha_MorrowAndLowke(E, N) * we;
}

canonical_original_code:
void Niu_MorrowAndLowke(double *pNiu_i, double *pNiu_a, double E, double N) {
    double we;
    we = fabs(We_MorrowAndLowke(E, N));
    *pNiu_a = Eta_MorrowAndLowke(E, N) * we;
    *pNiu_i = Alpha_MorrowAndLowke(E, N) * we;
}


ElectronTemperature

decompiled_code:
double ElectronTemperature()
{
return *(double *)&LC49;
}

canonical_decompiled_code:
double func18()
{
return *(double *)&LC49;
}

original_code:
MyDataF ElectronTemperature(MyDataF Em, MyDataF p) {
    return 2.0;
}

canonical_original_code:
double ElectronTemperature(double Em, double p) {
    return 2.0;
}

variable_types: Em double

variable_types: p double


collision

decompiled_code:
double collision()
{
return *(double *)&LC50;
}

canonical_decompiled_code:
double func19()
{
return *(double *)&LC50;
}

original_code:
MyDataF collision(MyDataF Em, MyDataF p) {
    return 4.0e12;
}

canonical_original_code:
double collision(double Em, double p) {
    return 4.0e12;
}


ionization

variable_types: Ngas double

variable_types: EmDivNgas double

variable_types: y double

variable_types: xc double

variable_types: w double

variable_types: A double


attachment

decompiled_code:
double attachment()
{
return 0.0;
}

canonical_decompiled_code:
double func21()
{
return 0.0;
}

original_code:
MyDataF attachment(MyDataF Em, MyDataF p) {
    return 0.0;
}

canonical_original_code:
double attachment(double Em, double p) {
    return 0.0;
}


help

decompiled_code:
int help()
{
puts("Usage:");
puts("XXXX option\n");
puts("--niu-type=n\tChoose niu formula type to compute.");
puts("\t1\t------\tMorrow and Lowke's");
puts("\t2\t------\tNikonov's");
puts("\t3\t------\tKang's");
puts("\tothers\t------\tdefault");
puts("--matlab=[1,0]\tUse Matlab engine to show results");
puts("--rei=XXX\tSet rei");
puts("--niu-e=XXX\tSet Niu_e");
puts("--tm=1\tset to TM mode");
puts("--total-time=[>0]\ttotal simulation time");
puts("--fine-grid=\thow many fine grid cells per Maxwell cell");
puts("--maxwell-grid=\thow many Maxwell cells per wavelength");
puts("--is-connect=[0,1]\tuse connecting interface or not");
puts("--with-density=[0,1]\twether with density");
puts("--e-max= \tset E field amptidute");
puts("--waveform=\tset waveform\n\t0\t sine(default)\n\t1\t Gaussian pulse\n\t2\tcosine");
return puts("--thread-count=n\tset number of threads to run the job");
}

canonical_decompiled_code:
int func0()
{
puts("Usage:");
puts("XXXX option\n");
puts("--niu-type=n\tChoose niu formula type to compute.");
puts("\t1\t------\tMorrow and Lowke's");
puts("\t2\t------\tNikonov's");
puts("\t3\t------\tKang's");
puts("\tothers\t------\tdefault");
puts("--matlab=[1,0]\tUse Matlab engine to show results");
puts("--rei=XXX\tSet rei");
puts("--niu-e=XXX\tSet Niu_e");
puts("--tm=1\tset to TM mode");
puts("--total-time=[>0]\ttotal simulation time");
puts("--fine-grid=\thow many fine grid cells per Maxwell cell");
puts("--maxwell-grid=\thow many Maxwell cells per wavelength");
puts("--is-connect=[0,1]\tuse connecting interface or not");
puts("--with-density=[0,1]\twether with density");
puts("--e-max= \tset E field amptidute");
puts("--waveform=\tset waveform\n\t0\t sine(default)\n\t1\t Gaussian pulse\n\t2\tcosine");
return puts("--thread-count=n\tset number of threads to run the job");
}

original_code:
void help() {
    printf("Usage:\n");
    printf("XXXX option\n\n");
    printf("--niu-type=n\tChoose niu formula type to compute.\n");
    printf("\t1\t------\tMorrow and Lowke's\n");
    printf("\t2\t------\tNikonov's\n");
    printf("\t3\t------\tKang's\n");
    printf("\tothers\t------\tdefault\n");
    printf("--matlab=[1,0]\tUse Matlab engine to show results\n");
    printf("--rei=XXX\tSet rei\n");
    printf("--niu-e=XXX\tSet Niu_e\n");
    printf("--tm=1\tset to TM mode\n");
    printf("--total-time=[>0]\ttotal simulation time\n");
    printf("--fine-grid=\thow many fine grid cells per Maxwell cell\n");
    printf("--maxwell-grid=\thow many Maxwell cells per wavelength\n");
    printf("--is-connect=[0,1]\tuse connecting interface or not\n");
    printf("--with-density=[0,1]\twether with density\n");
    printf("--e-max= \tset E field amptidute\n");
    printf("--waveform=\tset waveform\n\t0\t sine(default)\n\t1\t Gaussian pulse\n\t2\tcosine\n");
    printf("--thread-count=n\tset number of threads to run the job\n");
}


PrintInput

decompiled_code:
int PrintInput()
{
printf("--niu-type=%d\n", niutype);
printf("--matlab=%d\n", IsMatlabSim);
printf("--rei=%5.3e\n", rei);
printf("--niu-e=%5.3e\n", mu_e);
printf("--tm=%d\n", IsTMx);
printf("--fine-grid=%d\n", m);
printf("--total-time=%5.3e\n", totaltime);
printf("--is-connect=%d\n", isConnect);
printf("--with-density=%d\n", IfWithDensity);
printf("--e-max=%5.3e\n", E_0);
printf("--waveform=%d\n", srcType);
return printf("--thead-count=%d\n", thread_count);
}

canonical_decompiled_code:
int func1()
{
printf("--niu-type=%d\n", niutype);
printf("--matlab=%d\n", IsMatlabSim);
printf("--rei=%5.3e\n", rei);
printf("--niu-e=%5.3e\n", mu_e);
printf("--tm=%d\n", IsTMx);
printf("--fine-grid=%d\n", m);
printf("--total-time=%5.3e\n", totaltime);
printf("--is-connect=%d\n", isConnect);
printf("--with-density=%d\n", IfWithDensity);
printf("--e-max=%5.3e\n", E_0);
printf("--waveform=%d\n", srcType);
return printf("--thead-count=%d\n", thread_count);
}

original_code:
void PrintInput() {
    printf("--niu-type=%d\n", niutype);
    printf("--matlab=%d\n", IsMatlabSim);
    printf("--rei=%5.3e\n", rei);
    printf("--niu-e=%5.3e\n", mu_e);
    printf("--tm=%d\n", IsTMx);
    printf("--fine-grid=%d\n", m);
    printf("--total-time=%5.3e\n", totaltime);
    printf("--is-connect=%d\n", isConnect);
    printf("--with-density=%d\n", IfWithDensity);
    printf("--e-max=%5.3e\n", E_0);
    printf("--waveform=%d\n",srcType);
    printf("--thead-count=%d\n", thread_count);
}


input

decompiled_code:
int __fastcall input(int a1, __int64 a2, __m128d a3)
{
const void **v3; // rbx
__int64 v4; // rbp
const char *v5; // rax
int v6; // eax
int v7; // eax
__m128d v8; // xmm1
__m128d v9; // xmm0

if ( a1 <= 1 )
{
help();
exit(-1);
}
v3 = (const void **)(a2 + 8);
v4 = a2 + 8LL * (unsigned int)(a1 - 2) + 16;
do
{
v5 = (const char *)*v3;
if ( !memcmp(*v3, "--niu-type=", 0xBuLL) )
{
niutype = atoi(v5 + 11);
}
else if ( !memcmp(*v3, "--matlab=1", 0xAuLL) )
{
IsMatlabSim = 1;
}
else if ( !memcmp(*v3, "--rei=", 6uLL) )
{
rei = atof(v5 + 6);
}
else if ( !memcmp(*v3, "--niu-e=", 8uLL) )
{
mu_e = atof(v5 + 8);
}
else if ( !memcmp(*v3, "--tm=1", 6uLL) )
{
IsTMx = 0;
IsTEx = 1;
}
else if ( !memcmp(*v3, "--maxwell-grid=", 0xFuLL) )
{
v6 = atoi(v5 + 12);
if ( v6 < 4 )
v6 = 50;
maxwellGridSize = v6;
}
else if ( !memcmp(*v3, "--fine-grid=", 0xCuLL) )
{
v7 = atoi(v5 + 12);
if ( v7 < 4 )
v7 = 10;
m = v7;
}
else if ( !memcmp(*v3, "--total-time=", 0xDuLL) )
{
a3.m128d_f64[0] = atof(v5 + 13);
v8 = a3;
v9 = _mm_cmple_sd(a3, (__m128d)0LL);
a3 = _mm_or_pd(_mm_andn_pd(v9, v8), _mm_and_pd((__m128d)(unsigned __int64)LC40, v9));
totaltime = *(_QWORD *)&a3.m128d_f64[0];
}
else if ( !memcmp(*v3, "--is-connect=", 0xDuLL) )
{
isConnect = atoi(v5 + 13);
}
else if ( !memcmp(*v3, "--with-density=", 0xFuLL) )
{
IfWithDensity = atoi(v5 + 15);
}
else if ( !memcmp(*v3, "--e-max=", 8uLL) )
{
E_0 = atof(v5 + 8);
}
else if ( !memcmp(*v3, "--waveform=", 0xBuLL) )
{
srcType = atoi(v5 + 11);
}
else if ( !memcmp(*v3, "--thread-count=", 0xFuLL) )
{
thread_count = atoi(v5 + 15);
}
++v3;
}
while ( v3 != (const void **)v4 );
if ( niutype == 4 )
if_erms_E_max = 1;
return PrintInput();
}

canonical_decompiled_code:
int __fastcall func2(int a1, __int64 a2, __m128d a3)
{
const void **v3; // rbx
__int64 v4; // rbp
const char *v5; // rax
int v6; // eax
int v7; // eax
__m128d v8; // xmm1
__m128d v9; // xmm0

if ( a1 <= 1 )
{
func0();
exit(-1);
}
v3 = (const void **)(a2 + 8);
v4 = a2 + 8LL * (unsigned int)(a1 - 2) + 16;
do
{
v5 = (const char *)*v3;
if ( !memcmp(*v3, "--niu-type=", 0xBuLL) )
{
niutype = atoi(v5 + 11);
}
else if ( !memcmp(*v3, "--matlab=1", 0xAuLL) )
{
IsMatlabSim = 1;
}
else if ( !memcmp(*v3, "--rei=", 6uLL) )
{
rei = atof(v5 + 6);
}
else if ( !memcmp(*v3, "--niu-e=", 8uLL) )
{
mu_e = atof(v5 + 8);
}
else if ( !memcmp(*v3, "--tm=1", 6uLL) )
{
IsTMx = 0;
IsTEx = 1;
}
else if ( !memcmp(*v3, "--maxwell-grid=", 0xFuLL) )
{
v6 = atoi(v5 + 12);
if ( v6 < 4 )
v6 = 50;
maxwellGridSize = v6;
}
else if ( !memcmp(*v3, "--fine-grid=", 0xCuLL) )
{
v7 = atoi(v5 + 12);
if ( v7 < 4 )
v7 = 10;
m = v7;
}
else if ( !memcmp(*v3, "--total-time=", 0xDuLL) )
{
a3.m128d_f64[0] = atof(v5 + 13);
v8 = a3;
v9 = _mm_cmple_sd(a3, (__m128d)0LL);
a3 = _mm_or_pd(_mm_andn_pd(v9, v8), _mm_and_pd((__m128d)(unsigned __int64)LC40, v9));
totaltime = *(_QWORD *)&a3.m128d_f64[0];
}
else if ( !memcmp(*v3, "--is-connect=", 0xDuLL) )
{
isConnect = atoi(v5 + 13);
}
else if ( !memcmp(*v3, "--with-density=", 0xFuLL) )
{
IfWithDensity = atoi(v5 + 15);
}
else if ( !memcmp(*v3, "--e-max=", 8uLL) )
{
E_0 = atof(v5 + 8);
}
else if ( !memcmp(*v3, "--waveform=", 0xBuLL) )
{
srcType = atoi(v5 + 11);
}
else if ( !memcmp(*v3, "--thread-count=", 0xFuLL) )
{
thread_count = atoi(v5 + 15);
}
++v3;
}
while ( v3 != (const void **)v4 );
if ( niutype == 4 )
if_erms_E_max = 1;
return func1();
}

original_code:
void input(int argc, char*argv[]) {
    void PrintInput();
    void help();
    int i;
    if (argc < 2) {
        help();
        exit(-1);
    }
    for (i = 1; i < argc; i++) {
        if (strncmp(argv[i], "--niu-type=", 11) == 0) {
            niutype = atoi(argv[i] + 11);
        } else if (strncmp(argv[i], "--matlab=1", 10) == 0) {
            IsMatlabSim = 1;
        } else if (strncmp(argv[i], "--rei=", 6) == 0) {
            rei = atof(argv[i] + 6);
        } else if (strncmp(argv[i], "--niu-e=", 8) == 0) {
            mu_e = atof(argv[i] + 8);
        } else if (strncmp(argv[i], "--tm=1", 6) == 0) {
            IsTMx = 0;
            IsTEx = 1;
        } else if (strncmp(argv[i], "--maxwell-grid=", 15) == 0) {
            maxwellGridSize = atoi(argv[i] + 12);
            if (maxwellGridSize < 4)maxwellGridSize = 50;
        } else if (strncmp(argv[i], "--fine-grid=", 12) == 0) {
            m = atoi(argv[i] + 12);
            if (m < 4)m = 10;
        } else if (strncmp(argv[i], "--total-time=", 13) == 0) {
            totaltime = atof(argv[i] + 13);
            if (totaltime <= 0)totaltime = 100.0;
        } else if (strncmp(argv[i], "--is-connect=", 13) == 0) {
            isConnect = atoi(argv[i] + 13);
        } else if (strncmp(argv[i], "--with-density=", 15) == 0) {
            IfWithDensity = atoi(argv[i] + 15);
        } else if (strncmp(argv[i], "--e-max=", 8) == 0) {
            E_0 = atof(argv[i] + 8);
        }else if(strncmp(argv[i],"--waveform=",11)==0){
            srcType=atoi(argv[i]+11);
        }
        else if (strncmp(argv[i], "--thread-count=", 15) == 0) {
            thread_count = atoi(argv[i] + 15);
        }
    }
    if (niutype == 4) {
        if_erms_E_max = 1;
    }
    PrintInput();
}

canonical_original_code:
void input(int argc, char *argv[]) {
    void PrintInput();
    void help();
    int i;
    if (argc < 2) {
        help();
        exit(-1);
    }
    for (i = 1; i < argc; i++) {
        if (strncmp(argv[i], "--niu-type=", 11) == 0) {
            niutype = atoi(argv[i] + 11);
        } else if (strncmp(argv[i], "--matlab=1", 10) == 0) {
            IsMatlabSim = 1;
        } else if (strncmp(argv[i], "--rei=", 6) == 0) {
            rei = atof(argv[i] + 6);
        } else if (strncmp(argv[i], "--niu-e=", 8) == 0) {
            mu_e = atof(argv[i] + 8);
        } else if (strncmp(argv[i], "--tm=1", 6) == 0) {
            IsTMx = 0;
            IsTEx = 1;
        } else if (strncmp(argv[i], "--maxwell-grid=", 15) == 0) {
            maxwellGridSize = atoi(argv[i] + 12);
            if (maxwellGridSize < 4)maxwellGridSize = 50;
        } else if (strncmp(argv[i], "--fine-grid=", 12) == 0) {
            m = atoi(argv[i] + 12);
            if (m < 4)m = 10;
        } else if (strncmp(argv[i], "--total-time=", 13) == 0) {
            totaltime = atof(argv[i] + 13);
            if (totaltime <= 0)totaltime = 100.0;
        } else if (strncmp(argv[i], "--is-connect=", 13) == 0) {
            isConnect = atoi(argv[i] + 13);
        } else if (strncmp(argv[i], "--with-density=", 15) == 0) {
            IfWithDensity = atoi(argv[i] + 15);
        } else if (strncmp(argv[i], "--e-max=", 8) == 0) {
            E_0 = atof(argv[i] + 8);
        }else if(strncmp(argv[i],"--waveform=",11)==0){
            srcType=atoi(argv[i]+11);
        }
        else if (strncmp(argv[i], "--thread-count=", 15) == 0) {
            thread_count = atoi(argv[i] + 15);
        }
    }
    if (niutype == 4) {
        if_erms_E_max = 1;
    }
    PrintInput();
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types:
PrintInput
void ()

variable_types:
help
void ()

variable_types: i int


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__m128d v3; // xmm0

input(argc, (__int64)argv, v3);
initCommonData();
CalDomainSize();
InitBndCtrl();
InitCoeff();
InitPMLBound();
IntTtlFldDmnBnd();
fdtd();
FreePMLSpace();
SaveToFile();
FreeSpace();
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__m128d v3; // xmm0

func2(argc, (__int64)argv, v3);
initCommonData();
CalDomainSize();
InitBndCtrl();
InitCoeff();
InitPMLBound();
IntTtlFldDmnBnd();
fdtd();
FreePMLSpace();
SaveToFile();
FreeSpace();
return 0;
}

original_code:
int main(int argc, char** argv) {
    input(argc, argv);
    initCommonData();
    CalDomainSize();
    InitBndCtrl();
    InitCoeff();
    InitPMLBound();
    IntTtlFldDmnBnd();
    fdtd();
    FreePMLSpace();
    SaveToFile();
    FreeSpace();
    return (0);
}

canonical_original_code:
int main(int argc, char **argv) {
    input(argc, argv);
    initCommonData();
    CalDomainSize();
    InitBndCtrl();
    InitCoeff();
    InitPMLBound();
    IntTtlFldDmnBnd();
    fdtd();
    FreePMLSpace();
    SaveToFile();
    FreeSpace();
    return (0);
}

variable_types:
argv
char **


DispEMFields

decompiled_code:
void DispEMFields()
{
;
}

canonical_decompiled_code:
void func0()
{
;
}

original_code:
void DispEMFields(const int timestep) {
    if (IsMatlabSim) {
    }
}

canonical_original_code:
void DispEMFields(int timestep) {
    if (IsMatlabSim) {
    }
}

variable_types: timestep int


EndMatlabSim

decompiled_code:
void EndMatlabSim()
{
;
}

canonical_decompiled_code:
void func1()
{
;
}

original_code:
void EndMatlabSim() {
    if (IsMatlabSim) {
    }
}


DispNe

decompiled_code:
void DispNe()
{
;
}

canonical_decompiled_code:
void func2()
{
;
}

original_code:
void DispNe(const int timestep) {
    if (IsMatlabSim) {
    }
}

canonical_original_code:
void DispNe(int timestep) {
    if (IsMatlabSim) {
    }
}


InitSim

decompiled_code:
void InitSim()
{
;
}

canonical_decompiled_code:
void func3()
{
;
}

original_code:
void InitSim() {
    if (IsMatlabSim) {
    }
}

canonical_original_code:
void InitSim() {
    if (IsMatlabSim) {
    }
}


ResetStructDataR

decompiled_code:
double *__fastcall ResetStructDataR(__int64 a1, __int64 a2, double a3)
{
double *result; // rax
int v4; // er10
__int64 v5; // rdi
int v7; // esi
int v8; // ecx

result = (double *)a1;
v4 = a1;
v5 = a1 >> 32;
if ( (int)result > 0 )
{
v7 = 0;
v8 = 0;
do
{
if ( (int)v5 > 0 )
{
result = (double *)(a2 + 8LL * v7);
do
*result++ = a3;
while ( result != (double *)(a2 + 8 + 8 * ((unsigned int)(v5 - 1) + (__int64)v7)) );
}
++v8;
v7 += v5;
}
while ( v8 != v4 );
}
return result;
}

canonical_decompiled_code:
double *__fastcall func0(__int64 a1, __int64 a2, double a3)
{
double *result; // rax
int v4; // er10
__int64 v5; // rdi
int v7; // esi
int v8; // ecx

result = (double *)a1;
v4 = a1;
v5 = a1 >> 32;
if ( (int)result > 0 )
{
v7 = 0;
v8 = 0;
do
{
if ( (int)v5 > 0 )
{
result = (double *)(a2 + 8LL * v7);
do
*result++ = a3;
while ( result != (double *)(a2 + 8 + 8 * ((unsigned int)(v5 - 1) + (__int64)v7)) );
}
++v8;
v7 += v5;
}
while ( v8 != v4 );
}
return result;
}

original_code:
void ResetStructDataR(MyStruct mst, MyDataF val) {
    int i, j;
    for (i = 0; i < mst.nx; i++) {
        for (j = 0; j < mst.ny; j++) {
            mst.data[i * mst.ny + j] = val;
        }
    }
}

canonical_original_code:
void ResetStructDataR(struct MyStruct mst, double val) {
    int i; int j;
    for (i = 0; i < mst.nx; i++) {
        for (j = 0; j < mst.ny; j++) {
            mst.data[i * mst.ny + j] = val;
        }
    }
}

variable_types: struct MyStruct { int nx; int ny; double *data; }

variable_types: val double

variable_types: j int


PrintData

original_code:
void PrintData(MyStruct mst) {
    int i, j;
    for (i = 0; i < mst.nx; i++) {
        for (j = 0; j < mst.ny; j++) {
            printf("%2.3e ", mst.data[i * mst.ny + j]);
        }
        printf("\n");
    }
}

canonical_original_code:
void PrintData(struct MyStruct mst) {
    int i; int j;
    for (i = 0; i < mst.nx; i++) {
        for (j = 0; j < mst.ny; j++) {
            printf("%2.3e ", mst.data[i * mst.ny + j]);
        }
        printf("\n");
    }
}

user_defined_types: struct MyStruct { int nx; int ny; double *data; }


BackupMyStruct

decompiled_code:
__int64 __fastcall BackupMyStruct(__int64 a1, const void *a2, __int64 a3, void *a4)
{
unsigned int v4; // ebx

if ( a2 == a4 )
{
puts("Cannot Copy to Itself!");
v4 = 0;
}
else if ( a4 && a2 )
{
if ( HIDWORD(a1) == HIDWORD(a3) )
{
if ( HIDWORD(a1) && (_DWORD)a1 )
{
v4 = a1 * HIDWORD(a1);
memcpy(a4, a2, 8LL * (int)a1 * HIDWORD(a1));
}
else
{
puts("Empty space to be copied from!");
v4 = 0;
}
}
else
{
puts("Fields are not the same size!");
v4 = 0;
}
}
else
{
puts("One of the fields is empty!");
v4 = 0;
}
return v4;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, const void *a2, __int64 a3, void *a4)
{
unsigned int v4; // ebx

if ( a2 == a4 )
{
puts("Cannot Copy to Itself!");
v4 = 0;
}
else if ( a4 && a2 )
{
if ( HIDWORD(a1) == HIDWORD(a3) )
{
if ( HIDWORD(a1) && (_DWORD)a1 )
{
v4 = a1 * HIDWORD(a1);
memcpy(a4, a2, 8LL * (int)a1 * HIDWORD(a1));
}
else
{
puts("Empty space to be copied from!");
v4 = 0;
}
}
else
{
puts("Fields are not the same size!");
v4 = 0;
}
}
else
{
puts("One of the fields is empty!");
v4 = 0;
}
return v4;
}

original_code:
int BackupMyStruct(MyStruct st, MyStruct stpre) {
    if (st.data == stpre.data || &st == &stpre) {
        printf("Cannot Copy to Itself!\n");
        return 0;
    }
    if (st.data == ((void *)0) || stpre.data == ((void *)0)) {
        printf("One of the fields is empty!\n");
        return 0;
    }
    if (st.ny != stpre.ny || st.nx != st.nx) {
        printf("Fields are not the same size!\n");
        return 0;
    }
    if (st.nx == 0 || st.ny == 0) {
        printf("Empty space to be copied from!\n");
        return 0;
    }
    memcpy(stpre.data, st.data, st.nx * st.ny * sizeof (st.data[0]));
    return st.nx * st.ny;
}

canonical_original_code:
int BackupMyStruct(struct MyStruct st, struct MyStruct stpre) {
    if (st.data == stpre.data || &st == &stpre) {
        printf("Cannot Copy to Itself!\n");
        return 0;
    }
    if (st.data == ((void *)0) || stpre.data == ((void *)0)) {
        printf("One of the fields is empty!\n");
        return 0;
    }
    if (st.ny != stpre.ny || st.nx != st.nx) {
        printf("Fields are not the same size!\n");
        return 0;
    }
    if (st.nx == 0 || st.ny == 0) {
        printf("Empty space to be copied from!\n");
        return 0;
    }
    memcpy(stpre.data, st.data, st.nx * st.ny * sizeof (st.data[0]));
    return st.nx * st.ny;
}

variable_types:
stpre
struct MyStruct