decompiled_code:
void __fastcall iposix_gid_free(__int64 a1)
{
if ( !a1 )
_assert_fail("gid != NULL", "install-posix.c", 0x76u, "iposix_gid_free");
}

canonical_decompiled_code:
void __fastcall func11(__int64 a1)
{
if ( !a1 )
_assert_fail("gid != NULL", "install-posix.c", 0x76u, "iposix_gid_free");
}

original_code:
static void
iposix_gid_free (group_id_t *gid)
{
  ((void) sizeof ((gid != ((void *)0)) ? 1 : 0), __extension__ ({ if (gid != ((void *)0)) ; else __assert_fail ("gid != NULL", "install-posix.c", 118, __extension__ __PRETTY_FUNCTION__); }));
}

canonical_original_code:
static void iposix_gid_free(struct group_id_t *gid)
{
  ((void) sizeof ((gid != ((void *)0)) ? 1 : 0), __extension__ ({ if (gid != ((void *)0)) ; else __assert_fail ("gid != NULL", "install-posix.c", 118, __extension__ __PRETTY_FUNCTION__); }));
}

variable_types:
gid
struct group_id_t { int value; } *


decompiled_code:
_BOOL8 __fastcall iposix_file_link(const char *a1, const char *a2)
{
if ( !a1 )
_assert_fail("src != NULL", "install-posix.c", 0x112u, "iposix_file_link");
if ( !a2 )
_assert_fail("dst != NULL", "install-posix.c", 0x113u, "iposix_file_link");
return symlink(a1, a2) != -1;
}

canonical_decompiled_code:
_BOOL8 __fastcall func12(const char *a1, const char *a2)
{
if ( !a1 )
_assert_fail("src != NULL", "install-posix.c", 0x112u, "iposix_file_link");
if ( !a2 )
_assert_fail("dst != NULL", "install-posix.c", 0x113u, "iposix_file_link");
return symlink(a1, a2) != -1;
}

original_code:
static int
iposix_file_link (const char *src, const char *dst)
{
  ((void) sizeof ((src != ((void *)0)) ? 1 : 0), __extension__ ({ if (src != ((void *)0)) ; else __assert_fail ("src != NULL", "install-posix.c", 274, __extension__ __PRETTY_FUNCTION__); }));
  ((void) sizeof ((dst != ((void *)0)) ? 1 : 0), __extension__ ({ if (dst != ((void *)0)) ; else __assert_fail ("dst != NULL", "install-posix.c", 275, __extension__ __PRETTY_FUNCTION__); }));
  if (symlink (src, dst) == -1) return 0;
  return 1;
}

canonical_original_code:
static int iposix_file_link(char *src, char *dst)
{
  ((void) sizeof ((src != ((void *)0)) ? 1 : 0), __extension__ ({ if (src != ((void *)0)) ; else __assert_fail ("src != NULL", "install-posix.c", 274, __extension__ __PRETTY_FUNCTION__); }));
  ((void) sizeof ((dst != ((void *)0)) ? 1 : 0), __extension__ ({ if (dst != ((void *)0)) ; else __assert_fail ("dst != NULL", "install-posix.c", 275, __extension__ __PRETTY_FUNCTION__); }));
  if (symlink (src, dst) == -1) return 0;
  return 1;
}

variable_types:
src
char *

variable_types:
dst
char *

return_type: int


decompiled_code:
__int64 __fastcall iposix_file_size(const char *a1, __off_t *a2)
{
int v2; // er8
__int64 result; // rax
struct stat v4; // [rsp+0h] [rbp-98h] BYREF

if ( !a1 )
_assert_fail("file != NULL", "install-posix.c", 0x106u, "iposix_file_size");
if ( !a2 )
_assert_fail("size != NULL", "install-posix.c", 0x107u, "iposix_file_size");
v2 = stat(a1, &v4);
result = 0LL;
if ( v2 != -1 )
{
*a2 = v4.st_size;
result = 1LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func13(const char *a1, __off_t *a2)
{
int v2; // er8
__int64 result; // rax
struct stat v4; // [rsp+0h] [rbp-98h] BYREF

if ( !a1 )
_assert_fail("file != NULL", "install-posix.c", 0x106u, "iposix_file_size");
if ( !a2 )
_assert_fail("size != NULL", "install-posix.c", 0x107u, "iposix_file_size");
v2 = stat(a1, &v4);
result = 0LL;
if ( v2 != -1 )
{
*a2 = v4.st_size;
result = 1LL;
}
return result;
}

original_code:
static int
iposix_file_size (const char *file, size_t *size)
{
  struct stat sb;
  ((void) sizeof ((file != ((void *)0)) ? 1 : 0), __extension__ ({ if (file != ((void *)0)) ; else __assert_fail ("file != NULL", "install-posix.c", 262, __extension__ __PRETTY_FUNCTION__); }));
  ((void) sizeof ((size != ((void *)0)) ? 1 : 0), __extension__ ({ if (size != ((void *)0)) ; else __assert_fail ("size != NULL", "install-posix.c", 263, __extension__ __PRETTY_FUNCTION__); }));
  if (stat (file, &sb) == -1) return 0;
  *size = sb.st_size;
  return 1;
}

canonical_original_code:
static int iposix_file_size(char *file, unsigned long *size)
{
  struct stat sb;
  ((void) sizeof ((file != ((void *)0)) ? 1 : 0), __extension__ ({ if (file != ((void *)0)) ; else __assert_fail ("file != NULL", "install-posix.c", 262, __extension__ __PRETTY_FUNCTION__); }));
  ((void) sizeof ((size != ((void *)0)) ? 1 : 0), __extension__ ({ if (size != ((void *)0)) ; else __assert_fail ("size != NULL", "install-posix.c", 263, __extension__ __PRETTY_FUNCTION__); }));
  if (stat (file, &sb) == -1) return 0;
  *size = sb.st_size;
  return 1;
}

variable_types:
file
char *

variable_types:
size
unsigned long *

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

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 iposix_file_ownership_get(const char *a1, __uid_t *a2, __gid_t *a3)
{
int v4; // er8
__int64 result; // rax
struct stat v6; // [rsp+0h] [rbp-A8h] BYREF

if ( !a1 )
_assert_fail("file != NULL", "install-posix.c", 0xF6u, "iposix_file_ownership_get");
if ( !a2 )
_assert_fail("uid != NULL", "install-posix.c", 0xF7u, "iposix_file_ownership_get");
if ( !a3 )
_assert_fail("gid != NULL", "install-posix.c", 0xF8u, "iposix_file_ownership_get");
v4 = stat(a1, &v6);
result = 0LL;
if ( v4 != -1 )
{
*a2 = v6.st_uid;
*a3 = v6.st_gid;
result = 1LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func14(const char *a1, __uid_t *a2, __gid_t *a3)
{
int v4; // er8
__int64 result; // rax
struct stat v6; // [rsp+0h] [rbp-A8h] BYREF

if ( !a1 )
_assert_fail("file != NULL", "install-posix.c", 0xF6u, "iposix_file_ownership_get");
if ( !a2 )
_assert_fail("uid != NULL", "install-posix.c", 0xF7u, "iposix_file_ownership_get");
if ( !a3 )
_assert_fail("gid != NULL", "install-posix.c", 0xF8u, "iposix_file_ownership_get");
v4 = stat(a1, &v6);
result = 0LL;
if ( v4 != -1 )
{
*a2 = v6.st_uid;
*a3 = v6.st_gid;
result = 1LL;
}
return result;
}

original_code:
static int
iposix_file_ownership_get (const char *file, user_id_t *uid, group_id_t *gid)
{
  struct stat sb;
  ((void) sizeof ((file != ((void *)0)) ? 1 : 0), __extension__ ({ if (file != ((void *)0)) ; else __assert_fail ("file != NULL", "install-posix.c", 246, __extension__ __PRETTY_FUNCTION__); }));
  ((void) sizeof ((uid != ((void *)0)) ? 1 : 0), __extension__ ({ if (uid != ((void *)0)) ; else __assert_fail ("uid != NULL", "install-posix.c", 247, __extension__ __PRETTY_FUNCTION__); }));
  ((void) sizeof ((gid != ((void *)0)) ? 1 : 0), __extension__ ({ if (gid != ((void *)0)) ; else __assert_fail ("gid != NULL", "install-posix.c", 248, __extension__ __PRETTY_FUNCTION__); }));
  if (stat (file, &sb) == -1) return 0;
  uid->value = sb.st_uid;
  gid->value = sb.st_gid;
  return 1;
}

canonical_original_code:
static int iposix_file_ownership_get(char *file, struct user_id_t *uid, struct group_id_t *gid)
{
  struct stat sb;
  ((void) sizeof ((file != ((void *)0)) ? 1 : 0), __extension__ ({ if (file != ((void *)0)) ; else __assert_fail ("file != NULL", "install-posix.c", 246, __extension__ __PRETTY_FUNCTION__); }));
  ((void) sizeof ((uid != ((void *)0)) ? 1 : 0), __extension__ ({ if (uid != ((void *)0)) ; else __assert_fail ("uid != NULL", "install-posix.c", 247, __extension__ __PRETTY_FUNCTION__); }));
  ((void) sizeof ((gid != ((void *)0)) ? 1 : 0), __extension__ ({ if (gid != ((void *)0)) ; else __assert_fail ("gid != NULL", "install-posix.c", 248, __extension__ __PRETTY_FUNCTION__); }));
  if (stat (file, &sb) == -1) return 0;
  uid->value = sb.st_uid;
  gid->value = sb.st_gid;
  return 1;
}

variable_types:
uid
struct user_id_t { int value; } *

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


decompiled_code:
__int64 __fastcall iposix_file_mode_get(const char *a1, int *a2)
{
int v2; // er8
__int64 result; // rax
struct stat v4; // [rsp+0h] [rbp-98h] BYREF

if ( !a1 )
_assert_fail("file != NULL", "install-posix.c", 0xE0u, "iposix_file_mode_get");
if ( !a2 )
_assert_fail("mode != NULL", "install-posix.c", 0xE1u, "iposix_file_mode_get");
v2 = stat(a1, &v4);
result = 0LL;
if ( v2 != -1 )
{
*a2 = v4.st_mode & 0x1ED;
result = 1LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func15(const char *a1, int *a2)
{
int v2; // er8
__int64 result; // rax
struct stat v4; // [rsp+0h] [rbp-98h] BYREF

if ( !a1 )
_assert_fail("file != NULL", "install-posix.c", 0xE0u, "iposix_file_mode_get");
if ( !a2 )
_assert_fail("mode != NULL", "install-posix.c", 0xE1u, "iposix_file_mode_get");
v2 = stat(a1, &v4);
result = 0LL;
if ( v2 != -1 )
{
*a2 = v4.st_mode & 0x1ED;
result = 1LL;
}
return result;
}

original_code:
static int
iposix_file_mode_get (const char *file, permissions_t *mode)
{
  struct stat sb;
  ((void) sizeof ((file != ((void *)0)) ? 1 : 0), __extension__ ({ if (file != ((void *)0)) ; else __assert_fail ("file != NULL", "install-posix.c", 224, __extension__ __PRETTY_FUNCTION__); }));
  ((void) sizeof ((mode != ((void *)0)) ? 1 : 0), __extension__ ({ if (mode != ((void *)0)) ; else __assert_fail ("mode != NULL", "install-posix.c", 225, __extension__ __PRETTY_FUNCTION__); }));
  if (stat (file, &sb) == -1) return 0;
  mode->value = sb.st_mode & 0755;
  return 1;
}

canonical_original_code:
static int iposix_file_mode_get(char *file, struct permissions_t *mode)
{
  struct stat sb;
  ((void) sizeof ((file != ((void *)0)) ? 1 : 0), __extension__ ({ if (file != ((void *)0)) ; else __assert_fail ("file != NULL", "install-posix.c", 224, __extension__ __PRETTY_FUNCTION__); }));
  ((void) sizeof ((mode != ((void *)0)) ? 1 : 0), __extension__ ({ if (mode != ((void *)0)) ; else __assert_fail ("mode != NULL", "install-posix.c", 225, __extension__ __PRETTY_FUNCTION__); }));
  if (stat (file, &sb) == -1) return 0;
  mode->value = sb.st_mode & 0755;
  return 1;
}

variable_types: struct permissions_t { unsigned int value; } *


decompiled_code:
_BOOL8 __fastcall iposix_file_ownership_set(const char *a1, __uid_t a2, __gid_t a3)
{
if ( !a1 )
_assert_fail("file != NULL", "install-posix.c", 0xEBu, "iposix_file_ownership_set");
return chown(a1, a2, a3) != -1;
}

canonical_decompiled_code:
_BOOL8 __fastcall func16(const char *a1, __uid_t a2, __gid_t a3)
{
if ( !a1 )
_assert_fail("file != NULL", "install-posix.c", 0xEBu, "iposix_file_ownership_set");
return chown(a1, a2, a3) != -1;
}

original_code:
static int
iposix_file_ownership_set (const char *file, user_id_t uid, group_id_t gid)
{
  ((void) sizeof ((file != ((void *)0)) ? 1 : 0), __extension__ ({ if (file != ((void *)0)) ; else __assert_fail ("file != NULL", "install-posix.c", 235, __extension__ __PRETTY_FUNCTION__); }));
  if (chown (file, uid.value, gid.value) == -1) return 0;
  return 1;
}

canonical_original_code:
static int iposix_file_ownership_set(char *file, struct user_id_t uid, struct group_id_t gid)
{
  ((void) sizeof ((file != ((void *)0)) ? 1 : 0), __extension__ ({ if (file != ((void *)0)) ; else __assert_fail ("file != NULL", "install-posix.c", 235, __extension__ __PRETTY_FUNCTION__); }));
  if (chown (file, uid.value, gid.value) == -1) return 0;
  return 1;
}

variable_types:
uid
struct user_id_t { int value; }

variable_types:
gid
struct group_id_t { int value; }

user_defined_types:
struct user_id_t { int value; }
struct group_id_t { int value; }


decompiled_code:
_BOOL8 __fastcall iposix_file_mode_set(const char *a1, __mode_t a2)
{
if ( !a1 )
_assert_fail("file != NULL", "install-posix.c", 0xD6u, "iposix_file_mode_set");
return chmod(a1, a2) == 0;
}

canonical_decompiled_code:
_BOOL8 __fastcall func17(const char *a1, __mode_t a2)
{
if ( !a1 )
_assert_fail("file != NULL", "install-posix.c", 0xD6u, "iposix_file_mode_set");
return chmod(a1, a2) == 0;
}

original_code:
static int
iposix_file_mode_set (const char *file, permissions_t mode)
{
  ((void) sizeof ((file != ((void *)0)) ? 1 : 0), __extension__ ({ if (file != ((void *)0)) ; else __assert_fail ("file != NULL", "install-posix.c", 214, __extension__ __PRETTY_FUNCTION__); }));
  return chmod (file, mode.value) == 0;
}

canonical_original_code:
static int iposix_file_mode_set(char *file, struct permissions_t mode)
{
  ((void) sizeof ((file != ((void *)0)) ? 1 : 0), __extension__ ({ if (file != ((void *)0)) ; else __assert_fail ("file != NULL", "install-posix.c", 214, __extension__ __PRETTY_FUNCTION__); }));
  return chmod (file, mode.value) == 0;
}

variable_types: struct permissions_t { unsigned int value; }


decompiled_code:
_BOOL8 __fastcall iposix_mkdir(const char *a1, __mode_t a2)
{
if ( !a1 )
_assert_fail("dir != NULL", "install-posix.c", 0xCBu, "iposix_mkdir");
return mkdir(a1, a2) == 0;
}

canonical_decompiled_code:
_BOOL8 __fastcall func18(const char *a1, __mode_t a2)
{
if ( !a1 )
_assert_fail("dir != NULL", "install-posix.c", 0xCBu, "iposix_mkdir");
return mkdir(a1, a2) == 0;
}

original_code:
static int
iposix_mkdir (const char *dir, permissions_t mode)
{
  ((void) sizeof ((dir != ((void *)0)) ? 1 : 0), __extension__ ({ if (dir != ((void *)0)) ; else __assert_fail ("dir != NULL", "install-posix.c", 203, __extension__ __PRETTY_FUNCTION__); }));
  return mkdir (dir, mode.value) == 0;
}

canonical_original_code:
static int iposix_mkdir(char *dir, struct permissions_t mode)
{
  ((void) sizeof ((dir != ((void *)0)) ? 1 : 0), __extension__ ({ if (dir != ((void *)0)) ; else __assert_fail ("dir != NULL", "install-posix.c", 203, __extension__ __PRETTY_FUNCTION__); }));
  return mkdir (dir, mode.value) == 0;
}

variable_types:
dir
char *

user_defined_types: struct permissions_t { unsigned int value; }


decompiled_code:
__int64 __fastcall iposix_uid_lookup(const char *a1, __uid_t *a2)
{
struct passwd *v2; // rax

if ( !a1 )
_assert_fail("user != NULL", "install-posix.c", 0xA4u, "iposix_uid_lookup");
if ( !a2 )
_assert_fail("uid != NULL", "install-posix.c", 0xA5u, "iposix_uid_lookup");
v2 = getpwnam(a1);
if ( !v2 )
return 0LL;
*a2 = v2->pw_uid;
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func19(const char *a1, __uid_t *a2)
{
struct passwd *v2; // rax

if ( !a1 )
_assert_fail("user != NULL", "install-posix.c", 0xA4u, "iposix_uid_lookup");
if ( !a2 )
_assert_fail("uid != NULL", "install-posix.c", 0xA5u, "iposix_uid_lookup");
v2 = getpwnam(a1);
if ( !v2 )
return 0LL;
*a2 = v2->pw_uid;
return 1LL;
}

original_code:
static int
iposix_uid_lookup (const char *user, user_id_t *uid)
{
  struct passwd *pwd;
  ((void) sizeof ((user != ((void *)0)) ? 1 : 0), __extension__ ({ if (user != ((void *)0)) ; else __assert_fail ("user != NULL", "install-posix.c", 164, __extension__ __PRETTY_FUNCTION__); }));
  ((void) sizeof ((uid != ((void *)0)) ? 1 : 0), __extension__ ({ if (uid != ((void *)0)) ; else __assert_fail ("uid != NULL", "install-posix.c", 165, __extension__ __PRETTY_FUNCTION__); }));
  pwd = getpwnam (user);
  if (!pwd) return 0;
  uid->value = pwd->pw_uid;
  return 1;
}

canonical_original_code:
static int iposix_uid_lookup(char *user, struct user_id_t *uid)
{
  struct passwd *pwd;
  ((void) sizeof ((user != ((void *)0)) ? 1 : 0), __extension__ ({ if (user != ((void *)0)) ; else __assert_fail ("user != NULL", "install-posix.c", 164, __extension__ __PRETTY_FUNCTION__); }));
  ((void) sizeof ((uid != ((void *)0)) ? 1 : 0), __extension__ ({ if (uid != ((void *)0)) ; else __assert_fail ("uid != NULL", "install-posix.c", 165, __extension__ __PRETTY_FUNCTION__); }));
  pwd = getpwnam (user);
  if (!pwd) return 0;
  uid->value = pwd->pw_uid;
  return 1;
}

variable_types:
user
char *

variable_types: struct passwd { char *pw_name; char *pw_passwd; unsigned int pw_uid; unsigned int pw_gid; char *pw_gecos; char *pw_dir; char *pw_shell; } *


decompiled_code:
__int64 __fastcall iposix_uid_current(__uid_t *a1)
{
if ( !a1 )
_assert_fail("uid != NULL", "install-posix.c", 0x99u, "iposix_uid_current");
*a1 = getuid();
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func20(__uid_t *a1)
{
if ( !a1 )
_assert_fail("uid != NULL", "install-posix.c", 0x99u, "iposix_uid_current");
*a1 = getuid();
return 1LL;
}

original_code:
static int
iposix_uid_current (user_id_t *uid)
{
  ((void) sizeof ((uid != ((void *)0)) ? 1 : 0), __extension__ ({ if (uid != ((void *)0)) ; else __assert_fail ("uid != NULL", "install-posix.c", 153, __extension__ __PRETTY_FUNCTION__); }));
  uid->value = getuid ();
  return 1;
}

canonical_original_code:
static int iposix_uid_current(struct user_id_t *uid)
{
  ((void) sizeof ((uid != ((void *)0)) ? 1 : 0), __extension__ ({ if (uid != ((void *)0)) ; else __assert_fail ("uid != NULL", "install-posix.c", 153, __extension__ __PRETTY_FUNCTION__); }));
  uid->value = getuid ();
  return 1;
}


decompiled_code:
__int64 __fastcall iposix_uid_scan(__int64 a1, __int64 a2)
{
if ( !a1 )
_assert_fail("buffer != NULL", "install-posix.c", 0x8Fu, "iposix_uid_scan");
if ( !a2 )
_assert_fail("uid != NULL", "install-posix.c", 0x90u, "iposix_uid_scan");
return _isoc99_sscanf(a1, "%d", a2);
}

canonical_decompiled_code:
__int64 __fastcall func21(__int64 a1, __int64 a2)
{
if ( !a1 )
_assert_fail("buffer != NULL", "install-posix.c", 0x8Fu, "iposix_uid_scan");
if ( !a2 )
_assert_fail("uid != NULL", "install-posix.c", 0x90u, "iposix_uid_scan");
return _isoc99_sscanf(a1, "%d", a2);
}

original_code:
static unsigned int
iposix_uid_scan (const char *buffer, user_id_t *uid)
{
  ((void) sizeof ((buffer != ((void *)0)) ? 1 : 0), __extension__ ({ if (buffer != ((void *)0)) ; else __assert_fail ("buffer != NULL", "install-posix.c", 143, __extension__ __PRETTY_FUNCTION__); }));
  ((void) sizeof ((uid != ((void *)0)) ? 1 : 0), __extension__ ({ if (uid != ((void *)0)) ; else __assert_fail ("uid != NULL", "install-posix.c", 144, __extension__ __PRETTY_FUNCTION__); }));
  unsigned int size = sscanf (buffer, "%d", &uid->value);
  return size;
}

canonical_original_code:
static unsigned int iposix_uid_scan(char *buffer, struct user_id_t *uid)
{
  ((void) sizeof ((buffer != ((void *)0)) ? 1 : 0), __extension__ ({ if (buffer != ((void *)0)) ; else __assert_fail ("buffer != NULL", "install-posix.c", 143, __extension__ __PRETTY_FUNCTION__); }));
  ((void) sizeof ((uid != ((void *)0)) ? 1 : 0), __extension__ ({ if (uid != ((void *)0)) ; else __assert_fail ("uid != NULL", "install-posix.c", 144, __extension__ __PRETTY_FUNCTION__); }));
  unsigned int size = sscanf (buffer, "%d", &uid->value);
  return size;
}

variable_types:
buffer
char *

variable_types:
size
unsigned int

return_type: unsigned int


decompiled_code:
__int64 __fastcall iposix_gid_scan(__int64 a1, __int64 a2)
{
if ( !a1 )
_assert_fail("buffer != NULL", "install-posix.c", 0x4Eu, "iposix_gid_scan");
if ( !a2 )
_assert_fail("gid != NULL", "install-posix.c", 0x4Fu, "iposix_gid_scan");
return _isoc99_sscanf(a1, "%d", a2);
}

canonical_decompiled_code:
__int64 __fastcall func22(__int64 a1, __int64 a2)
{
if ( !a1 )
_assert_fail("buffer != NULL", "install-posix.c", 0x4Eu, "iposix_gid_scan");
if ( !a2 )
_assert_fail("gid != NULL", "install-posix.c", 0x4Fu, "iposix_gid_scan");
return _isoc99_sscanf(a1, "%d", a2);
}

original_code:
static unsigned int
iposix_gid_scan (const char *buffer, group_id_t *gid)
{
  ((void) sizeof ((buffer != ((void *)0)) ? 1 : 0), __extension__ ({ if (buffer != ((void *)0)) ; else __assert_fail ("buffer != NULL", "install-posix.c", 78, __extension__ __PRETTY_FUNCTION__); }));
  ((void) sizeof ((gid != ((void *)0)) ? 1 : 0), __extension__ ({ if (gid != ((void *)0)) ; else __assert_fail ("gid != NULL", "install-posix.c", 79, __extension__ __PRETTY_FUNCTION__); }));
  unsigned int size = sscanf (buffer, "%d", &gid->value);
  return size;
}

canonical_original_code:
static unsigned int iposix_gid_scan(char *buffer, struct group_id_t *gid)
{
  ((void) sizeof ((buffer != ((void *)0)) ? 1 : 0), __extension__ ({ if (buffer != ((void *)0)) ; else __assert_fail ("buffer != NULL", "install-posix.c", 78, __extension__ __PRETTY_FUNCTION__); }));
  ((void) sizeof ((gid != ((void *)0)) ? 1 : 0), __extension__ ({ if (gid != ((void *)0)) ; else __assert_fail ("gid != NULL", "install-posix.c", 79, __extension__ __PRETTY_FUNCTION__); }));
  unsigned int size = sscanf (buffer, "%d", &gid->value);
  return size;
}


decompiled_code:
int __fastcall iposix_uid_format(char *a1, unsigned int a2)
{
if ( !a1 )
_assert_fail("buffer != NULL", "install-posix.c", 0x86u, "iposix_uid_format");
return snprintf(a1, 0x20uLL, "%d", a2);
}

canonical_decompiled_code:
int __fastcall func23(char *a1, unsigned int a2)
{
if ( !a1 )
_assert_fail("buffer != NULL", "install-posix.c", 0x86u, "iposix_uid_format");
return snprintf(a1, 0x20uLL, "%d", a2);
}

original_code:
static unsigned int
iposix_uid_format (char *buffer, user_id_t uid)
{
  ((void) sizeof ((buffer != ((void *)0)) ? 1 : 0), __extension__ ({ if (buffer != ((void *)0)) ; else __assert_fail ("buffer != NULL", "install-posix.c", 134, __extension__ __PRETTY_FUNCTION__); }));
  unsigned int size = snprintf (buffer, (sizeof (int) << 3), "%d", uid.value);
  return size;
}

canonical_original_code:
static unsigned int iposix_uid_format(char *buffer, struct user_id_t uid)
{
  ((void) sizeof ((buffer != ((void *)0)) ? 1 : 0), __extension__ ({ if (buffer != ((void *)0)) ; else __assert_fail ("buffer != NULL", "install-posix.c", 134, __extension__ __PRETTY_FUNCTION__); }));
  unsigned int size = snprintf (buffer, (sizeof (int) << 3), "%d", uid.value);
  return size;
}


decompiled_code:
int __fastcall iposix_gid_format(char *a1, unsigned int a2)
{
if ( !a1 )
_assert_fail("buffer != NULL", "install-posix.c", 0x45u, "iposix_gid_format");
return snprintf(a1, 0x20uLL, "%d", a2);
}

canonical_decompiled_code:
int __fastcall func24(char *a1, unsigned int a2)
{
if ( !a1 )
_assert_fail("buffer != NULL", "install-posix.c", 0x45u, "iposix_gid_format");
return snprintf(a1, 0x20uLL, "%d", a2);
}

original_code:
static unsigned int
iposix_gid_format (char *buffer, group_id_t gid)
{
  ((void) sizeof ((buffer != ((void *)0)) ? 1 : 0), __extension__ ({ if (buffer != ((void *)0)) ; else __assert_fail ("buffer != NULL", "install-posix.c", 69, __extension__ __PRETTY_FUNCTION__); }));
  unsigned int size = snprintf (buffer, (sizeof (int) << 3), "%d", gid.value);
  return size;
}

canonical_original_code:
static unsigned int iposix_gid_format(char *buffer, struct group_id_t gid)
{
  ((void) sizeof ((buffer != ((void *)0)) ? 1 : 0), __extension__ ({ if (buffer != ((void *)0)) ; else __assert_fail ("buffer != NULL", "install-posix.c", 69, __extension__ __PRETTY_FUNCTION__); }));
  unsigned int size = snprintf (buffer, (sizeof (int) << 3), "%d", gid.value);
  return size;
}


decompiled_code:
__int64 __fastcall iposix_gid_lookup(const char *a1, __gid_t *a2)
{
struct group *v2; // rax

if ( !a1 )
_assert_fail("group != NULL", "install-posix.c", 0x63u, "iposix_gid_lookup");
if ( !a2 )
_assert_fail("gid != NULL", "install-posix.c", 0x64u, "iposix_gid_lookup");
v2 = getgrnam(a1);
if ( !v2 )
return 0LL;
*a2 = v2->gr_gid;
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func25(const char *a1, __gid_t *a2)
{
struct group *v2; // rax

if ( !a1 )
_assert_fail("group != NULL", "install-posix.c", 0x63u, "iposix_gid_lookup");
if ( !a2 )
_assert_fail("gid != NULL", "install-posix.c", 0x64u, "iposix_gid_lookup");
v2 = getgrnam(a1);
if ( !v2 )
return 0LL;
*a2 = v2->gr_gid;
return 1LL;
}

original_code:
static int
iposix_gid_lookup (const char *group, group_id_t *gid)
{
  struct group *grp;
  ((void) sizeof ((group != ((void *)0)) ? 1 : 0), __extension__ ({ if (group != ((void *)0)) ; else __assert_fail ("group != NULL", "install-posix.c", 99, __extension__ __PRETTY_FUNCTION__); }));
  ((void) sizeof ((gid != ((void *)0)) ? 1 : 0), __extension__ ({ if (gid != ((void *)0)) ; else __assert_fail ("gid != NULL", "install-posix.c", 100, __extension__ __PRETTY_FUNCTION__); }));
  grp = getgrnam (group);
  if (!grp) return 0;
  gid->value = grp->gr_gid;
  return 1;
}

canonical_original_code:
static int iposix_gid_lookup(char *group, struct group_id_t *gid)
{
  struct group *grp;
  ((void) sizeof ((group != ((void *)0)) ? 1 : 0), __extension__ ({ if (group != ((void *)0)) ; else __assert_fail ("group != NULL", "install-posix.c", 99, __extension__ __PRETTY_FUNCTION__); }));
  ((void) sizeof ((gid != ((void *)0)) ? 1 : 0), __extension__ ({ if (gid != ((void *)0)) ; else __assert_fail ("gid != NULL", "install-posix.c", 100, __extension__ __PRETTY_FUNCTION__); }));
  grp = getgrnam (group);
  if (!grp) return 0;
  gid->value = grp->gr_gid;
  return 1;
}

variable_types:
group
char *

variable_types: struct group { char *gr_name; char *gr_passwd; unsigned int gr_gid; char **gr_mem; } *


decompiled_code:
__int64 __fastcall iposix_gid_current(__gid_t *a1)
{
if ( !a1 )
_assert_fail("gid != NULL", "install-posix.c", 0x58u, "iposix_gid_current");
*a1 = getgid();
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func26(__gid_t *a1)
{
if ( !a1 )
_assert_fail("gid != NULL", "install-posix.c", 0x58u, "iposix_gid_current");
*a1 = getgid();
return 1LL;
}

original_code:
static int
iposix_gid_current (group_id_t *gid)
{
  ((void) sizeof ((gid != ((void *)0)) ? 1 : 0), __extension__ ({ if (gid != ((void *)0)) ; else __assert_fail ("gid != NULL", "install-posix.c", 88, __extension__ __PRETTY_FUNCTION__); }));
  gid->value = getgid ();
  return 1;
}

canonical_original_code:
static int iposix_gid_current(struct group_id_t *gid)
{
  ((void) sizeof ((gid != ((void *)0)) ? 1 : 0), __extension__ ({ if (gid != ((void *)0)) ; else __assert_fail ("gid != NULL", "install-posix.c", 88, __extension__ __PRETTY_FUNCTION__); }));
  gid->value = getgid ();
  return 1;
}

variable_types:
gid
struct group_id_t { int value; } *


decompiled_code:
int *iposix_error_reset()
{
int *result; // rax

result = _errno_location();
*result = 0;
return result;
}

canonical_decompiled_code:
int *func27()
{
int *result; // rax

result = _errno_location();
*result = 0;
return result;
}

original_code:
static void
iposix_error_reset (void)
{
  (*__errno_location ()) = 0;
}

canonical_original_code:
static void iposix_error_reset()
{
  (*__errno_location ()) = 0;
}

return_type: void


decompiled_code:
__int64 iposix_error_current()
{
return *_errno_location();
}

canonical_decompiled_code:
__int64 func28()
{
return *_errno_location();
}

original_code:
static install_error_t
iposix_error_current (void)
{
  install_error_t e;
  e.value = (unsigned long) (*__errno_location ());
  return e;
}

canonical_original_code:
static struct install_error_t iposix_error_current()
{
  struct install_error_t e;
  e.value = (unsigned long) (*__errno_location ());
  return e;
}

variable_types: struct install_error_t { unsigned long value; }


decompiled_code:
// attributes: thunk
char *iposix_error_message(int errnum)
{
return strerror(errnum);
}

canonical_decompiled_code:
char *func29(int errnum)
{
return strerror(errnum);
}

original_code:
static const char *
iposix_error_message (install_error_t error)
{
  return strerror (error.value);
}

canonical_original_code:
static char *iposix_error_message(struct install_error_t error)
{
  return strerror (error.value);
}

return_type: char *

user_defined_types: struct install_error_t { unsigned long value; }


decompiled_code:
char *iposix_error_message_current()
{
int v0; // eax

v0 = iposix_error_current();
return iposix_error_message(v0);
}

canonical_decompiled_code:
char *func30()
{
int v0; // eax

v0 = func28();
return func29(v0);
}

original_code:
static const char *
iposix_error_message_current (void)
{
  return iposix_error_message (iposix_error_current ());
}

canonical_original_code:
static char *iposix_error_message_current()
{
  return iposix_error_message (iposix_error_current ());
}


decompiled_code:
int __fastcall cb_info(const char *a1)
{
return fprintf(stderr, "%s\n", a1);
}

canonical_decompiled_code:
int __fastcall func0(const char *a1)
{
return fprintf(stderr, "%s\n", a1);
}

original_code:
static void
cb_info (const char *str, void *data)
{
  (void) fprintf (stderr, "%s\n", str);
}

canonical_original_code:
static void cb_info(char *str, void *data)
{
  (void) fprintf (stderr, "%s\n", str);
}

variable_types:
str
char *

variable_types:
data
void *


decompiled_code:
int __fastcall cb_warn(const char *a1)
{
return fprintf(stderr, "%s: warning: %s\n", "instchk", a1);
}

canonical_decompiled_code:
int __fastcall func1(const char *a1)
{
return fprintf(stderr, "%s: warning: %s\n", "instchk", a1);
}

original_code:
static void
cb_warn (const char *str, void *data)
{
  (void) fprintf (stderr, "%s: warning: %s\n", progname, str);
}

canonical_original_code:
static void cb_warn(char *str, void *data)
{
  (void) fprintf (stderr, "%s: warning: %s\n", progname, str);
}


repo: ioerror/libmsr

decompiled_code:
__int64 __fastcall msr_dumpbits(unsigned __int8 *a1, int a2)
{
unsigned __int8 *v2; // rbp
unsigned int v3; // ebx
bool v4; // cf
int v5; // eax

if ( a2 > 0 )
{
v2 = a1;
do
{
v3 = 7;
do
{
while ( 1 )
{
v5 = *v2;
if ( !_bittest(&v5, v3) )
break;
putchar(49);
v4 = v3-- == 0;
if ( v4 )
goto LABEL_7;
}
putchar(48);
v4 = v3-- == 0;
}
while ( !v4 );
LABEL_7:
++v2;
}
while ( &a1[a2 - 1 + 1] != v2 );
}
putchar(10);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func0(unsigned __int8 *a1, int a2)
{
unsigned __int8 *v2; // rbp
unsigned int v3; // ebx
bool v4; // cf
int v5; // eax

if ( a2 > 0 )
{
v2 = a1;
do
{
v3 = 7;
do
{
while ( 1 )
{
v5 = *v2;
if ( !_bittest(&v5, v3) )
break;
putchar(49);
v4 = v3-- == 0;
if ( v4 )
goto LABEL_7;
}
putchar(48);
v4 = v3-- == 0;
}
while ( !v4 );
LABEL_7:
++v2;
}
while ( &a1[a2 - 1 + 1] != v2 );
}
putchar(10);
return 0LL;
}

original_code:
int
msr_dumpbits (uint8_t * buf, int len)
{
 int bytes, i;
 for (bytes = 0; bytes < len; bytes++) {
  for (i = 7; i > -1; i--) {
   if (buf[bytes] & (1 << i))
    printf("1");
   else
    printf("0");
  }
 }
 printf ("\n");
 return (0);
}

canonical_original_code:
int msr_dumpbits(unsigned char *buf, int len)
{
 int bytes; int i;
 for (bytes = 0; bytes < len; bytes++) {
  for (i = 7; i > -1; i--) {
   if (buf[bytes] & (1 << i))
    printf("1");
   else
    printf("0");
  }
 }
 printf ("\n");
 return (0);
}

variable_types:
buf
unsigned char *

variable_types: len int

variable_types: bytes int

variable_types: i int


decompiled_code:
__int64 __fastcall msr_getbit(__int64 a1, unsigned __int8 a2, unsigned int a3)
{
__int64 v4; // rsi
__int64 v5; // rdx

v4 = a3;
v5 = 8 * (unsigned int)a2;
if ( (int)v5 >= (int)v4 )
return ((int)*(unsigned __int8 *)(a1 + (int)v4 / 8) >> (((unsigned int)((int)v4 >> 31) >> 29)
- ((((unsigned int)((int)v4 >> 31) >> 29) + v4) & 7)
+ 7)) & 1;
printf("%d > %d\n", v4, v5);
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, unsigned __int8 a2, unsigned int a3)
{
__int64 v4; // rsi
__int64 v5; // rdx

v4 = a3;
v5 = 8 * (unsigned int)a2;
if ( (int)v5 >= (int)v4 )
return ((int)*(unsigned __int8 *)(a1 + (int)v4 / 8) >> (((unsigned int)((int)v4 >> 31) >> 29)
- ((((unsigned int)((int)v4 >> 31) >> 29) + v4) & 7)
+ 7)) & 1;
printf("%d > %d\n", v4, v5);
return 0xFFFFFFFFLL;
}

original_code:
int
msr_getbit (uint8_t * buf, uint8_t len, int bit)
{
 int byte;
 int b;
 if (bit > (len * 8)) {
  printf ("%d > %d\n", bit, len * 8);
  return (-1);
 }
 byte = bit / 8;
 b = 7 - (bit % 8);
 if (buf[byte] & (1 << b))
  return (1);
 return (0);
}

canonical_original_code:
int msr_getbit(unsigned char *buf, unsigned char len, int bit)
{
 int byte;
 int b;
 if (bit > (len * 8)) {
  printf ("%d > %d\n", bit, len * 8);
  return (-1);
 }
 byte = bit / 8;
 b = 7 - (bit % 8);
 if (buf[byte] & (1 << b))
  return (1);
 return (0);
}

variable_types:
len
unsigned char

variable_types: bit int

variable_types: byte int

variable_types: b int


decompiled_code:
__int64 __fastcall msr_setbit(__int64 a1, unsigned __int8 a2, unsigned int a3, int a4)
{
__int64 v5; // rsi
__int64 v6; // rdx
char *v7; // rdi
char v8; // dl
int v9; // eax
__int64 result; // rax

v5 = a3;
v6 = 8 * (unsigned int)a2;
if ( (int)v6 < (int)v5 )
{
printf("%d > %d\n", v5, v6);
result = 0xFFFFFFFFLL;
}
else
{
v7 = (char *)(a1 + (int)v5 / 8);
v8 = *v7;
v9 = 1 << (((unsigned int)((int)v5 >> 31) >> 29) - ((((unsigned int)((int)v5 >> 31) >> 29) + v5) & 7) + 7);
if ( a4 )
*v7 = v8 | v9;
else
*v7 = v8 & ~(_BYTE)v9;
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, unsigned __int8 a2, unsigned int a3, int a4)
{
__int64 v5; // rsi
__int64 v6; // rdx
char *v7; // rdi
char v8; // dl
int v9; // eax
__int64 result; // rax

v5 = a3;
v6 = 8 * (unsigned int)a2;
if ( (int)v6 < (int)v5 )
{
printf("%d > %d\n", v5, v6);
result = 0xFFFFFFFFLL;
}
else
{
v7 = (char *)(a1 + (int)v5 / 8);
v8 = *v7;
v9 = 1 << (((unsigned int)((int)v5 >> 31) >> 29) - ((((unsigned int)((int)v5 >> 31) >> 29) + v5) & 7) + 7);
if ( a4 )
*v7 = v8 | v9;
else
*v7 = v8 & ~(_BYTE)v9;
result = 0LL;
}
return result;
}

original_code:
int
msr_setbit (uint8_t * buf, uint8_t len, int bit, int val)
{
 int byte;
 int b;
 if (bit > (len * 8)) {
  printf ("%d > %d\n", bit, len * 8);
  return (-1);
 }
 byte = bit / 8;
 b = 7 - (bit % 8);
 if (val)
  buf[byte] |= 1 << b;
 else
  buf[byte] &= ~(1 << b);
 return (0);
}

canonical_original_code:
int msr_setbit(unsigned char *buf, unsigned char len, int bit, int val)
{
 int byte;
 int b;
 if (bit > (len * 8)) {
  printf ("%d > %d\n", bit, len * 8);
  return (-1);
 }
 byte = bit / 8;
 b = 7 - (bit % 8);
 if (val)
  buf[byte] |= 1 << b;
 else
  buf[byte] &= ~(1 << b);
 return (0);
}

variable_types: val int


original_code:
int
msr_decode(uint8_t * inbuf, uint8_t inlen,
    uint8_t * outbuf, uint8_t * outlen, int bpc)
{
 uint8_t * b;
 uint8_t len;
 int ch = 0;
 char byte = 0;
 int i, x;
 len = inlen;
 b = inbuf;
 x = 0;
 for (i = 0; i < len * 8; i++) {
  byte |= msr_getbit (b, len, i) << ch;
  if (ch == (bpc - 1)) {
   byte &= ~(1 << ch);
   if (bpc < 7)
    byte |= 0x30;
   else {
    if (byte < 0x20)
     byte |= 0x20;
    else {
     byte |= 0x40;
     byte -= 0x20;
    }
   }
   outbuf[x] = byte;
   x++;
   if (x == *outlen)
    break;
   ch = 0;
   byte = 0;
  } else
   ch++;
 }
 if (x == *outlen)
  return (-1);
 *outlen = x;
 return (0);
}

canonical_original_code:
int msr_decode(unsigned char *inbuf, unsigned char inlen, unsigned char *outbuf, unsigned char *outlen, int bpc)
{
 unsigned char *b;
 unsigned char len;
 int ch = 0;
 char byte = 0;
 int i; int x;
 len = inlen;
 b = inbuf;
 x = 0;
 for (i = 0; i < len * 8; i++) {
  byte |= msr_getbit (b, len, i) << ch;
  if (ch == (bpc - 1)) {
   byte &= ~(1 << ch);
   if (bpc < 7)
    byte |= 0x30;
   else {
    if (byte < 0x20)
     byte |= 0x20;
    else {
     byte |= 0x40;
     byte -= 0x20;
    }
   }
   outbuf[x] = byte;
   x++;
   if (x == *outlen)
    break;
   ch = 0;
   byte = 0;
  } else
   ch++;
 }
 if (x == *outlen)
  return (-1);
 *outlen = x;
 return (0);
}

variable_types:
inbuf
unsigned char *

variable_types:
inlen
unsigned char

variable_types:
outbuf
unsigned char *

variable_types:
outlen
unsigned char *

variable_types: bpc int

variable_types:
b
unsigned char *

variable_types: ch int

variable_types: byte char

variable_types: x int


decompiled_code:
int __fastcall msr_pretty_printer_hex(__int64 a1, __int64 a2, __int64 a3, __int64 a4, __int64 a5, __int64 a6, char a7)
{
unsigned int v7; // er13
char *v8; // r12
int v9; // eax
char *v10; // rbx
__int64 v11; // rbp
__int64 v12; // rsi
int result; // eax

v7 = 0;
v8 = &a7;
do
{
printf("Track %d: \n", v7);
v9 = (unsigned __int8)v8[255];
if ( (_BYTE)v9 )
{
v10 = v8;
v11 = (__int64)&v8[v9 - 1 + 1];
do
{
v12 = (unsigned __int8)*v10++;
printf("%02x ", v12);
}
while ( v10 != (char *)v11 );
}
++v7;
v8 += 256;
result = putchar(10);
}
while ( v7 != 3 );
return result;
}

canonical_decompiled_code:
int __fastcall func4(__int64 a1, __int64 a2, __int64 a3, __int64 a4, __int64 a5, __int64 a6, char a7)
{
unsigned int v7; // er13
char *v8; // r12
int v9; // eax
char *v10; // rbx
__int64 v11; // rbp
__int64 v12; // rsi
int result; // eax

v7 = 0;
v8 = &a7;
do
{
printf("Track %d: \n", v7);
v9 = (unsigned __int8)v8[255];
if ( (_BYTE)v9 )
{
v10 = v8;
v11 = (__int64)&v8[v9 - 1 + 1];
do
{
v12 = (unsigned __int8)*v10++;
printf("%02x ", v12);
}
while ( v10 != (char *)v11 );
}
++v7;
v8 += 256;
result = putchar(10);
}
while ( v7 != 3 );
return result;
}

original_code:
void
msr_pretty_printer_hex (msr_tracks_t tracks)
{
 int track_number;
 for (track_number = 0; track_number < 3; track_number++) {
  int x;
  printf("Track %d: \n", track_number);
  for (x = 0; x < tracks.msr_tracks[track_number].msr_tk_len; x++)
   printf("%02x ", tracks.msr_tracks[track_number].msr_tk_data[x]);
  printf("\n");
 }
}

canonical_original_code:
void msr_pretty_printer_hex(struct msr_tracks tracks)
{
 int track_number;
 for (track_number = 0; track_number < 3; track_number++) {
  int x;
  printf("Track %d: \n", track_number);
  for (x = 0; x < tracks.msr_tracks[track_number].msr_tk_len; x++)
   printf("%02x ", tracks.msr_tracks[track_number].msr_tk_data[x]);
  printf("\n");
 }
}

variable_types: struct msr_tracks { struct msr_track { unsigned char msr_tk_data[255]; unsigned char msr_tk_len; } msr_tracks[3]; }

user_defined_types: struct msr_tracks { struct msr_track msr_tracks[3]; }


decompiled_code:
int __fastcall msr_pretty_printer_string(__int64 a1, __int64 a2, __int64 a3, __int64 a4, __int64 a5, __int64 a6, char a7)
{
unsigned int v7; // ebx
char *v8; // rbp
int result; // eax

v7 = 0;
v8 = &a7;
do
{
if ( v8[255] )
result = printf("Track %d: \n[%s]\n", v7, v8);
++v7;
v8 += 256;
}
while ( v7 != 3 );
return result;
}

canonical_decompiled_code:
int __fastcall func5(__int64 a1, __int64 a2, __int64 a3, __int64 a4, __int64 a5, __int64 a6, char a7)
{
unsigned int v7; // ebx
char *v8; // rbp
int result; // eax

v7 = 0;
v8 = &a7;
do
{
if ( v8[255] )
result = printf("Track %d: \n[%s]\n", v7, v8);
++v7;
v8 += 256;
}
while ( v7 != 3 );
return result;
}

original_code:
void
msr_pretty_printer_string (msr_tracks_t tracks)
{
 int track_number;
 for (track_number = 0; track_number < 3; track_number++) {
  if (tracks.msr_tracks[track_number].msr_tk_len)
   printf ("Track %d: \n[%s]\n", track_number,
   tracks.msr_tracks[track_number].msr_tk_data);
 }
}

canonical_original_code:
void msr_pretty_printer_string(struct msr_tracks tracks)
{
 int track_number;
 for (track_number = 0; track_number < 3; track_number++) {
  if (tracks.msr_tracks[track_number].msr_tk_len)
   printf ("Track %d: \n[%s]\n", track_number,
   tracks.msr_tracks[track_number].msr_tk_data);
 }
}

user_defined_types: struct msr_track { unsigned char msr_tk_data[255]; unsigned char msr_tk_len; }


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

v1 = a1;
LOBYTE(v1) = (unsigned __int8)a1 >> 7;
return (32 * (_BYTE)a1) & 0x40 | (8 * (_BYTE)a1) & 0x20 | (2 * (_BYTE)a1) & 0x10 | ((int)(unsigned __int8)a1 >> 1) & 8 | ((int)(unsigned __int8)a1 >> 3) & 4 | ((int)(unsigned __int8)a1 >> 5) & 2 | ((unsigned __int8)a1 << 7) | v1;
}

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

v1 = a1;
LOBYTE(v1) = (unsigned __int8)a1 >> 7;
return (32 * (_BYTE)a1) & 0x40 | (8 * (_BYTE)a1) & 0x20 | (2 * (_BYTE)a1) & 0x10 | ((int)(unsigned __int8)a1 >> 1) & 8 | ((int)(unsigned __int8)a1 >> 3) & 4 | ((int)(unsigned __int8)a1 >> 5) & 2 | ((unsigned __int8)a1 << 7) | v1;
}

variable_types:
byte
unsigned char

return_type: unsigned char


decompiled_code:
__int64 __fastcall msr_reverse_track(int a1, __int64 a2)
{
unsigned __int8 *v2; // rsi
unsigned int v3; // edi
unsigned __int8 *v4; // r8
_BYTE *v5; // r8
char v6; // r9
unsigned __int8 *v7; // r10

v2 = (unsigned __int8 *)(((__int64)a1 << 8) + a2);
do
{
v3 = *v2++;
msr_reverse_byte(v3);
*(v2 - 1) = msr_reverse_byte(*v4);
*v5 = v6;
}
while ( v2 != v7 );
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func7(int a1, __int64 a2)
{
unsigned __int8 *v2; // rsi
unsigned int v3; // edi
unsigned __int8 *v4; // r8
_BYTE *v5; // r8
char v6; // r9
unsigned __int8 *v7; // r10

v2 = (unsigned __int8 *)(((__int64)a1 << 8) + a2);
do
{
v3 = *v2++;
func6(v3);
*(v2 - 1) = func6(*v4);
*v5 = v6;
}
while ( v2 != v7 );
return 0LL;
}

original_code:
int
msr_reverse_track (int track_number, msr_tracks_t * tracks)
{
 int i;
 int status = 0;
 int bytes_to_shuffle;
 char first_byte;
 char last_byte;
 unsigned char * head;
 unsigned char * tail;
 bytes_to_shuffle = tracks->msr_tracks[track_number].msr_tk_len;
 for (i=0; i <= bytes_to_shuffle / 2; i++) {
  head = &tracks->msr_tracks[track_number].msr_tk_data[i];
  tail = &tracks->msr_tracks[track_number].msr_tk_data[(bytes_to_shuffle -1) -i];
  first_byte = msr_reverse_byte(*head);
  last_byte = msr_reverse_byte(*tail);
  *head = last_byte;
  *tail = first_byte;
 }
 return status;
}

canonical_original_code:
int msr_reverse_track(int track_number, struct msr_tracks *tracks)
{
 int i;
 int status = 0;
 int bytes_to_shuffle;
 char first_byte;
 char last_byte;
 unsigned char *head;
 unsigned char *tail;
 bytes_to_shuffle = tracks->msr_tracks[track_number].msr_tk_len;
 for (i=0; i <= bytes_to_shuffle / 2; i++) {
  head = &tracks->msr_tracks[track_number].msr_tk_data[i];
  tail = &tracks->msr_tracks[track_number].msr_tk_data[(bytes_to_shuffle -1) -i];
  first_byte = msr_reverse_byte(*head);
  last_byte = msr_reverse_byte(*tail);
  *head = last_byte;
  *tail = first_byte;
 }
 return status;
}

variable_types: struct msr_tracks { struct msr_track { unsigned char msr_tk_data[255]; unsigned char msr_tk_len; } msr_tracks[3]; } *

variable_types: i int

variable_types: status int

variable_types:
head
unsigned char *

variable_types:
tail
unsigned char *


decompiled_code:
__int64 __fastcall msr_reverse_tracks(__int64 a1)
{
int v1; // er11
__int64 result; // rax
unsigned int v3; // er11

v1 = 0;
while ( 1 )
{
result = msr_reverse_track(v1, a1);
if ( (_DWORD)result )
break;
v1 = v3 + 1;
if ( v1 == 3 )
return result;
}
printf("Unable to reverse track: %i\n", v3);
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 __fastcall func8(__int64 a1)
{
int v1; // er11
__int64 result; // rax
unsigned int v3; // er11

v1 = 0;
while ( 1 )
{
result = func7(v1, a1);
if ( (_DWORD)result )
break;
v1 = v3 + 1;
if ( v1 == 3 )
return result;
}
printf("Unable to reverse track: %i\n", v3);
return 0xFFFFFFFFLL;
}

original_code:
int
msr_reverse_tracks (msr_tracks_t * tracks)
{
 int i, status;
 for (i = 0; i < 3; i++) {
  status = msr_reverse_track(i, tracks);
  if (status != 0) {
   printf("Unable to reverse track: %i\n", i);
   status = -1;
   break;
  }
 }
 return status;
}

canonical_original_code:
int msr_reverse_tracks(struct msr_tracks *tracks)
{
 int i; int status;
 for (i = 0; i < 3; i++) {
  status = msr_reverse_track(i, tracks);
  if (status != 0) {
   printf("Unable to reverse track: %i\n", i);
   status = -1;
   break;
  }
 }
 return status;
}


decompiled_code:
void *card_list_create()
{
return calloc(1uLL, 0x138uLL);
}

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

original_code:
CARD_LIST *card_list_create()
{
 return (CARD_LIST *)calloc(1, sizeof(CARD_LIST));
}

canonical_original_code:
struct card_list *card_list_create()
{
 return (struct card_list *)calloc(1, sizeof(CARD_LIST));
}

return_type: struct card_list { char filename[32]; unsigned char raw_card[128]; unsigned char mod_card[128]; int offset; struct card_list *next; struct card_list *prev; } *


decompiled_code:
void __fastcall card_list_remove(void *ptr)
{
__int64 v1; // rdx
__int64 v2; // rax

v1 = *((_QWORD *)ptr + 37);
v2 = *((_QWORD *)ptr + 38);
*(_QWORD *)(v1 + 304) = v2;
*(_QWORD *)(v2 + 296) = v1;
free(ptr);
}

original_code:
void card_list_remove(CARD_LIST *item)
{
 item->next->prev = item->prev;
 item->prev->next = item->next;
 memset(item, 0, sizeof(CARD_LIST));
 free(item);
}

canonical_original_code:
void card_list_remove(struct card_list *item)
{
 item->next->prev = item->prev;
 item->prev->next = item->next;
 memset(item, 0, sizeof(CARD_LIST));
 free(item);
}

variable_types: struct card_list { char filename[32]; unsigned char raw_card[128]; unsigned char mod_card[128]; int offset; struct card_list *next; struct card_list *prev; } *


decompiled_code:
void __fastcall card_list_destroy(_QWORD *a1)
{
_QWORD *v2; // rbp

do
{
v2 = a1;
a1 = (_QWORD *)a1[37];
card_list_remove(v2);
}
while ( v2 != a1 );
}

canonical_decompiled_code:
void __fastcall func2(_QWORD *a1)
{
_QWORD *v2; // rbp

do
{
v2 = a1;
a1 = (_QWORD *)a1[37];
func1(v2);
}
while ( v2 != a1 );
}

original_code:
void card_list_destroy(CARD_LIST *item)
{
 CARD_LIST *next;
 next = item;
 do
 {
  item = next;
  next = item->next;
  card_list_remove(item);
 }
 while (next != item);
}

canonical_original_code:
void card_list_destroy(struct card_list *item)
{
 struct card_list *next;
 next = item;
 do
 {
  item = next;
  next = item->next;
  card_list_remove(item);
 }
 while (next != item);
}

user_defined_types: struct card_list { char filename[32]; unsigned char raw_card[128]; unsigned char mod_card[128]; int offset; struct card_list *next; struct card_list *prev; }


decompiled_code:
__int64 __fastcall remove_card(__int64 a1)
{
__int64 v1; // r12

v1 = *(_QWORD *)(a1 + 296);
if ( a1 == v1 )
{
printw("You cannot remove the only remaining card!\n");
}
else
{
printw("Removed \"%s\".\n\n", (const char *)a1);
card_list_remove((void *)a1);
}
wrefresh(stdscr);
sleep(1u);
return v1;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1)
{
__int64 v1; // r12

v1 = *(_QWORD *)(a1 + 296);
if ( a1 == v1 )
{
printw("You cannot remove the only remaining card!\n");
}
else
{
printw("Removed \"%s\".\n\n", (const char *)a1);
func1((void *)a1);
}
wrefresh(stdscr);
sleep(1u);
return v1;
}

original_code:
CARD_LIST *remove_card(CARD_LIST *item)
{
 CARD_LIST *next;
 next = item->next;
 if (item == next)
 {
  printw("You cannot remove the only remaining card!\n");
 }
 else
 {
  printw ("Removed \"%s\".\n\n", item->filename);
  card_list_remove(item);
 }
 wrefresh(stdscr);
 sleep(1);
 return next;
}

canonical_original_code:
struct card_list *remove_card(struct card_list *item)
{
 struct card_list *next;
 next = item->next;
 if (item == next)
 {
  printw("You cannot remove the only remaining card!\n");
 }
 else
 {
  printw ("Removed \"%s\".\n\n", item->filename);
  card_list_remove(item);
 }
 wrefresh(stdscr);
 sleep(1);
 return next;
}

variable_types:
item
struct card_list *


original_code:
void shift_card(CARD_LIST *item, int shift)
{
 unsigned char a, b;
 unsigned char *src, *dst;
 int bit_offset, byte_offset;
 unsigned char rel_shift;
 int i;
 src = item->raw_card;
 dst = item->mod_card;
 memset(dst, 0, 128);
 item->offset += shift;
 byte_offset = abs(item->offset) / 8;
 bit_offset = abs(item->offset) % 8;
 if (item->offset >= 0)
 {
  dst += byte_offset;
  rel_shift = bit_offset;
  a = 0;
 }
 else
 {
  byte_offset += 1;
  src += byte_offset;
  rel_shift = 8 - bit_offset;
  a = *(src - 1);
 }
 for (i=0; i<128 - byte_offset; i++)
 {
  b = *(src + i);
  *(dst + i) = (((a<<8 | b) >> rel_shift ) & 0xff);
  a = b;
 }
}

canonical_original_code:
void shift_card(struct card_list *item, int shift)
{
 unsigned char a; unsigned char b;
 unsigned char *src; unsigned char *dst;
 int bit_offset; int byte_offset;
 unsigned char rel_shift;
 int i;
 src = item->raw_card;
 dst = item->mod_card;
 memset(dst, 0, 128);
 item->offset += shift;
 byte_offset = abs(item->offset) / 8;
 bit_offset = abs(item->offset) % 8;
 if (item->offset >= 0)
 {
  dst += byte_offset;
  rel_shift = bit_offset;
  a = 0;
 }
 else
 {
  byte_offset += 1;
  src += byte_offset;
  rel_shift = 8 - bit_offset;
  a = *(src - 1);
 }
 for (i=0; i<128 - byte_offset; i++)
 {
  b = *(src + i);
  *(dst + i) = (((a<<8 | b) >> rel_shift ) & 0xff);
  a = b;
 }
}

variable_types: shift int

variable_types:
a
unsigned char

variable_types:
b
unsigned char

variable_types:
src
unsigned char *

variable_types:
dst
unsigned char *


decompiled_code:
__int64 __fastcall read_file(const char *a1, char *a2)
{
unsigned int v3; // er12
void *v4; // rsi
ssize_t v5; // rax
int v6; // edi
int *v8; // rax
char *v9; // rax

v3 = open(a1, 0);
if ( v3 == -1 )
{
v8 = _errno_location();
v9 = strerror(*v8);
printw("open: %s.\n", v9);
wrefresh(stdscr);
sleep(1u);
}
else
{
do
{
v4 = a2;
a2 += 8;
v5 = read(v3, v4, 8uLL);
}
while ( v5 > 0 );
v6 = v3;
v3 = v5;
close(v6);
}
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func5(const char *a1, char *a2)
{
unsigned int v3; // er12
void *v4; // rsi
ssize_t v5; // rax
int v6; // edi
int *v8; // rax
char *v9; // rax

v3 = open(a1, 0);
if ( v3 == -1 )
{
v8 = _errno_location();
v9 = strerror(*v8);
printw("open: %s.\n", v9);
wrefresh(stdscr);
sleep(1u);
}
else
{
do
{
v4 = a2;
a2 += 8;
v5 = read(v3, v4, 8uLL);
}
while ( v5 > 0 );
v6 = v3;
v3 = v5;
close(v6);
}
return v3;
}

original_code:
int read_file (const char *filename, unsigned char *buffer)
{
 int fd;
 ssize_t bytes_read;
 fd = open(filename, 00);
 if (fd == -1)
 {
  printw("open: %s.\n", strerror((*__errno_location ())));
  wrefresh(stdscr);
  sleep(1);
  return -1;
 }
 do
 {
  bytes_read = read(fd, buffer, 8);
  buffer += 8;
 }
 while (bytes_read > 0);
 buffer = ((void *)0);
 close(fd);
 return bytes_read;
}

canonical_original_code:
int read_file(char *filename, unsigned char *buffer)
{
 int fd;
 long bytes_read;
 fd = open(filename, 00);
 if (fd == -1)
 {
  printw("open: %s.\n", strerror((*__errno_location ())));
  wrefresh(stdscr);
  sleep(1);
  return -1;
 }
 do
 {
  bytes_read = read(fd, buffer, 8);
  buffer += 8;
 }
 while (bytes_read > 0);
 buffer = ((void *)0);
 close(fd);
 return bytes_read;
}

variable_types:
filename
char *

variable_types:
buffer
unsigned char *

variable_types: fd int


decompiled_code:
int __fastcall print_bits(int a1)
{
int v1; // ebp
unsigned int v3; // esi
int result; // eax

v1 = 8;
do
{
v3 = (char)a1;
a1 *= 2;
result = printw("%c", (v3 >> 31) + 48);
--v1;
}
while ( v1 );
return result;
}

canonical_decompiled_code:
int __fastcall func6(int a1)
{
int v1; // ebp
unsigned int v3; // esi
int result; // eax

v1 = 8;
do
{
v3 = (char)a1;
a1 *= 2;
result = printw("%c", (v3 >> 31) + 48);
--v1;
}
while ( v1 );
return result;
}

original_code:
void print_bits(unsigned char c)
{
    int i;
    for (i = 0; i<8; i++)
    {
        printw("%c", (c&0x80)?'1':'0');
        c <<= 1;
    }
}

variable_types:
c
unsigned char


decompiled_code:
int __fastcall dump_buffer(__int64 a1)
{
__int64 i; // rbx
int result; // eax

for ( i = 1LL; i != 129; ++i )
{
while ( 1 )
{
print_bits(*(unsigned __int8 *)(a1 + i - 1));
result = printw(" ");
if ( (i & 7) != 0 )
break;
++i;
result = printw("\n");
if ( i == 129 )
return result;
}
if ( (i & 3) == 0 )
result = printw(" ");
}
return result;
}

canonical_decompiled_code:
int __fastcall func7(__int64 a1)
{
__int64 i; // rbx
int result; // eax

for ( i = 1LL; i != 129; ++i )
{
while ( 1 )
{
func6(*(unsigned __int8 *)(a1 + i - 1));
result = printw(" ");
if ( (i & 7) != 0 )
break;
++i;
result = printw("\n");
if ( i == 129 )
return result;
}
if ( (i & 3) == 0 )
result = printw(" ");
}
return result;
}

original_code:
void dump_buffer(const unsigned char *buffer)
{
 int i;
 for (i=0; i<128; i++)
 {
  print_bits(*(buffer +i));
  printw(" ");
  if ((i + 1) % 8 == 0)
  {
   printw("\n");
  }
  else if ((i + 1) % 4 == 0)
  {
   printw(" ");
  }
 }
}

canonical_original_code:
void dump_buffer(unsigned char *buffer)
{
 int i;
 for (i=0; i<128; i++)
 {
  print_bits(*(buffer +i));
  printw(" ");
  if ((i + 1) % 8 == 0)
  {
   printw("\n");
  }
  else if ((i + 1) % 4 == 0)
  {
   printw(" ");
  }
 }
}


decompiled_code:
int __fastcall display_card(__int64 a1)
{
printw("File: %s (Offset: %+d bits)\n\n", (const char *)a1, *(unsigned int *)(a1 + 288));
dump_buffer(a1 + 160);
return wrefresh(stdscr);
}

canonical_decompiled_code:
int __fastcall func8(__int64 a1)
{
printw("File: %s (Offset: %+d bits)\n\n", (const char *)a1, *(unsigned int *)(a1 + 288));
func7(a1 + 160);
return wrefresh(stdscr);
}

original_code:
void display_card(CARD_LIST *item)
{
 printw("File: %s  (Offset: %+d bits)\n\n", item->filename, item->offset);
 dump_buffer(item->mod_card);
 wrefresh(stdscr);
}

canonical_original_code:
void display_card(struct card_list *item)
{
 printw("File: %s  (Offset: %+d bits)\n\n", item->filename, item->offset);
 dump_buffer(item->mod_card);
 wrefresh(stdscr);
}


decompiled_code:
int display_header()
{
__m128i v1; // [rsp+0h] [rbp-28h] BYREF
char v2[16]; // [rsp+10h] [rbp-18h] BYREF

strcpy(v2, "lizer 0.1");
v1 = _mm_load_si128((const __m128i *)&LC11);
mvprintw(0, 23, "%s\n", v1.m128i_i8);
printw("\n");
return wrefresh(stdscr);
}

canonical_decompiled_code:
int func9()
{
__m128i v1; // [rsp+0h] [rbp-28h] BYREF
char v2[16]; // [rsp+10h] [rbp-18h] BYREF

strcpy(v2, "lizer 0.1");
v1 = _mm_load_si128((const __m128i *)&LC11);
mvprintw(0, 23, "%s\n", v1.m128i_i8);
printw("\n");
return wrefresh(stdscr);
}

original_code:
void display_header()
{
 int y, x;
 char title[] = "File Field Visualizer 0.1";
 y = 0;
 x = (72 - strlen(title)) / 2;
 mvprintw(y, x, "%s\n", title);
 printw("\n");
 wrefresh(stdscr);
}

canonical_original_code:
void display_header()
{
 int y; int x;
 char title[] = "File Field Visualizer 0.1";
 y = 0;
 x = (72 - strlen(title)) / 2;
 mvprintw(y, x, "%s\n", title);
 printw("\n");
 wrefresh(stdscr);
}

variable_types: y int

variable_types: x int

variable_types:
title
char []


decompiled_code:
int display_footer()
{
__int128 v1[2]; // [rsp+0h] [rbp-38h] BYREF
char v2[16]; // [rsp+20h] [rbp-18h] BYREF

strcpy(v2, " r, ?, q.");
v1[0] = (__int128)_mm_load_si128((const __m128i *)&LC12);
v1[1] = (__int128)_mm_load_si128((const __m128i *)&LC13);
printw("\n");
printw("%s\n", (const char *)v1);
return wrefresh(stdscr);
}

original_code:
void display_footer()
{
 char commands[] = "Commands: <L>, <R>, <U>, <D>, a, r, ?, q.";
 printw("\n");
 printw("%s\n", commands);
 wrefresh(stdscr);
}

variable_types:
commands
char []


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
char **v3; // rbx
const char **v4; // r12
__int64 *v5; // rbp
char *v6; // rdi
__m128i *v7; // rax
__int64 v8; // r12
int v9; // eax

if ( argc <= 1 )
{
printf("Usage: %s [file1] ... [fileN]\n", *argv);
exit(1);
}
v3 = (char **)(argv + 1);
initscr();
keypad(stdscr, 1);
noecho();
display_header();
v4 = &argv[(unsigned int)(argc - 2) + 2];
v5 = 0LL;
do
{
v6 = *v3++;
v7 = add_card(v6, (__int64)v5);
v5 = (__int64 *)v7;
}
while ( v4 != (const char **)v3 );
v8 = v7[18].m128i_i64[1];
sleep(1u);
while ( 1 )
{
while ( 1 )
{
while ( 1 )
{
while ( 1 )
{
wclear(stdscr);
display_header();
display_card(v8);
display_footer();
printw("\n");
wrefresh(stdscr);
v9 = wgetch(stdscr);
if ( v9 != 114 )
break;
v8 = remove_card(v8);
wrefresh(stdscr);
}
if ( v9 <= 114 )
break;
if ( v9 == 260 )
{
shift_card(v8, -1);
wrefresh(stdscr);
}
else if ( v9 <= 260 )
{
if ( v9 == 258 )
{
v8 = *(_QWORD *)(v8 + 296);
wrefresh(stdscr);
}
else if ( v9 == 259 )
{
v8 = *(_QWORD *)(v8 + 304);
wrefresh(stdscr);
}
else
{
LABEL_23:
printw("Unrecognized command: %c.\n", (unsigned int)v9);
wrefresh(stdscr);
sleep(1u);
wrefresh(stdscr);
}
}
else
{
if ( v9 != 261 )
goto LABEL_23;
shift_card(v8, 1);
wrefresh(stdscr);
}
}
if ( v9 != 97 )
break;
v8 = (__int64)add_card(0LL, v8);
wrefresh(stdscr);
}
if ( v9 > 97 )
break;
if ( v9 != 10 )
{
if ( v9 != 63 )
goto LABEL_23;
printw("<DOWN> - next card\n");
printw("<UP> - previous card\n");
printw("<LEFT> - bit shift left\n");
printw("<RIGHT> - bit shift right\n");
printw("a - add card\n");
printw("r - remove card\n");
printw("? - this help screen\n");
printw("q - exit program\n");
printw("\n");
printw("Press any key to continue ...\n");
wrefresh(stdscr);
wgetch(stdscr);
wrefresh(stdscr);
}
}
if ( v9 != 113 )
goto LABEL_23;
wrefresh(stdscr);
card_list_destroy(v5);
endwin();
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
char **v3; // rbx
const char **v4; // r12
__int64 *v5; // rbp
char *v6; // rdi
__m128i *v7; // rax
__int64 v8; // r12
int v9; // eax

if ( argc <= 1 )
{
printf("Usage: %s [file1] ... [fileN]\n", *argv);
exit(1);
}
v3 = (char **)(argv + 1);
initscr();
keypad(stdscr, 1);
noecho();
func9();
v4 = &argv[(unsigned int)(argc - 2) + 2];
v5 = 0LL;
do
{
v6 = *v3++;
v7 = add_card(v6, (__int64)v5);
v5 = (__int64 *)v7;
}
while ( v4 != (const char **)v3 );
v8 = v7[18].m128i_i64[1];
sleep(1u);
while ( 1 )
{
while ( 1 )
{
while ( 1 )
{
while ( 1 )
{
wclear(stdscr);
func9();
func8(v8);
func10();
printw("\n");
wrefresh(stdscr);
v9 = wgetch(stdscr);
if ( v9 != 114 )
break;
v8 = func3(v8);
wrefresh(stdscr);
}
if ( v9 <= 114 )
break;
if ( v9 == 260 )
{
func4(v8, -1);
wrefresh(stdscr);
}
else if ( v9 <= 260 )
{
if ( v9 == 258 )
{
v8 = *(_QWORD *)(v8 + 296);
wrefresh(stdscr);
}
else if ( v9 == 259 )
{
v8 = *(_QWORD *)(v8 + 304);
wrefresh(stdscr);
}
else
{
LABEL_23:
printw("Unrecognized command: %c.\n", (unsigned int)v9);
wrefresh(stdscr);
sleep(1u);
wrefresh(stdscr);
}
}
else
{
if ( v9 != 261 )
goto LABEL_23;
func4(v8, 1);
wrefresh(stdscr);
}
}
if ( v9 != 97 )
break;
v8 = (__int64)add_card(0LL, v8);
wrefresh(stdscr);
}
if ( v9 > 97 )
break;
if ( v9 != 10 )
{
if ( v9 != 63 )
goto LABEL_23;
printw("<DOWN> - next card\n");
printw("<UP> - previous card\n");
printw("<LEFT> - bit shift left\n");
printw("<RIGHT> - bit shift right\n");
printw("a - add card\n");
printw("r - remove card\n");
printw("? - this help screen\n");
printw("q - exit program\n");
printw("\n");
printw("Press any key to continue ...\n");
wrefresh(stdscr);
wgetch(stdscr);
wrefresh(stdscr);
}
}
if ( v9 != 113 )
goto LABEL_23;
wrefresh(stdscr);
func2(v5);
endwin();
return 0;
}

original_code:
int main(int argc, char **argv)
{
 CARD_LIST *cards;
 CARD_LIST *cur_card;
 unsigned char loop;
 int command;
 int i;
 if (argc <2)
 {
  printf("Usage: %s [file1] ... [fileN]\n", argv[0]);
  exit(1);
 }
 initscr();
 keypad(stdscr, 1);
 noecho();
 display_header();
 cards = ((void *)0);
 for (i=1; i<argc; i++)
 {
  cards = add_card(argv[i], cards);
 }
 cur_card = cards->next;
 sleep(1);
 loop = 1;
 while (loop)
 {
  wclear(stdscr);
  display_header();
  display_card(cur_card);
  display_footer();
  printw("\n");
  wrefresh(stdscr);
  command = wgetch(stdscr);
  switch (command)
  {
  case 0404:
   shift_card(cur_card, -1);
   break;
  case 0405:
   shift_card(cur_card, 1);
   break;
  case 0402:
   cur_card = cur_card->next;
   break;
  case 0403:
   cur_card = cur_card->prev;
   break;
  case 'a':
   cur_card = add_card(((void *)0), cur_card);
   break;
  case 'r':
   cur_card = remove_card(cur_card);
   break;
  case '?':
   printw("<DOWN> - next card\n");
   printw("<UP> - previous card\n");
   printw("<LEFT> - bit shift left\n");
   printw("<RIGHT> - bit shift right\n");
   printw("a - add card\n");
   printw("r - remove card\n");
   printw("? - this help screen\n");
   printw("q - exit program\n");
   printw("\n");
   printw("Press any key to continue ...\n");
   wrefresh(stdscr);
   wgetch(stdscr);
   break;
  case 'q':
   loop = 0;
   break;
  case '\n':
   continue;
  default:
   printw("Unrecognized command: %c.\n", command);
   wrefresh(stdscr);
   sleep(1);
   break;
  }
  wrefresh(stdscr);
 }
 card_list_destroy(cards);
 endwin();
 return 0;
}

canonical_original_code:
int main(int argc, char **argv)
{
 struct card_list *cards;
 struct card_list *cur_card;
 unsigned char loop;
 int command;
 int i;
 if (argc <2)
 {
  printf("Usage: %s [file1] ... [fileN]\n", argv[0]);
  exit(1);
 }
 initscr();
 keypad(stdscr, 1);
 noecho();
 display_header();
 cards = ((void *)0);
 for (i=1; i<argc; i++)
 {
  cards = add_card(argv[i], cards);
 }
 cur_card = cards->next;
 sleep(1);
 loop = 1;
 while (loop)
 {
  wclear(stdscr);
  display_header();
  display_card(cur_card);
  display_footer();
  printw("\n");
  wrefresh(stdscr);
  command = wgetch(stdscr);
  switch (command)
  {
  case 0404:
   shift_card(cur_card, -1);
   break;
  case 0405:
   shift_card(cur_card, 1);
   break;
  case 0402:
   cur_card = cur_card->next;
   break;
  case 0403:
   cur_card = cur_card->prev;
   break;
  case 'a':
   cur_card = add_card(((void *)0), cur_card);
   break;
  case 'r':
   cur_card = remove_card(cur_card);
   break;
  case '?':
   printw("<DOWN> - next card\n");
   printw("<UP> - previous card\n");
   printw("<LEFT> - bit shift left\n");
   printw("<RIGHT> - bit shift right\n");
   printw("a - add card\n");
   printw("r - remove card\n");
   printw("? - this help screen\n");
   printw("q - exit program\n");
   printw("\n");
   printw("Press any key to continue ...\n");
   wrefresh(stdscr);
   wgetch(stdscr);
   break;
  case 'q':
   loop = 0;
   break;
  case '\n':
   continue;
  default:
   printw("Unrecognized command: %c.\n", command);
   wrefresh(stdscr);
   sleep(1);
   break;
  }
  wrefresh(stdscr);
 }
 card_list_destroy(cards);
 endwin();
 return 0;
}

variable_types: argc int

variable_types:
argv
char **

variable_types:
loop
unsigned char

variable_types: command int

variable_types: i int


getend

decompiled_code:
__int64 __fastcall getend(__int64 a1)
{
char v2[3]; // [rsp+Ch] [rbp-Ch] BYREF
unsigned __int8 v3; // [rsp+Fh] [rbp-9h]

serial_read(a1, v2, 4LL);
if ( v3 == 48 )
return 0LL;
printf("read returned error status: 0x%x\n", v3);
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1)
{
char v2[3]; // [rsp+Ch] [rbp-Ch] BYREF
unsigned __int8 v3; // [rsp+Fh] [rbp-9h]

serial_read(a1, v2, 4LL);
if ( v3 == 48 )
return 0LL;
printf("read returned error status: 0x%x\n", v3);
return 0xFFFFFFFFLL;
}

original_code:
static int
getend (int fd)
{
 msr_end_t m;
 serial_read (fd, &m, sizeof(m));
 if (m.msr_sts != 0x30) {
  printf ("read returned error status: 0x%x\n", m.msr_sts);
  return (-1);
 }
 return (0);
}

canonical_original_code:
static int getend(int fd)
{
 struct msr_end m;
 serial_read (fd, &m, sizeof(m));
 if (m.msr_sts != 0x30) {
  printf ("read returned error status: 0x%x\n", m.msr_sts);
  return (-1);
 }
 return (0);
}

variable_types: struct msr_end { unsigned char msr_enddelim; unsigned char msr_fs; unsigned char msr_esc; unsigned char msr_sts; }


getstart

decompiled_code:
__int64 __fastcall getstart(unsigned int a1)
{
int v1; // ebx
char v3[25]; // [rsp+Fh] [rbp-19h] BYREF

v1 = 3;
while ( 1 )
{
serial_readchar(a1, v3);
if ( v3[0] == 115 )
break;
if ( !--v1 )
return 0xFFFFFFFFLL;
}
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func1(unsigned int a1)
{
int v1; // ebx
char v3[25]; // [rsp+Fh] [rbp-19h] BYREF

v1 = 3;
while ( 1 )
{
serial_readchar(a1, v3);
if ( v3[0] == 115 )
break;
if ( !--v1 )
return 0xFFFFFFFFLL;
}
return 0LL;
}

original_code:
static int
getstart (int fd)
{
 uint8_t b;
 int i, r;
 for (i = 0; i < 3; i++) {
  r = serial_readchar(fd, &b);
  if (b == 0x73)
   break;
 }
 if (i == 3)
  return (-1);
 return (0);
}

canonical_original_code:
static int getstart(int fd)
{
 unsigned char b;
 int i; int r;
 for (i = 0; i < 3; i++) {
  r = serial_readchar(fd, &b);
  if (b == 0x73)
   break;
 }
 if (i == 3)
  return (-1);
 return (0);
}

variable_types:
b
unsigned char

variable_types: r int


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

v3[1] = a2;
v3[0] = 27;
return serial_write(a1, v3, 2LL);
}

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

v3[1] = a2;
v3[0] = 27;
return serial_write(a1, v3, 2LL);
}

original_code:
int
msr_cmd (int fd, uint8_t c)
{
 msr_cmd_t cmd;
 cmd.msr_esc = 0x1B;
 cmd.msr_cmd = c;
 return (serial_write (fd, &cmd, sizeof(cmd)));
}

canonical_original_code:
int msr_cmd(int fd, unsigned char c)
{
 struct msr_cmd cmd;
 cmd.msr_esc = 0x1B;
 cmd.msr_cmd = c;
 return (serial_write (fd, &cmd, sizeof(cmd)));
}

variable_types: struct msr_cmd { unsigned char msr_esc; unsigned char msr_cmd; }


decompiled_code:
__int64 __fastcall msr_zeros(__int64 a1)
{
char v2[11]; // [rsp+Dh] [rbp-Bh] BYREF

msr_cmd(a1, 108);
serial_read((unsigned int)a1, v2, 3LL);
printf("zero13: %d zero: %d\n", (unsigned __int8)v2[1], (unsigned __int8)v2[2]);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1)
{
char v2[11]; // [rsp+Dh] [rbp-Bh] BYREF

func4(a1, 108);
serial_read((unsigned int)a1, v2, 3LL);
printf("zero13: %d zero: %d\n", (unsigned __int8)v2[1], (unsigned __int8)v2[2]);
return 0LL;
}

original_code:
int msr_zeros (int fd)
{
 msr_lz_t lz;
 msr_cmd (fd, 0x6C);
 serial_read (fd, &lz, sizeof(lz));
 printf("zero13: %d zero: %d\n", lz.msr_lz_tk1_3, lz.msr_lz_tk2);
 return (0);
}

canonical_original_code:
int msr_zeros(int fd)
{
 struct msr_lz lz;
 msr_cmd (fd, 0x6C);
 serial_read (fd, &lz, sizeof(lz));
 printf("zero13: %d zero: %d\n", lz.msr_lz_tk1_3, lz.msr_lz_tk2);
 return (0);
}

variable_types: struct msr_lz { unsigned char msr_esc; unsigned char msr_lz_tk1_3; unsigned char msr_lz_tk2; }


decompiled_code:
__int64 __fastcall msr_commtest(__int64 a1)
{
char v2[10]; // [rsp+Eh] [rbp-Ah] BYREF

if ( (unsigned int)msr_cmd(a1, 101) == -1 )
err(1, "Commtest write failed");
do
serial_readchar((unsigned int)a1, v2);
while ( v2[0] != 121 );
puts("Communications test passed.");
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1)
{
char v2[10]; // [rsp+Eh] [rbp-Ah] BYREF

if ( (unsigned int)func4(a1, 101) == -1 )
err(1, "Commtest write failed");
do
serial_readchar((unsigned int)a1, v2);
while ( v2[0] != 121 );
puts("Communications test passed.");
return 0LL;
}

original_code:
int
msr_commtest (int fd)
{
 int r;
 uint8_t buf[2];
 r = msr_cmd (fd, 0x65);
 if (r == -1)
     err(1, "Commtest write failed");
 while (1) {
  serial_readchar (fd, &buf[0]);
  if (buf[0] == 0x79)
   break;
 }
 if (buf[0] != 0x79) {
  printf("Communications test failure\n");
  return (-1);
 } else
  printf("Communications test passed.\n");
 return (0);
}

canonical_original_code:
int msr_commtest(int fd)
{
 int r;
 unsigned char buf[2];
 r = msr_cmd (fd, 0x65);
 if (r == -1)
     err(1, "Commtest write failed");
 while (1) {
  serial_readchar (fd, &buf[0]);
  if (buf[0] == 0x79)
   break;
 }
 if (buf[0] != 0x79) {
  printf("Communications test failure\n");
  return (-1);
 } else
  printf("Communications test passed.\n");
 return (0);
}

variable_types:
buf
unsigned char [2]


decompiled_code:
__int64 __fastcall msr_fwrev(unsigned int a1)
{
unsigned int v1; // er12
char v3[88]; // [rsp+0h] [rbp-58h] BYREF

bzero(v3, 0x40uLL);
if ( (unsigned int)msr_cmd(a1, 118) )
return (unsigned int)-1;
v1 = 0;
serial_readchar(a1, v3);
serial_read(a1, v3, 8LL);
v3[8] = 0;
printf("Firmware Version: %s\n", v3);
return v1;
}

canonical_decompiled_code:
__int64 __fastcall func7(unsigned int a1)
{
unsigned int v1; // er12
char v3[88]; // [rsp+0h] [rbp-58h] BYREF

bzero(v3, 0x40uLL);
if ( (unsigned int)func4(a1, 118) )
return (unsigned int)-1;
v1 = 0;
serial_readchar(a1, v3);
serial_read(a1, v3, 8LL);
v3[8] = 0;
printf("Firmware Version: %s\n", v3);
return v1;
}

original_code:
int
msr_fwrev (int fd)
{
 uint8_t buf[64];
 bzero (buf, sizeof(buf));
 if (msr_cmd (fd, 0x76) != 0)
            return (-1);
 serial_readchar (fd, &buf[0]);
 serial_read (fd, buf, 8);
 buf[8] = '\0';
 printf ("Firmware Version: %s\n", buf);
 return (0);
}

canonical_original_code:
int msr_fwrev(int fd)
{
 unsigned char buf[64];
 bzero (buf, sizeof(buf));
 if (msr_cmd (fd, 0x76) != 0)
            return (-1);
 serial_readchar (fd, &buf[0]);
 serial_read (fd, buf, 8);
 buf[8] = '\0';
 printf ("Firmware Version: %s\n", buf);
 return (0);
}

variable_types: fd int

variable_types:
buf
unsigned char [64]


decompiled_code:
__int64 __fastcall msr_model(__int64 a1)
{
__int64 result; // rax
char v2[11]; // [rsp+Dh] [rbp-Bh] BYREF

msr_cmd(a1, 116);
serial_read((unsigned int)a1, v2, 3LL);
result = 1LL;
if ( v2[2] == 83 )
{
printf("Device Model: MSR-206-%c\n", (unsigned __int8)v2[1]);
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func8(__int64 a1)
{
__int64 result; // rax
char v2[11]; // [rsp+Dh] [rbp-Bh] BYREF

func4(a1, 116);
serial_read((unsigned int)a1, v2, 3LL);
result = 1LL;
if ( v2[2] == 83 )
{
printf("Device Model: MSR-206-%c\n", (unsigned __int8)v2[1]);
result = 0LL;
}
return result;
}

original_code:
int
msr_model (int fd)
{
 msr_model_t m;
 msr_cmd (fd, 0x74);
 serial_read (fd, &m, sizeof(m));
 if (m.msr_s != 0x53)
  return (1);
 printf("Device Model: MSR-206-%c\n", m.msr_model);
 return (0);
}

canonical_original_code:
int msr_model(int fd)
{
 struct msr_model m;
 msr_cmd (fd, 0x74);
 serial_read (fd, &m, sizeof(m));
 if (m.msr_s != 0x53)
  return (1);
 printf("Device Model: MSR-206-%c\n", m.msr_model);
 return (0);
}

variable_types: struct msr_model { unsigned char msr_esc; unsigned char msr_model; unsigned char msr_s; }


decompiled_code:
__int64 __fastcall msr_flash_led(__int64 a1, char a2)
{
if ( (unsigned int)msr_cmd(a1, a2) == -1 )
err(1, "LED failure");
usleep(0x186A0u);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func9(__int64 a1, char a2)
{
if ( (unsigned int)func4(a1, a2) == -1 )
err(1, "LED failure");
usleep(0x186A0u);
return 0LL;
}

original_code:
int
msr_flash_led (int fd, uint8_t led)
{
 int r;
 r = msr_cmd (fd, led);
 if (r == -1)
  err(1, "LED failure");
 usleep (100000);
 return (0);
}

canonical_original_code:
int msr_flash_led(int fd, unsigned char led)
{
 int r;
 r = msr_cmd (fd, led);
 if (r == -1)
  err(1, "LED failure");
 usleep (100000);
 return (0);
}

variable_types:
led
unsigned char


decompiled_code:
__int64 __fastcall msr_sensor_test(__int64 a1)
{
__int64 result; // rax
char v2[12]; // [rsp+Ch] [rbp-Ch] BYREF

msr_cmd(a1, 134);
puts("Attempting sensor test -- please slide a card...");
serial_read((unsigned int)a1, v2, 2LL);
if ( v2[0] == 27 && v2[1] == 48 )
{
puts("Sensor test successfull");
result = 0LL;
}
else
{
puts("It appears that the sensor did not sense a magnetic card.");
result = 0xFFFFFFFFLL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func10(__int64 a1)
{
__int64 result; // rax
char v2[12]; // [rsp+Ch] [rbp-Ch] BYREF

func4(a1, 134);
puts("Attempting sensor test -- please slide a card...");
serial_read((unsigned int)a1, v2, 2LL);
if ( v2[0] == 27 && v2[1] == 48 )
{
puts("Sensor test successfull");
result = 0LL;
}
else
{
puts("It appears that the sensor did not sense a magnetic card.");
result = 0xFFFFFFFFLL;
}
return result;
}

original_code:
int
msr_sensor_test (int fd)
{
 uint8_t b[4];
 msr_cmd (fd, 0x86);
 printf("Attempting sensor test -- please slide a card...\n");
 serial_read (fd, &b, 2);
 if (b[0] == 0x1B && b[1] == 0x30) {
  printf("Sensor test successfull\n");
  return 0;
 }
 printf("It appears that the sensor did not sense a magnetic card.\n");
 return (-1);
}

canonical_original_code:
int msr_sensor_test(int fd)
{
 unsigned char b[4];
 msr_cmd (fd, 0x86);
 printf("Attempting sensor test -- please slide a card...\n");
 serial_read (fd, &b, 2);
 if (b[0] == 0x1B && b[1] == 0x30) {
  printf("Sensor test successfull\n");
  return 0;
 }
 printf("It appears that the sensor did not sense a magnetic card.\n");
 return (-1);
}

variable_types:
b
unsigned char [4]


decompiled_code:
__int64 __fastcall msr_ram_test(unsigned int a1)
{
__int64 result; // rax
char v2[10]; // [rsp+Eh] [rbp-Ah] BYREF

puts("Running ram test...");
msr_cmd(a1, 135);
serial_read(a1, v2, 2LL);
if ( v2[0] == 27 && v2[1] == 48 )
{
puts("RAM test successfull.");
result = 0LL;
}
else
{
puts("It appears that the RAM test failed");
result = 0xFFFFFFFFLL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func11(unsigned int a1)
{
__int64 result; // rax
char v2[10]; // [rsp+Eh] [rbp-Ah] BYREF

puts("Running ram test...");
func4(a1, 135);
serial_read(a1, v2, 2LL);
if ( v2[0] == 27 && v2[1] == 48 )
{
puts("RAM test successfull.");
result = 0LL;
}
else
{
puts("It appears that the RAM test failed");
result = 0xFFFFFFFFLL;
}
return result;
}

original_code:
int
msr_ram_test (int fd)
{
 uint8_t b[2];
 printf("Running ram test...\n");
 msr_cmd (fd, 0x87);
 serial_read(fd, b, sizeof(b));
 if (b[0] == 0x1B && b[1] == 0x30) {
  printf("RAM test successfull.\n");
   return (0);
 }
 printf("It appears that the RAM test failed\n");
 return (-1);
}

canonical_original_code:
int msr_ram_test(int fd)
{
 unsigned char b[2];
 printf("Running ram test...\n");
 msr_cmd (fd, 0x87);
 serial_read(fd, b, sizeof(b));
 if (b[0] == 0x1B && b[1] == 0x30) {
  printf("RAM test successfull.\n");
   return (0);
 }
 printf("It appears that the RAM test failed\n");
 return (-1);
}

variable_types:
b
unsigned char [2]


decompiled_code:
__int64 __fastcall msr_set_hi_co(unsigned int a1)
{
__int64 result; // rax
char v2[10]; // [rsp+Eh] [rbp-Ah] BYREF

puts("Putting the writer to Hi-Co mode...");
msr_cmd(a1, 120);
serial_read(a1, v2, 2LL);
if ( v2[0] == 27 && v2[1] == 48 )
{
puts("We were able to put the writer into Hi-Co mode.");
result = 0LL;
}
else
{
printf("It appears that the reader did not switch to Hi-Co mode.");
result = 1LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func12(unsigned int a1)
{
__int64 result; // rax
char v2[10]; // [rsp+Eh] [rbp-Ah] BYREF

puts("Putting the writer to Hi-Co mode...");
func4(a1, 120);
serial_read(a1, v2, 2LL);
if ( v2[0] == 27 && v2[1] == 48 )
{
puts("We were able to put the writer into Hi-Co mode.");
result = 0LL;
}
else
{
printf("It appears that the reader did not switch to Hi-Co mode.");
result = 1LL;
}
return result;
}

original_code:
int
msr_set_hi_co (int fd)
{
 char b[2];
 printf("Putting the writer to Hi-Co mode...\n");
 msr_cmd (fd, 0x78);
 serial_read (fd, &b, 2);
 if (b[0] == 0x1B && b[1] == 0x30) {
  printf("We were able to put the writer into Hi-Co mode.\n");
  return (0);
 }
 printf("It appears that the reader did not switch to Hi-Co mode.");
 return (1);
}

canonical_original_code:
int msr_set_hi_co(int fd)
{
 char b[2];
 printf("Putting the writer to Hi-Co mode...\n");
 msr_cmd (fd, 0x78);
 serial_read (fd, &b, 2);
 if (b[0] == 0x1B && b[1] == 0x30) {
  printf("We were able to put the writer into Hi-Co mode.\n");
  return (0);
 }
 printf("It appears that the reader did not switch to Hi-Co mode.");
 return (1);
}

variable_types:
b
char [2]


decompiled_code:
__int64 __fastcall msr_set_lo_co(unsigned int a1)
{
__int64 result; // rax
char v2[10]; // [rsp+Eh] [rbp-Ah] BYREF

puts("Putting the writer to Lo-Co mode...");
msr_cmd(a1, 121);
serial_read(a1, v2, 2LL);
if ( v2[0] == 27 && v2[1] == 48 )
{
puts("We were able to put the writer into Lo-Co mode.");
result = 0LL;
}
else
{
printf("It appears that the reader did not switch to Lo-Co mode.");
result = 1LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func13(unsigned int a1)
{
__int64 result; // rax
char v2[10]; // [rsp+Eh] [rbp-Ah] BYREF

puts("Putting the writer to Lo-Co mode...");
func4(a1, 121);
serial_read(a1, v2, 2LL);
if ( v2[0] == 27 && v2[1] == 48 )
{
puts("We were able to put the writer into Lo-Co mode.");
result = 0LL;
}
else
{
printf("It appears that the reader did not switch to Lo-Co mode.");
result = 1LL;
}
return result;
}

original_code:
int
msr_set_lo_co (int fd)
{
 char b[2];
 printf("Putting the writer to Lo-Co mode...\n");
 msr_cmd (fd, 0x79);
 serial_read (fd, &b, 2);
 if (b[0] == 0x1B && b[1] == 0x30) {
  printf("We were able to put the writer into Lo-Co mode.\n");
  return (0);
 }
 printf("It appears that the reader did not switch to Lo-Co mode.");
 return (1);
}

canonical_original_code:
int msr_set_lo_co(int fd)
{
 char b[2];
 printf("Putting the writer to Lo-Co mode...\n");
 msr_cmd (fd, 0x79);
 serial_read (fd, &b, 2);
 if (b[0] == 0x1B && b[1] == 0x30) {
  printf("We were able to put the writer into Lo-Co mode.\n");
  return (0);
 }
 printf("It appears that the reader did not switch to Lo-Co mode.");
 return (1);
}


decompiled_code:
__int64 __fastcall msr_reset(__int64 a1)
{
msr_cmd(a1, 97);
usleep(0x186A0u);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func14(__int64 a1)
{
func4(a1, 97);
usleep(0x186A0u);
return 0LL;
}

original_code:
int
msr_reset (int fd)
{
 msr_cmd (fd, 0x61);
 usleep (100000);
 return (0);
}

canonical_original_code:
int msr_reset(int fd)
{
 msr_cmd (fd, 0x61);
 usleep (100000);
 return (0);
}


decompiled_code:
__int64 __fastcall msr_iso_read(__int64 a1, __int64 a2)
{
int i; // ebp
_BYTE *v4; // rcx
__int64 v5; // rdx
unsigned int v6; // er12

if ( (unsigned int)msr_cmd(a1, 114) == -1 )
err(1, "Command write failed");
if ( (unsigned int)getstart(a1) == -1 )
err(1, "get start delimiter failed");
for ( i = 0; i != 3; gettrack_iso_isra_0((unsigned int)a1, i, v5, v4) )
{
++i;
v4 = (_BYTE *)(a2 + 255);
v5 = a2;
a2 += 256LL;
}
v6 = getend((unsigned int)a1);
if ( v6 != -1 )
return 0;
warnx("read failed");
return v6;
}

canonical_decompiled_code:
__int64 __fastcall func15(__int64 a1, __int64 a2)
{
int i; // ebp
_BYTE *v4; // rcx
__int64 v5; // rdx
unsigned int v6; // er12

if ( (unsigned int)func4(a1, 114) == -1 )
err(1, "Command write failed");
if ( (unsigned int)func1(a1) == -1 )
err(1, "get start delimiter failed");
for ( i = 0; i != 3; func3((unsigned int)a1, i, v5, v4) )
{
++i;
v4 = (_BYTE *)(a2 + 255);
v5 = a2;
a2 += 256LL;
}
v6 = func0((unsigned int)a1);
if ( v6 != -1 )
return 0;
warnx("read failed");
return v6;
}

original_code:
int
msr_iso_read(int fd, msr_tracks_t * tracks)
{
 int r;
 int i;
 r = msr_cmd (fd, 0x72);
 if (r == -1)
  err(1, "Command write failed");
 if (getstart (fd) == -1)
  err(1, "get start delimiter failed");
 for (i = 0; i < 3; i++)
  gettrack_iso (fd, i + 1, tracks->msr_tracks[i].msr_tk_data,
      &tracks->msr_tracks[i].msr_tk_len);
 if (getend (fd) == -1) {
  warnx("read failed");
  return (-1);
 }
 return (0);
}

canonical_original_code:
int msr_iso_read(int fd, struct msr_tracks *tracks)
{
 int r;
 int i;
 r = msr_cmd (fd, 0x72);
 if (r == -1)
  err(1, "Command write failed");
 if (getstart (fd) == -1)
  err(1, "get start delimiter failed");
 for (i = 0; i < 3; i++)
  gettrack_iso (fd, i + 1, tracks->msr_tracks[i].msr_tk_data,
      &tracks->msr_tracks[i].msr_tk_len);
 if (getend (fd) == -1) {
  warnx("read failed");
  return (-1);
 }
 return (0);
}

variable_types: struct msr_tracks { struct msr_track { unsigned char msr_tk_data[255]; unsigned char msr_tk_len; } msr_tracks[3]; } *


decompiled_code:
__int64 __fastcall msr_erase(__int64 a1, char a2)
{
__int64 result; // rax
char v3[18]; // [rsp+Ch] [rbp-1Ch] BYREF
unsigned __int8 v4; // [rsp+1Eh] [rbp-Ah] BYREF
unsigned __int8 v5; // [rsp+1Fh] [rbp-9h]

v3[0] = a2;
msr_cmd(a1, 99);
serial_write((unsigned int)a1, v3, 1LL);
if ( (unsigned int)serial_read((unsigned int)a1, &v4, 2LL) == -1 )
err(1, "read erase response failed");
if ( v4 == 27 && v5 == 48 )
{
puts("Erase successfull");
result = 0LL;
}
else
{
printf("%x %x\n", v4, v5);
result = 0xFFFFFFFFLL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func16(__int64 a1, char a2)
{
__int64 result; // rax
char v3[18]; // [rsp+Ch] [rbp-1Ch] BYREF
unsigned __int8 v4; // [rsp+1Eh] [rbp-Ah] BYREF
unsigned __int8 v5; // [rsp+1Fh] [rbp-9h]

v3[0] = a2;
func4(a1, 99);
serial_write((unsigned int)a1, v3, 1LL);
if ( (unsigned int)serial_read((unsigned int)a1, &v4, 2LL) == -1 )
err(1, "read erase response failed");
if ( v4 == 27 && v5 == 48 )
{
puts("Erase successfull");
result = 0LL;
}
else
{
printf("%x %x\n", v4, v5);
result = 0xFFFFFFFFLL;
}
return result;
}

original_code:
int
msr_erase (int fd, uint8_t tracks)
{
 uint8_t b[2];
 msr_cmd (fd, 0x63);
 serial_write (fd, &tracks, 1);
 if (serial_read (fd, b, 2) == -1)
  err(1, "read erase response failed");
 if (b[0] == 0x1B && b[1] == 0x30) {
  printf("Erase successfull\n");
  return (0);
 } else
  printf ("%x %x\n", b[0], b[1]);
 return (-1);
}

canonical_original_code:
int msr_erase(int fd, unsigned char tracks)
{
 unsigned char b[2];
 msr_cmd (fd, 0x63);
 serial_write (fd, &tracks, 1);
 if (serial_read (fd, b, 2) == -1)
  err(1, "read erase response failed");
 if (b[0] == 0x1B && b[1] == 0x30) {
  printf("Erase successfull\n");
  return (0);
 } else
  printf ("%x %x\n", b[0], b[1]);
 return (-1);
}

variable_types:
tracks
unsigned char


decompiled_code:
__int64 __fastcall msr_iso_write(__int64 a1, __int64 a2)
{
__int64 v2; // r12
__int64 v4; // rdx
__int64 v5; // rsi
__int16 v7[14]; // [rsp+Ch] [rbp-1Ch] BYREF

v2 = 1LL;
msr_cmd(a1, 119);
v7[0] = 29467;
serial_write((unsigned int)a1, v7, 2LL);
do
{
HIBYTE(v7[0]) = v2;
LOBYTE(v7[0]) = 27;
++v2;
serial_write((unsigned int)a1, v7, 2LL);
v4 = *(unsigned __int8 *)(a2 + 255);
v5 = a2;
a2 += 256LL;
serial_write((unsigned int)a1, v5, v4);
}
while ( v2 != 4 );
v7[0] = 7231;
serial_write((unsigned int)a1, v7, 2LL);
serial_readchar((unsigned int)a1, v7);
serial_readchar((unsigned int)a1, v7);
if ( LOBYTE(v7[0]) != 48 )
warnx("write failed");
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func17(__int64 a1, __int64 a2)
{
__int64 v2; // r12
__int64 v4; // rdx
__int64 v5; // rsi
__int16 v7[14]; // [rsp+Ch] [rbp-1Ch] BYREF

v2 = 1LL;
func4(a1, 119);
v7[0] = 29467;
serial_write((unsigned int)a1, v7, 2LL);
do
{
HIBYTE(v7[0]) = v2;
LOBYTE(v7[0]) = 27;
++v2;
serial_write((unsigned int)a1, v7, 2LL);
v4 = *(unsigned __int8 *)(a2 + 255);
v5 = a2;
a2 += 256LL;
serial_write((unsigned int)a1, v5, v4);
}
while ( v2 != 4 );
v7[0] = 7231;
serial_write((unsigned int)a1, v7, 2LL);
serial_readchar((unsigned int)a1, v7);
serial_readchar((unsigned int)a1, v7);
if ( LOBYTE(v7[0]) != 48 )
warnx("write failed");
return 0LL;
}

original_code:
int
msr_iso_write(int fd, msr_tracks_t * tracks)
{
 int i;
 uint8_t buf[4];
 msr_cmd (fd, 0x77);
 buf[0] = 0x1B;
 buf[1] = 0x73;
 serial_write (fd, buf, 2);
 for (i = 0; i < 3; i++) {
  buf[0] = 0x1B;
  buf[1] = i + 1;
  serial_write (fd, buf, 2);
  serial_write (fd, tracks->msr_tracks[i].msr_tk_data,
   tracks->msr_tracks[i].msr_tk_len);
 }
 buf[0] = 0x3F;
 buf[1] = 0x1C;
 serial_write (fd, buf, 2);
 serial_readchar (fd, &buf[0]);
 serial_readchar (fd, &buf[0]);
 if (buf[0] != 0x30)
  warnx("write failed");
 return (0);
}

canonical_original_code:
int msr_iso_write(int fd, struct msr_tracks *tracks)
{
 int i;
 unsigned char buf[4];
 msr_cmd (fd, 0x77);
 buf[0] = 0x1B;
 buf[1] = 0x73;
 serial_write (fd, buf, 2);
 for (i = 0; i < 3; i++) {
  buf[0] = 0x1B;
  buf[1] = i + 1;
  serial_write (fd, buf, 2);
  serial_write (fd, tracks->msr_tracks[i].msr_tk_data,
   tracks->msr_tracks[i].msr_tk_len);
 }
 buf[0] = 0x3F;
 buf[1] = 0x1C;
 serial_write (fd, buf, 2);
 serial_readchar (fd, &buf[0]);
 serial_readchar (fd, &buf[0]);
 if (buf[0] != 0x30)
  warnx("write failed");
 return (0);
}

variable_types:
buf
unsigned char [4]


decompiled_code:
__int64 __fastcall msr_raw_read(__int64 a1, __int64 a2)
{
int i; // ebp
_BYTE *v4; // rcx
__int64 v5; // rdx

if ( (unsigned int)msr_cmd(a1, 109) == -1 )
err(1, "Command write failed");
if ( (unsigned int)getstart(a1) == -1 )
err(1, "get start delimiter failed");
for ( i = 0; i != 3; gettrack_raw_isra_0((unsigned int)a1, i, v5, v4) )
{
++i;
v4 = (_BYTE *)(a2 + 255);
v5 = a2;
a2 += 256LL;
}
if ( (unsigned int)getend((unsigned int)a1) == -1 )
err(1, "read failed");
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func18(__int64 a1, __int64 a2)
{
int i; // ebp
_BYTE *v4; // rcx
__int64 v5; // rdx

if ( (unsigned int)func4(a1, 109) == -1 )
err(1, "Command write failed");
if ( (unsigned int)func1(a1) == -1 )
err(1, "get start delimiter failed");
for ( i = 0; i != 3; func2((unsigned int)a1, i, v5, v4) )
{
++i;
v4 = (_BYTE *)(a2 + 255);
v5 = a2;
a2 += 256LL;
}
if ( (unsigned int)func0((unsigned int)a1) == -1 )
err(1, "read failed");
return 0LL;
}

original_code:
int
msr_raw_read(int fd, msr_tracks_t * tracks)
{
 int r;
 int i;
 r = msr_cmd (fd, 0x6D);
 if (r == -1)
  err(1, "Command write failed");
 if (getstart (fd) == -1)
  err(1, "get start delimiter failed");
 for (i = 0; i < 3; i++)
  gettrack_raw (fd, i + 1, tracks->msr_tracks[i].msr_tk_data,
      &tracks->msr_tracks[i].msr_tk_len);
 if (getend (fd) == -1)
  err(1, "read failed");
 return (0);
}

canonical_original_code:
int msr_raw_read(int fd, struct msr_tracks *tracks)
{
 int r;
 int i;
 r = msr_cmd (fd, 0x6D);
 if (r == -1)
  err(1, "Command write failed");
 if (getstart (fd) == -1)
  err(1, "get start delimiter failed");
 for (i = 0; i < 3; i++)
  gettrack_raw (fd, i + 1, tracks->msr_tracks[i].msr_tk_data,
      &tracks->msr_tracks[i].msr_tk_len);
 if (getend (fd) == -1)
  err(1, "read failed");
 return (0);
}

variable_types: i int


decompiled_code:
__int64 __fastcall msr_raw_write(__int64 a1, __int64 a2)
{
__int64 v2; // r12
char v4; // al
__int64 v5; // rdx
__int64 v6; // rsi
__int16 v8; // [rsp+Ch] [rbp-1Ch] BYREF
char v9; // [rsp+Eh] [rbp-1Ah]

v2 = 1LL;
msr_cmd(a1, 110);
v8 = 29467;
serial_write((unsigned int)a1, &v8, 2LL);
do
{
v4 = *(_BYTE *)(a2 + 255);
HIBYTE(v8) = v2++;
LOBYTE(v8) = 27;
v9 = v4;
serial_write((unsigned int)a1, &v8, 3LL);
v5 = *(unsigned __int8 *)(a2 + 255);
v6 = a2;
a2 += 256LL;
serial_write((unsigned int)a1, v6, v5);
}
while ( v2 != 4 );
v8 = 7231;
serial_write((unsigned int)a1, &v8, 2LL);
serial_readchar((unsigned int)a1, &v8);
serial_readchar((unsigned int)a1, &v8);
if ( (_BYTE)v8 != 48 )
warnx("raw write failed");
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func19(__int64 a1, __int64 a2)
{
__int64 v2; // r12
char v4; // al
__int64 v5; // rdx
__int64 v6; // rsi
__int16 v8; // [rsp+Ch] [rbp-1Ch] BYREF
char v9; // [rsp+Eh] [rbp-1Ah]

v2 = 1LL;
func4(a1, 110);
v8 = 29467;
serial_write((unsigned int)a1, &v8, 2LL);
do
{
v4 = *(_BYTE *)(a2 + 255);
HIBYTE(v8) = v2++;
LOBYTE(v8) = 27;
v9 = v4;
serial_write((unsigned int)a1, &v8, 3LL);
v5 = *(unsigned __int8 *)(a2 + 255);
v6 = a2;
a2 += 256LL;
serial_write((unsigned int)a1, v6, v5);
}
while ( v2 != 4 );
v8 = 7231;
serial_write((unsigned int)a1, &v8, 2LL);
serial_readchar((unsigned int)a1, &v8);
serial_readchar((unsigned int)a1, &v8);
if ( (_BYTE)v8 != 48 )
warnx("raw write failed");
return 0LL;
}

original_code:
int
msr_raw_write(int fd, msr_tracks_t * tracks)
{
 int i;
 uint8_t buf[4];
 msr_cmd (fd, 0x6E);
 buf[0] = 0x1B;
 buf[1] = 0x73;
 serial_write (fd, buf, 2);
 for (i = 0; i < 3; i++) {
  buf[0] = 0x1B;
  buf[1] = i + 1;
  buf[2] = tracks->msr_tracks[i].msr_tk_len;
  serial_write (fd, buf, 3);
  serial_write (fd, tracks->msr_tracks[i].msr_tk_data,
   tracks->msr_tracks[i].msr_tk_len);
 }
 buf[0] = 0x3F;
 buf[1] = 0x1C;
 serial_write (fd, buf, 2);
 serial_readchar (fd, &buf[0]);
 serial_readchar (fd, &buf[0]);
 if (buf[0] != 0x30)
  warnx("raw write failed");
 return (0);
}

canonical_original_code:
int msr_raw_write(int fd, struct msr_tracks *tracks)
{
 int i;
 unsigned char buf[4];
 msr_cmd (fd, 0x6E);
 buf[0] = 0x1B;
 buf[1] = 0x73;
 serial_write (fd, buf, 2);
 for (i = 0; i < 3; i++) {
  buf[0] = 0x1B;
  buf[1] = i + 1;
  buf[2] = tracks->msr_tracks[i].msr_tk_len;
  serial_write (fd, buf, 3);
  serial_write (fd, tracks->msr_tracks[i].msr_tk_data,
   tracks->msr_tracks[i].msr_tk_len);
 }
 buf[0] = 0x3F;
 buf[1] = 0x1C;
 serial_write (fd, buf, 2);
 serial_readchar (fd, &buf[0]);
 serial_readchar (fd, &buf[0]);
 if (buf[0] != 0x30)
  warnx("raw write failed");
 return (0);
}


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

msr_reset(a1);
result = msr_commtest((unsigned int)a1);
if ( (_DWORD)result != -1 )
{
msr_reset((unsigned int)a1);
result = 0LL;
}
return result;
}

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

func14(a1);
result = func6((unsigned int)a1);
if ( (_DWORD)result != -1 )
{
func14((unsigned int)a1);
result = 0LL;
}
return result;
}

original_code:
int
msr_init(int fd)
{
 msr_reset (fd);
 if (msr_commtest (fd) == -1)
  return (-1);
 msr_reset (fd);
 return (0);
}


decompiled_code:
__int64 __fastcall msr_set_bpi(__int64 a1, unsigned __int8 a2)
{
__int64 result; // rax
char v3[18]; // [rsp+Ch] [rbp-1Ch] BYREF
char v4[10]; // [rsp+1Eh] [rbp-Ah] BYREF

v3[0] = a2;
msr_cmd(a1, 98);
serial_write((unsigned int)a1, v3, 1LL);
serial_read((unsigned int)a1, v4, 2LL);
if ( v4[0] == 27 && v4[1] == 48 )
{
printf("Set bits per inch to: %d\n", (unsigned __int8)v3[0]);
result = 0LL;
}
else
{
warnx("Set bpi failed\n");
result = 0xFFFFFFFFLL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func21(__int64 a1, unsigned __int8 a2)
{
__int64 result; // rax
char v3[18]; // [rsp+Ch] [rbp-1Ch] BYREF
char v4[10]; // [rsp+1Eh] [rbp-Ah] BYREF

v3[0] = a2;
func4(a1, 98);
serial_write((unsigned int)a1, v3, 1LL);
serial_read((unsigned int)a1, v4, 2LL);
if ( v4[0] == 27 && v4[1] == 48 )
{
printf("Set bits per inch to: %d\n", (unsigned __int8)v3[0]);
result = 0LL;
}
else
{
warnx("Set bpi failed\n");
result = 0xFFFFFFFFLL;
}
return result;
}

original_code:
int
msr_set_bpi (int fd, uint8_t bpi)
{
 uint8_t b[2];
 msr_cmd (fd, 0x62);
 serial_write (fd, &bpi, 1);
 serial_read (fd, &b, 2);
 if (b[0] == 0x1B && b[1] == 0x30) {
  printf("Set bits per inch to: %d\n", bpi);
  return (0);
 }
 warnx ("Set bpi failed\n");
 return (-1);
}

canonical_original_code:
int msr_set_bpi(int fd, unsigned char bpi)
{
 unsigned char b[2];
 msr_cmd (fd, 0x62);
 serial_write (fd, &bpi, 1);
 serial_read (fd, &b, 2);
 if (b[0] == 0x1B && b[1] == 0x30) {
  printf("Set bits per inch to: %d\n", bpi);
  return (0);
 }
 warnx ("Set bpi failed\n");
 return (-1);
}

variable_types:
bpi
unsigned char


decompiled_code:
__int64 __fastcall msr_set_bpc(__int64 a1, unsigned __int8 a2, unsigned __int8 a3, unsigned __int8 a4)
{
__int64 result; // rax
char v5[2]; // [rsp+Bh] [rbp-Dh] BYREF
unsigned __int8 v6; // [rsp+Dh] [rbp-Bh] BYREF
unsigned __int8 v7; // [rsp+Eh] [rbp-Ah]
unsigned __int8 v8; // [rsp+Fh] [rbp-9h]

v6 = a2;
v8 = a4;
v7 = a3;
msr_cmd(a1, 111);
serial_write((unsigned int)a1, &v6, 3LL);
serial_read((unsigned int)a1, v5, 2LL);
if ( v5[0] == 27 && v5[1] == 48 )
{
serial_read((unsigned int)a1, &v6, 3LL);
printf("Set bpc... %d %d %d\n", v6, v7, v8);
result = 0LL;
}
else
{
warnx("failed to set bpc");
result = 0xFFFFFFFFLL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func22(__int64 a1, unsigned __int8 a2, unsigned __int8 a3, unsigned __int8 a4)
{
__int64 result; // rax
char v5[2]; // [rsp+Bh] [rbp-Dh] BYREF
unsigned __int8 v6; // [rsp+Dh] [rbp-Bh] BYREF
unsigned __int8 v7; // [rsp+Eh] [rbp-Ah]
unsigned __int8 v8; // [rsp+Fh] [rbp-9h]

v6 = a2;
v8 = a4;
v7 = a3;
func4(a1, 111);
serial_write((unsigned int)a1, &v6, 3LL);
serial_read((unsigned int)a1, v5, 2LL);
if ( v5[0] == 27 && v5[1] == 48 )
{
serial_read((unsigned int)a1, &v6, 3LL);
printf("Set bpc... %d %d %d\n", v6, v7, v8);
result = 0LL;
}
else
{
warnx("failed to set bpc");
result = 0xFFFFFFFFLL;
}
return result;
}

original_code:
int
msr_set_bpc (int fd, uint8_t bpc1, uint8_t bpc2, uint8_t bpc3)
{
 uint8_t b[2];
 msr_bpc_t bpc;
 bpc.msr_bpctk1 = bpc1;
 bpc.msr_bpctk2 = bpc2;
 bpc.msr_bpctk3 = bpc3;
 msr_cmd (fd, 0x6F);
 serial_write (fd, &bpc, sizeof(bpc));
 serial_read (fd, &b, 2);
 if (b[0] == 0x1B && b[1] == 0x30) {
  serial_read (fd, &bpc, sizeof(bpc));
  printf ("Set bpc... %d %d %d\n", bpc.msr_bpctk1,
      bpc.msr_bpctk2, bpc.msr_bpctk3);
  return (0);
 }
 warnx("failed to set bpc");
 return (-1);
}

canonical_original_code:
int msr_set_bpc(int fd, unsigned char bpc1, unsigned char bpc2, unsigned char bpc3)
{
 unsigned char b[2];
 struct msr_bpc bpc;
 bpc.msr_bpctk1 = bpc1;
 bpc.msr_bpctk2 = bpc2;
 bpc.msr_bpctk3 = bpc3;
 msr_cmd (fd, 0x6F);
 serial_write (fd, &bpc, sizeof(bpc));
 serial_read (fd, &b, 2);
 if (b[0] == 0x1B && b[1] == 0x30) {
  serial_read (fd, &bpc, sizeof(bpc));
  printf ("Set bpc... %d %d %d\n", bpc.msr_bpctk1,
      bpc.msr_bpctk2, bpc.msr_bpctk3);
  return (0);
 }
 warnx("failed to set bpc");
 return (-1);
}

variable_types: struct msr_bpc { unsigned char msr_bpctk1; unsigned char msr_bpctk2; unsigned char msr_bpctk3; }


decompiled_code:
int __fastcall serial_setup(int fd, speed_t speed)
{
int result; // eax
tcflag_t v3; // eax
struct termios v4; // [rsp+0h] [rbp-58h] BYREF

result = tcgetattr(fd, &v4);
if ( result != -1 )
{
cfsetispeed(&v4, speed);
cfsetospeed(&v4, speed);
v4.c_lflag &= 0xFFFF7FB4;
v4.c_oflag &= 0xFFFFFFFE;
v4.c_cflag = v4.c_cflag & 0xFFFFFE8F | 0x8B0;
v3 = v4.c_iflag;
BYTE1(v3) = BYTE1(v4.c_iflag) & 0xE2;
v4.c_iflag = v3 | 5;
result = -(tcsetattr(fd, 0, &v4) == -1);
}
return result;
}

canonical_decompiled_code:
int __fastcall func7(int fd, speed_t speed)
{
int result; // eax
tcflag_t v3; // eax
struct termios v4; // [rsp+0h] [rbp-58h] BYREF

result = tcgetattr(fd, &v4);
if ( result != -1 )
{
cfsetispeed(&v4, speed);
cfsetospeed(&v4, speed);
v4.c_lflag &= 0xFFFF7FB4;
v4.c_oflag &= 0xFFFFFFFE;
v4.c_cflag = v4.c_cflag & 0xFFFFFE8F | 0x8B0;
v3 = v4.c_iflag;
BYTE1(v3) = BYTE1(v4.c_iflag) & 0xE2;
v4.c_iflag = v3 | 5;
result = -(tcsetattr(fd, 0, &v4) == -1);
}
return result;
}

original_code:
static int
serial_setup (int fd, speed_t baud)
{
        struct termios options;
 if (tcgetattr(fd, &options) == -1)
  return (-1);
 cfsetispeed(&options, baud);
 cfsetospeed(&options, baud);
 options.c_cflag |= (0004000 | 0000200);
 options.c_cflag &= ~0000400;
 options.c_cflag &= ~0000100;
 options.c_cflag &= ~0000060;
 options.c_cflag |= 0000060;
 options.c_lflag &= ~0000002;
 options.c_lflag &= ~0000010;
 options.c_lflag &= ~0000100;
 options.c_lflag &= ~0000001;
 options.c_lflag &= ~0100000;
 options.c_iflag &= ~0000400;
 options.c_iflag &= ~0002000;
 options.c_iflag &= ~0010000;
 options.c_iflag &= ~0004000;
 options.c_iflag |= 0000001;
 options.c_iflag |= 0000004;
 options.c_oflag &= ~0000001;
 if (tcsetattr(fd, 0, &options) == -1)
  return (-1);
 return (0);
}

canonical_original_code:
static int serial_setup(int fd, unsigned int baud)
{
        struct termios options;
 if (tcgetattr(fd, &options) == -1)
  return (-1);
 cfsetispeed(&options, baud);
 cfsetospeed(&options, baud);
 options.c_cflag |= (0004000 | 0000200);
 options.c_cflag &= ~0000400;
 options.c_cflag &= ~0000100;
 options.c_cflag &= ~0000060;
 options.c_cflag |= 0000060;
 options.c_lflag &= ~0000002;
 options.c_lflag &= ~0000010;
 options.c_lflag &= ~0000100;
 options.c_lflag &= ~0000001;
 options.c_lflag &= ~0100000;
 options.c_iflag &= ~0000400;
 options.c_iflag &= ~0002000;
 options.c_iflag &= ~0010000;
 options.c_iflag &= ~0004000;
 options.c_iflag |= 0000001;
 options.c_iflag |= 0000004;
 options.c_oflag &= ~0000001;
 if (tcsetattr(fd, 0, &options) == -1)
  return (-1);
 return (0);
}

variable_types:
baud
unsigned int

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


decompiled_code:
ssize_t __fastcall serial_readchar(int fd, _BYTE *a2)
{
ssize_t result; // rax
char buf[25]; // [rsp+Fh] [rbp-19h] BYREF

do
result = read(fd, buf, 1uLL);
while ( (_DWORD)result == -1 );
*a2 = buf[0];
return result;
}

canonical_decompiled_code:
ssize_t __fastcall func8(int fd, _BYTE *a2)
{
ssize_t result; // rax
char buf[25]; // [rsp+Fh] [rbp-19h] BYREF

do
result = read(fd, buf, 1uLL);
while ( (_DWORD)result == -1 );
*a2 = buf[0];
return result;
}

original_code:
int
serial_readchar (int fd, uint8_t * c)
{
 char b;
 int r;
 while ((r = read (fd, &b, 1)) == -1)
  ;
 if (r != -1) {
  *c = b;
 }
 return (r);
}

canonical_original_code:
int serial_readchar(int fd, unsigned char *c)
{
 char b;
 int r;
 while ((r = read (fd, &b, 1)) == -1)
  ;
 if (r != -1) {
  *c = b;
 }
 return (r);
}

variable_types:
c
unsigned char *

variable_types: b char

variable_types: r int


decompiled_code:
__int64 __fastcall serial_read(int fd, __int64 a2, __int64 a3)
{
__int64 v3; // rbp
__int64 v4; // rbx
char v6[25]; // [rsp+1h] [rbp-19h] BYREF

if ( !a3 )
return 0LL;
v3 = a2 + a3;
v4 = a2;
do
{
++v4;
serial_readchar(fd, v6);
*(_BYTE *)(v4 - 1) = v6[0];
}
while ( v4 != v3 );
return 0LL;
}

original_code:
int
serial_read (int fd, void * buf, size_t len)
{
 size_t i;
 uint8_t b, *p;
 p = buf;
 for (i = 0; i < len; i++) {
  serial_readchar (fd, &b);
  p[i] = b;
 }
 return (0);
}

canonical_original_code:
int serial_read(int fd, void *buf, unsigned long len)
{
 unsigned long i;
 unsigned char b; unsigned char *p;
 p = buf;
 for (i = 0; i < len; i++) {
  serial_readchar (fd, &b);
  p[i] = b;
 }
 return (0);
}

variable_types: fd int

variable_types:
buf
void *

variable_types:
len
unsigned long

variable_types:
i
unsigned long

variable_types:
b
unsigned char

variable_types:
p
unsigned char *


decompiled_code:
ssize_t __fastcall serial_write(int a1, const void *a2, size_t a3)
{
return write(a1, a2, a3);
}

canonical_decompiled_code:
ssize_t __fastcall func10(int a1, const void *a2, size_t a3)
{
return write(a1, a2, a3);
}

original_code:
int
serial_write (int fd, void * buf, size_t len)
{
 return (write (fd, buf, len));
}

canonical_original_code:
int serial_write(int fd, void *buf, unsigned long len)
{
 return (write (fd, buf, len));
}


decompiled_code:
int __fastcall serial_open(const char *a1, int *a2, int a3, speed_t a4)
{
int v5; // eax
int v6; // ebp
int result; // eax

v5 = open(a1, a3 | 0x101002);
if ( v5 == -1 )
return -1;
v6 = v5;
result = serial_setup(v5, a4);
if ( result )
{
close(v6);
result = -1;
}
else
{
*a2 = v6;
}
return result;
}

canonical_decompiled_code:
int __fastcall func11(const char *a1, int *a2, int a3, speed_t a4)
{
int v5; // eax
int v6; // ebp
int result; // eax

v5 = open(a1, a3 | 0x101002);
if ( v5 == -1 )
return -1;
v6 = v5;
result = func7(v5, a4);
if ( result )
{
close(v6);
result = -1;
}
else
{
*a2 = v6;
}
return result;
}

original_code:
int
serial_open(char *path, int * fd, int blocking, speed_t baud)
{
 int f;
 f = open(path, blocking | 02 | 04010000);
 if (f == -1)
  return (-1);
 if (serial_setup (f, baud) != 0) {
  close (f);
  return (-1);
 }
 *fd = f;
 return (0);
}

canonical_original_code:
int serial_open(char *path, int *fd, int blocking, unsigned int baud)
{
 int f;
 f = open(path, blocking | 02 | 04010000);
 if (f == -1)
  return (-1);
 if (serial_setup (f, baud) != 0) {
  close (f);
  return (-1);
 }
 *fd = f;
 return (0);
}

variable_types:
path
char *

variable_types:
fd
int *

variable_types: blocking int

variable_types: f int


decompiled_code:
__int64 __fastcall serial_close(int a1)
{
close(a1);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func12(int a1)
{
close(a1);
return 0LL;
}

original_code:
int
serial_close(int fd)
{
 close (fd);
 return (0);
}