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

if ( (unsigned int)switch_set_vlan_desc(0xFFFFFFFFLL, 0LL) != -1 )
_assert_fail("ret == -1", "vlan_rename.c", 0x26u, "test_rename_invalid");
result = _errno_location();
if ( *result != 22 )
_assert_fail("errno == EINVAL", "vlan_rename.c", 0x27u, "test_rename_invalid");
return result;
}

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

if ( (unsigned int)switch_set_vlan_desc(0xFFFFFFFFLL, 0LL) != -1 )
_assert_fail("ret == -1", "vlan_rename.c", 0x26u, "test_rename_invalid");
result = _errno_location();
if ( *result != 22 )
_assert_fail("errno == EINVAL", "vlan_rename.c", 0x27u, "test_rename_invalid");
return result;
}

original_code:
static void test_rename_invalid(void) {
 int ret;
 ret = switch_set_vlan_desc(-1, ((void *)0));
 ((void) sizeof ((ret == -1) ? 1 : 0), __extension__ ({ if (ret == -1) ; else __assert_fail ("ret == -1", "vlan_rename.c", 38, __extension__ __PRETTY_FUNCTION__); }));
 ((void) sizeof (((*__errno_location ()) == 22) ? 1 : 0), __extension__ ({ if ((*__errno_location ()) == 22) ; else __assert_fail ("errno == EINVAL", "vlan_rename.c", 39, __extension__ __PRETTY_FUNCTION__); }));
}

canonical_original_code:
static void test_rename_invalid() {
 int ret;
 ret = switch_set_vlan_desc(-1, ((void *)0));
 ((void) sizeof ((ret == -1) ? 1 : 0), __extension__ ({ if (ret == -1) ; else __assert_fail ("ret == -1", "vlan_rename.c", 38, __extension__ __PRETTY_FUNCTION__); }));
 ((void) sizeof (((*__errno_location ()) == 22) ? 1 : 0), __extension__ ({ if ((*__errno_location ()) == 22) ; else __assert_fail ("errno == EINVAL", "vlan_rename.c", 39, __extension__ __PRETTY_FUNCTION__); }));
}


repo: lisa-project/lisa-user

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

if ( (unsigned int)switch_set_vlan_desc(1LL, 0LL) != -1 )
_assert_fail("ret == -1", "vlan_rename.c", 0x2Eu, "test_rename_default");
result = _errno_location();
if ( *result != 1 )
_assert_fail("errno == EPERM", "vlan_rename.c", 0x2Fu, "test_rename_default");
return result;
}

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

if ( (unsigned int)switch_set_vlan_desc(1LL, 0LL) != -1 )
_assert_fail("ret == -1", "vlan_rename.c", 0x2Eu, "test_rename_default");
result = _errno_location();
if ( *result != 1 )
_assert_fail("errno == EPERM", "vlan_rename.c", 0x2Fu, "test_rename_default");
return result;
}

original_code:
static void test_rename_default(void) {
 int ret;
 ret = switch_set_vlan_desc(1, ((void *)0));
 ((void) sizeof ((ret == -1) ? 1 : 0), __extension__ ({ if (ret == -1) ; else __assert_fail ("ret == -1", "vlan_rename.c", 46, __extension__ __PRETTY_FUNCTION__); }));
 ((void) sizeof (((*__errno_location ()) == 1) ? 1 : 0), __extension__ ({ if ((*__errno_location ()) == 1) ; else __assert_fail ("errno == EPERM", "vlan_rename.c", 47, __extension__ __PRETTY_FUNCTION__); }));
}

canonical_original_code:
static void test_rename_default() {
 int ret;
 ret = switch_set_vlan_desc(1, ((void *)0));
 ((void) sizeof ((ret == -1) ? 1 : 0), __extension__ ({ if (ret == -1) ; else __assert_fail ("ret == -1", "vlan_rename.c", 46, __extension__ __PRETTY_FUNCTION__); }));
 ((void) sizeof (((*__errno_location ()) == 1) ? 1 : 0), __extension__ ({ if ((*__errno_location ()) == 1) ; else __assert_fail ("errno == EPERM", "vlan_rename.c", 47, __extension__ __PRETTY_FUNCTION__); }));
}

variable_types: ret int

return_type: void


decompiled_code:
__int64 test_rename_arbitrary()
{
int v0; // eax
int v1; // ebx
__int64 result; // rax
__int128 v3[2]; // [rsp+0h] [rbp-78h] BYREF
char s2[32]; // [rsp+20h] [rbp-58h] BYREF
char v5[56]; // [rsp+40h] [rbp-38h] BYREF

switch_init();
v0 = (*(__int64 (__fastcall **)(_QWORD, __int64))(sw_ops + 104LL))(sw_ops, 100LL);
v1 = v0;
if ( v0 == -1 )
{
if ( *_errno_location() != 17 )
_assert_fail("0", "vlan_rename.c", 0x3Cu, "test_rename_arbitrary");
v3[0] = (__int128)_mm_load_si128((const __m128i *)&LC8);
if ( (unsigned int)switch_get_vlan_desc(100LL, v5) )
_assert_fail("ret == 0", "vlan_rename.c", 0x4Cu, "test_rename_arbitrary");
if ( !strcmp((const char *)v3, v5) )
strcpy((char *)v3, "new desc");
}
else
{
if ( !v0 )
{
snprintf((char *)v3, 9uLL, "VLAN%04d", 100LL);
if ( (unsigned int)switch_set_vlan_desc(100LL, v3) )
{
result = (*(__int64 (__fastcall **)(_QWORD, __int64))(sw_ops + 112LL))(sw_ops, 100LL);
if ( (_DWORD)result )
_assert_fail("ret == 0", "vlan_rename.c", 0x42u, "test_rename_arbitrary");
return result;
}
}
v3[0] = (__int128)_mm_load_si128((const __m128i *)&LC8);
}
if ( (unsigned int)switch_set_vlan_desc(100LL, v3) )
_assert_fail("ret == 0", "vlan_rename.c", 0x52u, "test_rename_arbitrary");
if ( (unsigned int)switch_get_vlan_desc(100LL, s2) )
_assert_fail("ret == 0", "vlan_rename.c", 0x54u, "test_rename_arbitrary");
if ( strcmp((const char *)v3, s2) )
_assert_fail("strcmp(desc, eq_desc) == 0", "vlan_rename.c", 0x55u, "test_rename_arbitrary");
if ( v1 )
{
result = switch_set_vlan_desc(100LL, v5);
if ( (_DWORD)result )
_assert_fail("ret == 0", "vlan_rename.c", 0x61u, "test_rename_arbitrary");
}
else
{
if ( (*(unsigned int (__fastcall **)(_QWORD, __int64))(sw_ops + 112LL))(sw_ops, 100LL) )
_assert_fail("ret == 0", "vlan_rename.c", 0x5Au, "test_rename_arbitrary");
result = switch_del_vlan_desc(100LL);
if ( (_DWORD)result )
_assert_fail("ret == 0", "vlan_rename.c", 0x5Cu, "test_rename_arbitrary");
}
return result;
}

canonical_decompiled_code:
__int64 func2()
{
int v0; // eax
int v1; // ebx
__int64 result; // rax
__int128 v3[2]; // [rsp+0h] [rbp-78h] BYREF
char s2[32]; // [rsp+20h] [rbp-58h] BYREF
char v5[56]; // [rsp+40h] [rbp-38h] BYREF

switch_init();
v0 = (*(__int64 (__fastcall **)(_QWORD, __int64))(sw_ops + 104LL))(sw_ops, 100LL);
v1 = v0;
if ( v0 == -1 )
{
if ( *_errno_location() != 17 )
_assert_fail("0", "vlan_rename.c", 0x3Cu, "test_rename_arbitrary");
v3[0] = (__int128)_mm_load_si128((const __m128i *)&LC8);
if ( (unsigned int)switch_get_vlan_desc(100LL, v5) )
_assert_fail("ret == 0", "vlan_rename.c", 0x4Cu, "test_rename_arbitrary");
if ( !strcmp((const char *)v3, v5) )
strcpy((char *)v3, "new desc");
}
else
{
if ( !v0 )
{
snprintf((char *)v3, 9uLL, "VLAN%04d", 100LL);
if ( (unsigned int)switch_set_vlan_desc(100LL, v3) )
{
result = (*(__int64 (__fastcall **)(_QWORD, __int64))(sw_ops + 112LL))(sw_ops, 100LL);
if ( (_DWORD)result )
_assert_fail("ret == 0", "vlan_rename.c", 0x42u, "test_rename_arbitrary");
return result;
}
}
v3[0] = (__int128)_mm_load_si128((const __m128i *)&LC8);
}
if ( (unsigned int)switch_set_vlan_desc(100LL, v3) )
_assert_fail("ret == 0", "vlan_rename.c", 0x52u, "test_rename_arbitrary");
if ( (unsigned int)switch_get_vlan_desc(100LL, s2) )
_assert_fail("ret == 0", "vlan_rename.c", 0x54u, "test_rename_arbitrary");
if ( strcmp((const char *)v3, s2) )
_assert_fail("strcmp(desc, eq_desc) == 0", "vlan_rename.c", 0x55u, "test_rename_arbitrary");
if ( v1 )
{
result = switch_set_vlan_desc(100LL, v5);
if ( (_DWORD)result )
_assert_fail("ret == 0", "vlan_rename.c", 0x61u, "test_rename_arbitrary");
}
else
{
if ( (*(unsigned int (__fastcall **)(_QWORD, __int64))(sw_ops + 112LL))(sw_ops, 100LL) )
_assert_fail("ret == 0", "vlan_rename.c", 0x5Au, "test_rename_arbitrary");
result = switch_del_vlan_desc(100LL);
if ( (_DWORD)result )
_assert_fail("ret == 0", "vlan_rename.c", 0x5Cu, "test_rename_arbitrary");
}
return result;
}

original_code:
static void test_rename_arbitrary(void) {
 int add_ret, ret;
 char desc[31 + 1], eq_desc[31 + 1];
 char bkp_desc[31 + 1];
 switch_init();
 add_ret = sw_ops->vlan_add(sw_ops, 100);
 if (add_ret == -1 && (*__errno_location ()) != 17)
  ((void) sizeof ((0) ? 1 : 0), __extension__ ({ if (0) ; else __assert_fail ("0", "vlan_rename.c", 60, __extension__ __PRETTY_FUNCTION__); }));
 if (add_ret == 0) {
  snprintf(desc, 9, "VLAN%04d", (100));
  ret = switch_set_vlan_desc(100, desc);
  if (ret) {
   ret = sw_ops->vlan_del(sw_ops, 100);
   ((void) sizeof ((ret == 0) ? 1 : 0), __extension__ ({ if (ret == 0) ; else __assert_fail ("ret == 0", "vlan_rename.c", 66, __extension__ __PRETTY_FUNCTION__); }));
   return;
  }
 }
 strcpy(desc, "new description");
 if (add_ret == -1) {
  ret = switch_get_vlan_desc(100, bkp_desc);
  ((void) sizeof ((ret == 0) ? 1 : 0), __extension__ ({ if (ret == 0) ; else __assert_fail ("ret == 0", "vlan_rename.c", 76, __extension__ __PRETTY_FUNCTION__); }));
  if (strcmp(desc, bkp_desc) == 0)
   strcpy(desc, "new desc");
 }
 ret = switch_set_vlan_desc(100, desc);
 ((void) sizeof ((ret == 0) ? 1 : 0), __extension__ ({ if (ret == 0) ; else __assert_fail ("ret == 0", "vlan_rename.c", 82, __extension__ __PRETTY_FUNCTION__); }));
 ret= switch_get_vlan_desc(100, eq_desc);
 ((void) sizeof ((ret == 0) ? 1 : 0), __extension__ ({ if (ret == 0) ; else __assert_fail ("ret == 0", "vlan_rename.c", 84, __extension__ __PRETTY_FUNCTION__); }));
 ((void) sizeof ((strcmp(desc, eq_desc) == 0) ? 1 : 0), __extension__ ({ if (strcmp(desc, eq_desc) == 0) ; else __assert_fail ("strcmp(desc, eq_desc) == 0", "vlan_rename.c", 85, __extension__ __PRETTY_FUNCTION__); }));
 if (add_ret == 0) {
  ret = sw_ops->vlan_del(sw_ops, 100);
  ((void) sizeof ((ret == 0) ? 1 : 0), __extension__ ({ if (ret == 0) ; else __assert_fail ("ret == 0", "vlan_rename.c", 90, __extension__ __PRETTY_FUNCTION__); }));
  ret = switch_del_vlan_desc(100);
  ((void) sizeof ((ret == 0) ? 1 : 0), __extension__ ({ if (ret == 0) ; else __assert_fail ("ret == 0", "vlan_rename.c", 92, __extension__ __PRETTY_FUNCTION__); }));
 }
 else {
  ret = switch_set_vlan_desc(100, bkp_desc);
  ((void) sizeof ((ret == 0) ? 1 : 0), __extension__ ({ if (ret == 0) ; else __assert_fail ("ret == 0", "vlan_rename.c", 97, __extension__ __PRETTY_FUNCTION__); }));
 }
}

canonical_original_code:
static void test_rename_arbitrary() {
 int add_ret; int ret;
 char desc[-1]; char eq_desc[-1];
 char bkp_desc[-1];
 switch_init();
 add_ret = sw_ops->vlan_add(sw_ops, 100);
 if (add_ret == -1 && (*__errno_location ()) != 17)
  ((void) sizeof ((0) ? 1 : 0), __extension__ ({ if (0) ; else __assert_fail ("0", "vlan_rename.c", 60, __extension__ __PRETTY_FUNCTION__); }));
 if (add_ret == 0) {
  snprintf(desc, 9, "VLAN%04d", (100));
  ret = switch_set_vlan_desc(100, desc);
  if (ret) {
   ret = sw_ops->vlan_del(sw_ops, 100);
   ((void) sizeof ((ret == 0) ? 1 : 0), __extension__ ({ if (ret == 0) ; else __assert_fail ("ret == 0", "vlan_rename.c", 66, __extension__ __PRETTY_FUNCTION__); }));
   return;
  }
 }
 strcpy(desc, "new description");
 if (add_ret == -1) {
  ret = switch_get_vlan_desc(100, bkp_desc);
  ((void) sizeof ((ret == 0) ? 1 : 0), __extension__ ({ if (ret == 0) ; else __assert_fail ("ret == 0", "vlan_rename.c", 76, __extension__ __PRETTY_FUNCTION__); }));
  if (strcmp(desc, bkp_desc) == 0)
   strcpy(desc, "new desc");
 }
 ret = switch_set_vlan_desc(100, desc);
 ((void) sizeof ((ret == 0) ? 1 : 0), __extension__ ({ if (ret == 0) ; else __assert_fail ("ret == 0", "vlan_rename.c", 82, __extension__ __PRETTY_FUNCTION__); }));
 ret= switch_get_vlan_desc(100, eq_desc);
 ((void) sizeof ((ret == 0) ? 1 : 0), __extension__ ({ if (ret == 0) ; else __assert_fail ("ret == 0", "vlan_rename.c", 84, __extension__ __PRETTY_FUNCTION__); }));
 ((void) sizeof ((strcmp(desc, eq_desc) == 0) ? 1 : 0), __extension__ ({ if (strcmp(desc, eq_desc) == 0) ; else __assert_fail ("strcmp(desc, eq_desc) == 0", "vlan_rename.c", 85, __extension__ __PRETTY_FUNCTION__); }));
 if (add_ret == 0) {
  ret = sw_ops->vlan_del(sw_ops, 100);
  ((void) sizeof ((ret == 0) ? 1 : 0), __extension__ ({ if (ret == 0) ; else __assert_fail ("ret == 0", "vlan_rename.c", 90, __extension__ __PRETTY_FUNCTION__); }));
  ret = switch_del_vlan_desc(100);
  ((void) sizeof ((ret == 0) ? 1 : 0), __extension__ ({ if (ret == 0) ; else __assert_fail ("ret == 0", "vlan_rename.c", 92, __extension__ __PRETTY_FUNCTION__); }));
 }
 else {
  ret = switch_set_vlan_desc(100, bkp_desc);
  ((void) sizeof ((ret == 0) ? 1 : 0), __extension__ ({ if (ret == 0) ; else __assert_fail ("ret == 0", "vlan_rename.c", 97, __extension__ __PRETTY_FUNCTION__); }));
 }
}

variable_types:
desc
char [-1]


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
test_rename_invalid();
puts("Rename Invalid test susccesful");
test_rename_default();
puts("Rename Default test susccesful");
test_rename_arbitrary("Rename Default test susccesful", argv);
puts("Rename vlan tests susccesful");
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
func0();
puts("Rename Invalid test susccesful");
func1();
puts("Rename Default test susccesful");
func2("Rename Default test susccesful", argv);
puts("Rename vlan tests susccesful");
return 0;
}

original_code:
int main(int argc, char **argv) {
 test_rename_invalid();
 printf("Rename Invalid test susccesful\n");
 test_rename_default();
 printf("Rename Default test susccesful\n");
 test_rename_arbitrary();
 printf("Rename vlan tests susccesful\n");
 return 0;
}

variable_types: argc int

variable_types:
argv
char **

return_type: int


decompiled_code:
__int64 __fastcall cli_mask_apply(_DWORD *a1, int a2)
{
if ( a1 )
{
while ( *a1 )
{
if ( (*a1 & a2) == 0 )
return 0LL;
++a1;
}
}
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func0(_DWORD *a1, int a2)
{
if ( a1 )
{
while ( *a1 )
{
if ( (*a1 & a2) == 0 )
return 0LL;
++a1;
}
}
return 1LL;
}

original_code:
static __inline__ int cli_mask_apply(uint32_t *mask, uint32_t filter) {
 if (!mask)
  return 1;
 while (*mask) {
  if (!(*mask & filter))
   return 0;
  mask++;
 }
 return 1;
}

canonical_original_code:
static __inline__ int cli_mask_apply(unsigned int *mask, unsigned int filter) {
 if (!mask)
  return 1;
 while (*mask) {
  if (!(*mask & filter))
   return 0;
  mask++;
 }
 return 1;
}

variable_types:
mask
unsigned int *

variable_types:
filter
unsigned int


decompiled_code:
__int64 rlshell_ctrl_l()
{
return 0LL;
}

canonical_decompiled_code:
__int64 func1()
{
return 0LL;
}

original_code:
int rlshell_ctrl_l(int i, int j)
{
 return 0;
}

variable_types: i int

variable_types: j int


decompiled_code:
__int64 rlshell_ctrl_z()
{
if ( *(_DWORD *)(currctx + 92) )
{
puts("^Z");
ctrl_z = 1;
rl_done = 1;
}
return 0LL;
}

canonical_decompiled_code:
__int64 func2()
{
if ( *(_DWORD *)(currctx + 92) )
{
puts("^Z");
ctrl_z = 1;
rl_done = 1;
}
return 0LL;
}

original_code:
int rlshell_ctrl_z(int i, int j)
{
 if (!currctx->enable_ctrl_z)
  return 0;
 printf("^Z\n");
 ctrl_z = 1;
 rl_done = 1;
 return 0;
}


decompiled_code:
__int64 rlshell_ctrl_c()
{
putchar(10);
rl_replace_line(&LC2, 1LL);
rl_forced_update_display();
return 0LL;
}

canonical_decompiled_code:
__int64 func4()
{
putchar(10);
rl_replace_line(&LC2, 1LL);
rl_forced_update_display();
return 0LL;
}

original_code:
int rlshell_ctrl_c(int i, int j)
{
 printf("\n");
 rl_replace_line("", 1);
 rl_forced_update_display();
 return 0;
}


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

rl_prep_terminal();
tcgetattr(0, &v1);
v1.c_lflag &= 0xFFFFFFFE;
return tcsetattr(0, 0, &v1);
}

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

rl_prep_terminal();
tcgetattr(0, &v1);
v1.c_lflag &= 0xFFFFFFFE;
return tcsetattr(0, 0, &v1);
}

original_code:
void rlshell_prep_terminal(int meta_flag)
{
 struct termios t;
 rl_prep_terminal(meta_flag);
 tcgetattr(0, &t);
 t.c_lflag &= ~0000001;
 tcsetattr(0, 0, &t);
}

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:
int rlshell_invalid_cmd()
{
return printf("%% Unrecognized command\n");
}

canonical_decompiled_code:
int func7()
{
return printf("%% Unrecognized command\n");
}

original_code:
void rlshell_invalid_cmd(void)
{
 printf("%% Unrecognized command\n");
}

canonical_original_code:
void rlshell_invalid_cmd()
{
 printf("%% Unrecognized command\n");
}


decompiled_code:
int __fastcall rlshell_ambiguous_cmd(const char *a1)
{
return printf("%% Ambiguous command: \"%s\"\n", a1);
}

canonical_decompiled_code:
int __fastcall func8(const char *a1)
{
return printf("%% Ambiguous command: \"%s\"\n", a1);
}

original_code:
void rlshell_ambiguous_cmd(char *cmd)
{
 printf("%% Ambiguous command: \"%s\"\n", cmd);
}

variable_types:
cmd
char *


decompiled_code:
int rlshell_incomplete_cmd()
{
return printf("%% Incomplete command.\n");
}

canonical_decompiled_code:
int func9()
{
return printf("%% Incomplete command.\n");
}

original_code:
void rlshell_incomplete_cmd(char *cmd)
{
 printf("%% Incomplete command.\n");
}


decompiled_code:
int __fastcall rlshell_extra_input(unsigned int a1)
{
char s[18]; // [rsp+6h] [rbp-12h] BYREF

snprintf(s, 0xAuLL, "%%%dc^\n", a1);
printf(s, 32LL);
return printf("%% Invalid input detected at '^' marker.\n\n");
}

canonical_decompiled_code:
int __fastcall func10(unsigned int a1)
{
char s[18]; // [rsp+6h] [rbp-12h] BYREF

snprintf(s, 0xAuLL, "%%%dc^\n", a1);
printf(s, 32LL);
return printf("%% Invalid input detected at '^' marker.\n\n");
}

original_code:
void rlshell_extra_input(int off)
{
 char fmt[10];
 snprintf(fmt, sizeof(fmt), "%%%dc^\n", off);
 printf(fmt, ' ');
 printf("%% Invalid input detected at '^' marker.\n\n");
}

variable_types: off int

variable_types:
fmt
char [10]


decompiled_code:
void __fastcall rlshell_rejected_cmd(void *ptr)
{
if ( ptr )
{
printf("Command rejected: %s\n", (const char *)ptr);
free(ptr);
}
else
{
puts("Command rejected");
}
}

canonical_decompiled_code:
void __fastcall func11(void *ptr)
{
if ( ptr )
{
printf("Command rejected: %s\n", (const char *)ptr);
free(ptr);
}
else
{
puts("Command rejected");
}
}

original_code:
void rlshell_rejected_cmd(char *reason)
{
 if (reason == ((void *)0))
  printf("Command rejected\n");
 else {
  printf("Command rejected: %s\n", reason);
  free(reason);
 }
}

variable_types:
reason
char *


decompiled_code:
void __fastcall rlshell_warning_cmd(void *ptr)
{
if ( ptr )
{
puts((const char *)ptr);
free(ptr);
}
}

canonical_decompiled_code:
void __fastcall func12(void *ptr)
{
if ( ptr )
{
puts((const char *)ptr);
free(ptr);
}
}

original_code:
void rlshell_warning_cmd(char *reason)
{
 if (reason == ((void *)0))
  return;
 puts(reason);
 free(reason);
}


decompiled_code:
int rlshell_go_ahead()
{
return puts(" <cr>");
}

canonical_decompiled_code:
int func13()
{
return puts(" <cr>");
}

original_code:
void rlshell_go_ahead(void)
{
 printf("  <cr>\n");
}

canonical_original_code:
void rlshell_go_ahead()
{
 printf("  <cr>\n");
}


decompiled_code:
__int64 rlshell_init()
{
__int64 v0; // rax
__int64 v1; // rax
__int64 v2; // rax

rl_readline_name = "rlshell";
rl_prep_term_function = rlshell_prep_terminal;
rl_bind_key(63LL, rlshell_help);
rl_bind_key(9LL, rlshell_completion);
v0 = rl_get_keymap();
rl_set_key("\\C-l", rlshell_ctrl_l, v0);
v1 = rl_get_keymap();
rl_set_key("\\C-z", rlshell_ctrl_z, v1);
v2 = rl_get_keymap();
rl_set_key("\\C-c", rlshell_ctrl_c, v2);
return 0LL;
}

canonical_decompiled_code:
__int64 func18()
{
__int64 v0; // rax
__int64 v1; // rax
__int64 v2; // rax

rl_readline_name = "rlshell";
rl_prep_term_function = rlshell_prep_terminal;
rl_bind_key(63LL, rlshell_help);
rl_bind_key(9LL, rlshell_completion);
v0 = rl_get_keymap();
rl_set_key("\\C-l", rlshell_ctrl_l, v0);
v1 = rl_get_keymap();
rl_set_key("\\C-z", rlshell_ctrl_z, v1);
v2 = rl_get_keymap();
rl_set_key("\\C-c", rlshell_ctrl_c, v2);
return 0LL;
}

original_code:
int rlshell_init(void)
{
 ;
 rl_readline_name = "rlshell";
 rl_prep_term_function = rlshell_prep_terminal;
 rl_bind_key('?', rlshell_help);
 rl_bind_key('\t', rlshell_completion);
 rl_set_key("\\C-l", rlshell_ctrl_l, rl_get_keymap());
 rl_set_key("\\C-z", rlshell_ctrl_z, rl_get_keymap());
 rl_set_key("\\C-c", rlshell_ctrl_c, rl_get_keymap());
 return 0;
}

canonical_original_code:
int rlshell_init()
{
 ;
 rl_readline_name = "rlshell";
 rl_prep_term_function = rlshell_prep_terminal;
 rl_bind_key('?', rlshell_help);
 rl_bind_key('\t', rlshell_completion);
 rl_set_key("\\C-l", rlshell_ctrl_l, rl_get_keymap());
 rl_set_key("\\C-z", rlshell_ctrl_z, rl_get_keymap());
 rl_set_key("\\C-c", rlshell_ctrl_c, rl_get_keymap());
 return 0;
}


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

if ( !ptr )
_assert_fail("s", "rstp_client.c", 0x3Fu, "rstp_session_end");
v2 = (void *)*((_QWORD *)ptr + 9);
if ( v2 )
free(v2);
if ( *(_DWORD *)ptr != -1 )
mq_close();
if ( *((_DWORD *)ptr + 1) != -1 )
{
mq_close();
mq_unlink((char *)ptr + 40);
}
free(ptr);
}

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

if ( !ptr )
_assert_fail("s", "rstp_client.c", 0x3Fu, "rstp_session_end");
v2 = (void *)*((_QWORD *)ptr + 9);
if ( v2 )
free(v2);
if ( *(_DWORD *)ptr != -1 )
mq_close();
if ( *((_DWORD *)ptr + 1) != -1 )
{
mq_close();
mq_unlink((char *)ptr + 40);
}
free(ptr);
}

original_code:
void
rstp_session_end(struct rstp_session *s)
{
 ((void) sizeof ((s) ? 1 : 0), __extension__ ({ if (s) ; else __assert_fail ("s", "rstp_client.c", 63, __extension__ __PRETTY_FUNCTION__); }));
 if (s->response)
  free(s->response);
 if (s->sq != -1) {
  mq_close(s->sq);
 }
 if (s->rq != -1) {
  mq_close(s->rq);
  mq_unlink(s->rq_name);
 }
 free(s);
}

variable_types: struct rstp_session { int sq; char sq_name[32]; char *response; int max_msg_len; } *


decompiled_code:
char *rstp_session_start()
{
char *v0; // rax
char *v1; // r12
char *v2; // rbp
char *v3; // r13
int v4; // eax
unsigned int v5; // eax
int v6; // eax
int v7; // edi
void *v8; // rax
__int64 v10; // [rsp+0h] [rbp-58h] BYREF
__int64 v11; // [rsp+10h] [rbp-48h]

v0 = (char *)malloc(0x58uLL);
v1 = v0;
if ( !v0 )
return v1;
v2 = v0 + 40;
v3 = v0 + 8;
*(_OWORD *)(v0 + 40) = 0LL;
*(_OWORD *)(v0 + 56) = 0LL;
*(_OWORD *)(v0 + 72) = 0LL;
*(_QWORD *)v0 = -1LL;
*(_OWORD *)(v0 + 8) = 0LL;
*(_OWORD *)(v0 + 24) = 0LL;
snprintf(v0 + 8, 0x20uLL, "/lisa-rstp-%d", 0LL);
v1[39] = 0;
v4 = mq_open(v3, 1LL);
*(_DWORD *)v1 = v4;
if ( v4 < 0 )
{
perror("Could not open send queue\n");
}
else
{
*(_OWORD *)(v1 + 40) = 0LL;
*((_OWORD *)v2 + 1) = 0LL;
v5 = getpid();
snprintf(v2, 0x20uLL, "/lisa-rstp-%d", v5);
v1[71] = 0;
v6 = mq_open(v2, 64LL);
*((_DWORD *)v1 + 1) = v6;
if ( v6 < 0 )
{
puts("Could not open recv queue");
}
else if ( (int)mq_getattr((unsigned int)v6, &v10, 0.0) < 0 )
{
puts("Could not get attributes");
}
else
{
v7 = v11;
*((_DWORD *)v1 + 20) = v11;
v8 = malloc(v7);
*((_QWORD *)v1 + 9) = v8;
if ( v8 )
return v1;
puts("Could not allocate mem");
}
}
rstp_session_end(v1);
return 0LL;
}

canonical_decompiled_code:
char *func1()
{
char *v0; // rax
char *v1; // r12
char *v2; // rbp
char *v3; // r13
int v4; // eax
unsigned int v5; // eax
int v6; // eax
int v7; // edi
void *v8; // rax
__int64 v10; // [rsp+0h] [rbp-58h] BYREF
__int64 v11; // [rsp+10h] [rbp-48h]

v0 = (char *)malloc(0x58uLL);
v1 = v0;
if ( !v0 )
return v1;
v2 = v0 + 40;
v3 = v0 + 8;
*(_OWORD *)(v0 + 40) = 0LL;
*(_OWORD *)(v0 + 56) = 0LL;
*(_OWORD *)(v0 + 72) = 0LL;
*(_QWORD *)v0 = -1LL;
*(_OWORD *)(v0 + 8) = 0LL;
*(_OWORD *)(v0 + 24) = 0LL;
snprintf(v0 + 8, 0x20uLL, "/lisa-rstp-%d", 0LL);
v1[39] = 0;
v4 = mq_open(v3, 1LL);
*(_DWORD *)v1 = v4;
if ( v4 < 0 )
{
perror("Could not open send queue\n");
}
else
{
*(_OWORD *)(v1 + 40) = 0LL;
*((_OWORD *)v2 + 1) = 0LL;
v5 = getpid();
snprintf(v2, 0x20uLL, "/lisa-rstp-%d", v5);
v1[71] = 0;
v6 = mq_open(v2, 64LL);
*((_DWORD *)v1 + 1) = v6;
if ( v6 < 0 )
{
puts("Could not open recv queue");
}
else if ( (int)mq_getattr((unsigned int)v6, &v10, 0.0) < 0 )
{
puts("Could not get attributes");
}
else
{
v7 = v11;
*((_DWORD *)v1 + 20) = v11;
v8 = malloc(v7);
*((_QWORD *)v1 + 9) = v8;
if ( v8 )
return v1;
puts("Could not allocate mem");
}
}
func0(v1);
return 0LL;
}

original_code:
struct rstp_session *
rstp_session_start(void)
{
 struct rstp_session *s;
 struct mq_attr attr;
 if (!(s = (struct rstp_session *)malloc(sizeof(struct rstp_session))))
  return ((void *)0);
 memset(s, 0, sizeof(struct rstp_session));
 s->sq = s->rq = -1;
 memset(s->sq_name, 0, sizeof(s->sq_name));
 snprintf(s->sq_name, sizeof(s->sq_name), "/lisa-rstp-%d", 0);
 s->sq_name[sizeof(s->sq_name) - 1] = '\0';
 if ((s->sq = mq_open(s->sq_name, 01)) < 0) {
  perror("Could not open send queue\n");
  goto out_err;
 }
 memset(s->rq_name, 0, sizeof(s->rq_name));
 snprintf(s->rq_name, sizeof(s->rq_name), "/lisa-rstp-%d", getpid());
 s->rq_name[sizeof(s->rq_name) - 1] = '\0';
 if ((s->rq = mq_open(s->rq_name, 0100 | 00, 0666, ((void *)0))) < 0) {
  printf("Could not open recv queue\n");
  goto out_err;
 }
 if (mq_getattr(s->rq, &attr) < 0) {
  printf("Could not get attributes\n");
  goto out_err;
 }
 s->max_msg_len = attr.mq_msgsize;
 if (!(s->response = malloc(s->max_msg_len))) {
  printf("Could not allocate mem\n");
  goto out_err;
 }
 return s;
out_err:
 rstp_session_end(s);
 return ((void *)0);
}

canonical_original_code:
struct rstp_session *rstp_session_start()
{
 struct rstp_session *s;
 struct mq_attr attr;
 if (!(s = (struct rstp_session *)malloc(sizeof(struct rstp_session))))
  return ((void *)0);
 memset(s, 0, sizeof(struct rstp_session));
 s->sq = s->rq = -1;
 memset(s->sq_name, 0, sizeof(s->sq_name));
 snprintf(s->sq_name, sizeof(s->sq_name), "/lisa-rstp-%d", 0);
 s->sq_name[sizeof(s->sq_name) - 1] = '\0';
 if ((s->sq = mq_open(s->sq_name, 01)) < 0) {
  perror("Could not open send queue\n");
  goto out_err;
 }
 memset(s->rq_name, 0, sizeof(s->rq_name));
 snprintf(s->rq_name, sizeof(s->rq_name), "/lisa-rstp-%d", getpid());
 s->rq_name[sizeof(s->rq_name) - 1] = '\0';
 if ((s->rq = mq_open(s->rq_name, 0100 | 00, 0666, ((void *)0))) < 0) {
  printf("Could not open recv queue\n");
  goto out_err;
 }
 if (mq_getattr(s->rq, &attr) < 0) {
  printf("Could not get attributes\n");
  goto out_err;
 }
 s->max_msg_len = attr.mq_msgsize;
 if (!(s->response = malloc(s->max_msg_len))) {
  printf("Could not allocate mem\n");
  goto out_err;
 }
 return s;
out_err:
 rstp_session_end(s);
 return ((void *)0);
}

variable_types: struct mq_attr { long mq_flags; long mq_maxmsg; long mq_msgsize; long mq_curmsgs; long __pad[4]; }

return_type: struct rstp_session { int sq; char sq_name[32]; char *response; int max_msg_len; } *


decompiled_code:
__int64 __fastcall rstp_session_recv(__int64 a1)
{
__int64 v1; // rdx
__int64 v2; // rsi
__int64 v3; // rdi
__int64 result; // rax
unsigned int v5; // ebx
time_t timer; // [rsp+8h] [rbp-30h] BYREF
__int128 v7; // [rsp+10h] [rbp-28h] BYREF

if ( !a1 )
_assert_fail("s", "rstp_client.c", 0x55u, "rstp_session_recv");
v7 = 0LL;
time(&timer);
v1 = *(int *)(a1 + 80);
v2 = *(_QWORD *)(a1 + 72);
v3 = *(unsigned int *)(a1 + 4);
*(_QWORD *)&v7 = timer + 3;
LODWORD(result) = mq_timedreceive(v3, v2, v1, 0LL, &v7);
v5 = result;
if ( (int)result >= 0 )
return (unsigned int)result;
fprintf(stderr, "No message received from rstpd in %d seconds.\nDisabling rstp in this session.\n", 3LL);
return v5;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1)
{
__int64 v1; // rdx
__int64 v2; // rsi
__int64 v3; // rdi
__int64 result; // rax
unsigned int v5; // ebx
time_t timer; // [rsp+8h] [rbp-30h] BYREF
__int128 v7; // [rsp+10h] [rbp-28h] BYREF

if ( !a1 )
_assert_fail("s", "rstp_client.c", 0x55u, "rstp_session_recv");
v7 = 0LL;
time(&timer);
v1 = *(int *)(a1 + 80);
v2 = *(_QWORD *)(a1 + 72);
v3 = *(unsigned int *)(a1 + 4);
*(_QWORD *)&v7 = timer + 3;
LODWORD(result) = mq_timedreceive(v3, v2, v1, 0LL, &v7);
v5 = result;
if ( (int)result >= 0 )
return (unsigned int)result;
fprintf(stderr, "No message received from rstpd in %d seconds.\nDisabling rstp in this session.\n", 3LL);
return v5;
}

original_code:
int
rstp_session_recv(struct rstp_session *s)
{
 struct timespec ts;
 time_t ns;
 int err;
 ((void) sizeof ((s) ? 1 : 0), __extension__ ({ if (s) ; else __assert_fail ("s", "rstp_client.c", 85, __extension__ __PRETTY_FUNCTION__); }));
 memset(&ts, 0, sizeof(ts));
 time(&ns);
 ts.tv_sec = ns + 3;
 if ((err = mq_timedreceive(s->rq, s->response, s->max_msg_len, ((void *)0), &ts)) < 0) {
  fprintf(stderr, "No message received from rstpd in %d seconds.\n"
   "Disabling rstp in this session.\n", 3);
 }
 return err;
}

canonical_original_code:
int rstp_session_recv(struct rstp_session *s)
{
 struct timespec ts;
 long ns;
 int err;
 ((void) sizeof ((s) ? 1 : 0), __extension__ ({ if (s) ; else __assert_fail ("s", "rstp_client.c", 85, __extension__ __PRETTY_FUNCTION__); }));
 memset(&ts, 0, sizeof(ts));
 time(&ns);
 ts.tv_sec = ns + 3;
 if ((err = mq_timedreceive(s->rq, s->response, s->max_msg_len, ((void *)0), &ts)) < 0) {
  fprintf(stderr, "No message received from rstpd in %d seconds.\n"
   "Disabling rstp in this session.\n", 3);
 }
 return err;
}

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

variable_types: ns long

variable_types: err int

user_defined_types: struct rstp_session { int sq; char sq_name[32]; char *response; int max_msg_len; }


decompiled_code:
__int64 __fastcall rstp_set_interface(unsigned int *a1, int a2, int a3)
{
__pid_t v3; // eax
__int64 v4; // rdi
int v5; // eax
unsigned int v7; // [rsp+Ch] [rbp-6Ch]
int v8[26]; // [rsp+10h] [rbp-68h] BYREF

if ( !a1 )
_assert_fail("session", "rstp_client.c", 0x69u, "rstp_set_interface");
memset(v8, 0, 0x48uLL);
v8[0] = a3 == 0;
v8[18] = 0;
v3 = getpid();
v4 = *a1;
v8[1] = v3;
v8[2] = a2;
v5 = mq_send(v4, v8, 76LL, 0LL);
if ( v5 >= 0 )
return 10LL;
v7 = v5;
perror("rstp_session_send");
return v7;
}

canonical_decompiled_code:
__int64 __fastcall func3(unsigned int *a1, int a2, int a3)
{
__pid_t v3; // eax
__int64 v4; // rdi
int v5; // eax
unsigned int v7; // [rsp+Ch] [rbp-6Ch]
int v8[26]; // [rsp+10h] [rbp-68h] BYREF

if ( !a1 )
_assert_fail("session", "rstp_client.c", 0x69u, "rstp_set_interface");
memset(v8, 0, 0x48uLL);
v8[0] = a3 == 0;
v8[18] = 0;
v3 = getpid();
v4 = *a1;
v8[1] = v3;
v8[2] = a2;
v5 = mq_send(v4, v8, 76LL, 0LL);
if ( v5 >= 0 )
return 10LL;
v7 = v5;
perror("rstp_session_send");
return v7;
}

original_code:
int
rstp_set_interface(struct rstp_session *session, int if_index, int enabled)
{
 struct rstp_request m;
 int err;
 ((void) sizeof ((session) ? 1 : 0), __extension__ ({ if (session) ; else __assert_fail ("session", "rstp_client.c", 105, __extension__ __PRETTY_FUNCTION__); }));
 memset(&m, 0, sizeof(m));
 m.type = enabled ? RSTP_IF_ENABLE : RSTP_IF_DISABLE;
 m.pid = getpid();
 m.if_index = if_index;
 if ((err = ({ int r = mq_send(session->sq, (const char *)&m, sizeof(m), 0); r; })) < 0) {
  perror("rstp_session_send");
  return err;
 }
 return 10;
}

variable_types: enabled int

variable_types: struct rstp_request { int type; int pid; int if_index; char device_id[64]; }

variable_types: r int


decompiled_code:
__int64 __fastcall get_integer(_DWORD *a1, const char *a2, int a3)
{
__int64 v3; // rax
char *endptr; // [rsp+0h] [rbp-20h] BYREF

if ( !a2 )
return 0xFFFFFFFFLL;
if ( !*a2 )
return 0xFFFFFFFFLL;
v3 = strtol(a2, &endptr, a3);
if ( !endptr || endptr == a2 || *endptr || (unsigned __int64)(v3 + 0x80000000LL) > 0xFFFFFFFF )
return 0xFFFFFFFFLL;
*a1 = v3;
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func2(_DWORD *a1, const char *a2, int a3)
{
__int64 v3; // rax
char *endptr; // [rsp+0h] [rbp-20h] BYREF

if ( !a2 )
return 0xFFFFFFFFLL;
if ( !*a2 )
return 0xFFFFFFFFLL;
v3 = strtol(a2, &endptr, a3);
if ( !endptr || endptr == a2 || *endptr || (unsigned __int64)(v3 + 0x80000000LL) > 0xFFFFFFFF )
return 0xFFFFFFFFLL;
*a1 = v3;
return 0LL;
}

original_code:
int get_integer(int *val, const char *arg, int base) {
 long res;
 char *ptr;
 if (!arg || !*arg)
  return -1;
 res = strtol(arg, &ptr, base);
 if (!ptr || ptr == arg || *ptr || res > 0x7fffffff || res < (-0x7fffffff - 1))
  return -1;
 *val = res;
 return 0;
}

canonical_original_code:
int get_integer(int *val, char *arg, int base) {
 long res;
 char *ptr;
 if (!arg || !*arg)
  return -1;
 res = strtol(arg, &ptr, base);
 if (!ptr || ptr == arg || *ptr || res > 0x7fffffff || res < (-0x7fffffff - 1))
  return -1;
 *val = res;
 return 0;
}

variable_types:
val
int *

variable_types:
arg
char *

variable_types: base int

variable_types: res long

variable_types:
ptr
char *


decompiled_code:
__int64 __fastcall parse_rtattr(__int64 a1, int a2, unsigned __int16 *a3, int a4)
{
int i; // er8
__int64 v5; // r9
int v6; // eax
__int64 v7; // rax
unsigned int v8; // er9

for ( i = a4; i > 3; a3 = (unsigned __int16 *)((char *)a3 + v7) )
{
v6 = *a3;
v8 = v6;
if ( (unsigned __int16)v6 <= 3u || i < v6 )
goto LABEL_8;
v5 = a3[1];
if ( (int)v5 <= a2 )
{
*(_QWORD *)(a1 + 8 * v5) = a3;
v6 = *a3;
}
v7 = (v6 + 3) & 0xFFFFFFFC;
i -= v7;
}
if ( i )
{
v8 = *a3;
LABEL_8:
fprintf(stderr, "!!!Deficit %d, rta_len=%d\n", (unsigned int)i, v8);
return 0LL;
}
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1, int a2, unsigned __int16 *a3, int a4)
{
int i; // er8
__int64 v5; // r9
int v6; // eax
__int64 v7; // rax
unsigned int v8; // er9

for ( i = a4; i > 3; a3 = (unsigned __int16 *)((char *)a3 + v7) )
{
v6 = *a3;
v8 = v6;
if ( (unsigned __int16)v6 <= 3u || i < v6 )
goto LABEL_8;
v5 = a3[1];
if ( (int)v5 <= a2 )
{
*(_QWORD *)(a1 + 8 * v5) = a3;
v6 = *a3;
}
v7 = (v6 + 3) & 0xFFFFFFFC;
i -= v7;
}
if ( i )
{
v8 = *a3;
LABEL_8:
fprintf(stderr, "!!!Deficit %d, rta_len=%d\n", (unsigned int)i, v8);
return 0LL;
}
return 0LL;
}

original_code:
int parse_rtattr(struct rtattr *tb[], int max, struct rtattr *rta, int len) {
 while (((len) >= (int)sizeof(struct rtattr) && (rta)->rta_len >= sizeof(struct rtattr) && (rta)->rta_len <= (len))) {
  if (rta->rta_type <= max)
   tb[rta->rta_type] = rta;
  rta = ((len) -= ( (((rta)->rta_len)+4U -1) & ~(4U -1) ), (struct rtattr*)(((char*)(rta)) + ( (((rta)->rta_len)+4U -1) & ~(4U -1) )));
 }
 if (len)
  fprintf(stderr, "!!!Deficit %d, rta_len=%d\n", len, rta->rta_len);
 return 0;
}

canonical_original_code:
int parse_rtattr(struct rtattr *tb[], int max, struct rtattr *rta, int len) {
 while (((len) >= (int)sizeof(struct rtattr) && (rta)->rta_len >= sizeof(struct rtattr) && (rta)->rta_len <= (len))) {
  if (rta->rta_type <= max)
   tb[rta->rta_type] = rta;
  rta = ((len) -= ( (((rta)->rta_len)+4U -1) & ~(4U -1) ), (struct rtattr *)(((char *)(rta)) + ( (((rta)->rta_len)+4U -1) & ~(4U -1) )));
 }
 if (len)
  fprintf(stderr, "!!!Deficit %d, rta_len=%d\n", len, rta->rta_len);
 return 0;
}

variable_types: struct rtattr { unsigned short rta_len; unsigned short rta_type; } *[]

variable_types: max int

variable_types:
rta
struct rtattr *

variable_types: len int


decompiled_code:
__int64 __fastcall addattr_l(_DWORD *a1, unsigned int a2, __int16 a3, const void *a4, int a5)
{
int v5; // ebp
__int64 v7; // rdi
_WORD *v8; // rdi
__int64 result; // rax

v5 = a5 + 4;
v7 = (*a1 + 3) & 0xFFFFFFFC;
if ( a5 + 4 + (int)v7 > a2 )
{
fprintf(stderr, "addattr_l ERROR: message exceeded bound of %d\n", a2);
result = 0xFFFFFFFFLL;
}
else
{
v8 = (_WORD *)((char *)a1 + v7);
v8[1] = a3;
v8 += 2;
*(v8 - 2) = a5 + 4;
memcpy(v8, a4, a5);
*a1 = v5 + ((*a1 + 3) & 0xFFFFFFFC);
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func6(_DWORD *a1, unsigned int a2, __int16 a3, const void *a4, int a5)
{
int v5; // ebp
__int64 v7; // rdi
_WORD *v8; // rdi
__int64 result; // rax

v5 = a5 + 4;
v7 = (*a1 + 3) & 0xFFFFFFFC;
if ( a5 + 4 + (int)v7 > a2 )
{
fprintf(stderr, "addattr_l ERROR: message exceeded bound of %d\n", a2);
result = 0xFFFFFFFFLL;
}
else
{
v8 = (_WORD *)((char *)a1 + v7);
v8[1] = a3;
v8 += 2;
*(v8 - 2) = a5 + 4;
memcpy(v8, a4, a5);
*a1 = v5 + ((*a1 + 3) & 0xFFFFFFFC);
result = 0LL;
}
return result;
}

original_code:
int addattr_l(struct nlmsghdr *n, int maxlen, int type, const void *data,
       int alen) {
 int len = (( ((sizeof(struct rtattr))+4U -1) & ~(4U -1) ) + (alen));
 struct rtattr *rta;
 if (( ((n->nlmsg_len)+4U -1) & ~(4U -1) ) + len > maxlen) {
  fprintf(stderr, "addattr_l ERROR: message exceeded bound of %d\n",maxlen);
  return -1;
 }
 rta = (struct rtattr*)(((char*)n) + ( ((n->nlmsg_len)+4U -1) & ~(4U -1) ));
 rta->rta_type = type;
 rta->rta_len = len;
 memcpy(((void*)(((char*)(rta)) + (( ((sizeof(struct rtattr))+4U -1) & ~(4U -1) ) + (0)))), data, alen);
 n->nlmsg_len = ( ((n->nlmsg_len)+4U -1) & ~(4U -1) ) + len;
 return 0;
}

canonical_original_code:
int addattr_l(struct nlmsghdr *n, int maxlen, int type, void *data, int alen) {
 int len = (( ((sizeof(struct rtattr))+4U -1) & ~(4U -1) ) + (alen));
 struct rtattr *rta;
 if (( ((n->nlmsg_len)+4U -1) & ~(4U -1) ) + len > maxlen) {
  fprintf(stderr, "addattr_l ERROR: message exceeded bound of %d\n",maxlen);
  return -1;
 }
 rta = (struct rtattr *)(((char *)n) + ( ((n->nlmsg_len)+4U -1) & ~(4U -1) ));
 rta->rta_type = type;
 rta->rta_len = len;
 memcpy(((void *)(((char *)(rta)) + (( ((sizeof(struct rtattr))+4U -1) & ~(4U -1) ) + (0)))), data, alen);
 n->nlmsg_len = ( ((n->nlmsg_len)+4U -1) & ~(4U -1) ) + len;
 return 0;
}

variable_types: struct nlmsghdr { unsigned int nlmsg_len; unsigned short nlmsg_type; unsigned short nlmsg_flags; unsigned int nlmsg_seq; unsigned int nlmsg_pid; } *

variable_types: maxlen int

variable_types: type int

variable_types:
data
void *

variable_types: alen int

variable_types: struct rtattr { unsigned short rta_len; unsigned short rta_type; } *


decompiled_code:
__int64 __fastcall rtnl_open(__int64 a1)
{
int v2; // eax
int v3; // edi
int v4; // edi
__int64 result; // rax
socklen_t len; // [rsp+4h] [rbp-24h] BYREF
int optval; // [rsp+8h] [rbp-20h] BYREF
int v8[7]; // [rsp+Ch] [rbp-1Ch] BYREF

*(_QWORD *)a1 = 0LL;
optval = 0x8000;
v8[0] = 0x8000;
v2 = socket(16, 3, 0);
*(_DWORD *)a1 = v2;
if ( v2 < 0 )
{
perror("Cannot open netlink socket");
result = 0xFFFFFFFFLL;
}
else if ( setsockopt(v2, 1, 7, &optval, 4u) < 0 )
{
perror("SO_SNDBUF");
result = 0xFFFFFFFFLL;
}
else if ( setsockopt(*(_DWORD *)a1, 1, 8, v8, 4u) < 0 )
{
perror("SO_RCVBUF");
result = 0xFFFFFFFFLL;
}
else
{
*(_QWORD *)(a1 + 4) = 0LL;
*(_DWORD *)(a1 + 12) = 0;
v3 = *(_DWORD *)a1;
*(_WORD *)(a1 + 4) = 16;
if ( bind(v3, (const struct sockaddr *)(a1 + 4), 0xCu) < 0 )
{
perror("Cannot bind netlink socket");
result = 0xFFFFFFFFLL;
}
else
{
v4 = *(_DWORD *)a1;
len = 12;
if ( getsockname(v4, (struct sockaddr *)(a1 + 4), &len) < 0 )
{
perror("Cannot getsockname");
result = 0xFFFFFFFFLL;
}
else
{
if ( len == 12 )
{
if ( *(_WORD *)(a1 + 4) == 16 )
{
*(_DWORD *)(a1 + 28) = time(0LL);
return 0LL;
}
fprintf(stderr, "Wrong address family %d\n");
}
else
{
fprintf(stderr, "Wrong address length %d\n");
}
result = 0xFFFFFFFFLL;
}
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1)
{
int v2; // eax
int v3; // edi
int v4; // edi
__int64 result; // rax
socklen_t len; // [rsp+4h] [rbp-24h] BYREF
int optval; // [rsp+8h] [rbp-20h] BYREF
int v8[7]; // [rsp+Ch] [rbp-1Ch] BYREF

*(_QWORD *)a1 = 0LL;
optval = 0x8000;
v8[0] = 0x8000;
v2 = socket(16, 3, 0);
*(_DWORD *)a1 = v2;
if ( v2 < 0 )
{
perror("Cannot open netlink socket");
result = 0xFFFFFFFFLL;
}
else if ( setsockopt(v2, 1, 7, &optval, 4u) < 0 )
{
perror("SO_SNDBUF");
result = 0xFFFFFFFFLL;
}
else if ( setsockopt(*(_DWORD *)a1, 1, 8, v8, 4u) < 0 )
{
perror("SO_RCVBUF");
result = 0xFFFFFFFFLL;
}
else
{
*(_QWORD *)(a1 + 4) = 0LL;
*(_DWORD *)(a1 + 12) = 0;
v3 = *(_DWORD *)a1;
*(_WORD *)(a1 + 4) = 16;
if ( bind(v3, (const struct sockaddr *)(a1 + 4), 0xCu) < 0 )
{
perror("Cannot bind netlink socket");
result = 0xFFFFFFFFLL;
}
else
{
v4 = *(_DWORD *)a1;
len = 12;
if ( getsockname(v4, (struct sockaddr *)(a1 + 4), &len) < 0 )
{
perror("Cannot getsockname");
result = 0xFFFFFFFFLL;
}
else
{
if ( len == 12 )
{
if ( *(_WORD *)(a1 + 4) == 16 )
{
*(_DWORD *)(a1 + 28) = time(0LL);
return 0LL;
}
fprintf(stderr, "Wrong address family %d\n");
}
else
{
fprintf(stderr, "Wrong address length %d\n");
}
result = 0xFFFFFFFFLL;
}
}
}
return result;
}

original_code:
int rtnl_open(struct rtnl_handle *rth) {
 unsigned int addr_len;
 int sndbuf = 32768;
 int rcvbuf = 32768;
 memset(rth, 0, sizeof(rth));
 rth->fd = socket(16, SOCK_RAW, 0);
 if (rth->fd < 0) {
  perror("Cannot open netlink socket");
  return -1;
 }
 if (setsockopt(rth->fd,1,7,&sndbuf,sizeof(sndbuf)) < 0) {
  perror("SO_SNDBUF");
  return -1;
 }
 if (setsockopt(rth->fd,1,8,&rcvbuf,sizeof(rcvbuf)) < 0) {
  perror("SO_RCVBUF");
  return -1;
 }
 memset(&rth->local, 0, sizeof(rth->local));
 rth->local.nl_family = 16;
 rth->local.nl_groups = 0;
 if (bind(rth->fd, (struct sockaddr*)&rth->local, sizeof(rth->local)) < 0) {
  perror("Cannot bind netlink socket");
  return -1;
 }
 addr_len = sizeof(rth->local);
 if (getsockname(rth->fd, (struct sockaddr*)&rth->local, &addr_len) < 0) {
  perror("Cannot getsockname");
  return -1;
 }
 if (addr_len != sizeof(rth->local)) {
  fprintf(stderr, "Wrong address length %d\n", addr_len);
  return -1;
 }
 if (rth->local.nl_family != 16) {
  fprintf(stderr, "Wrong address family %d\n", rth->local.nl_family);
  return -1;
 }
 rth->seq = time(((void *)0));
 return 0;
}

canonical_original_code:
int rtnl_open(struct rtnl_handle *rth) {
 unsigned int addr_len;
 int sndbuf = 32768;
 int rcvbuf = 32768;
 memset(rth, 0, sizeof(rth));
 rth->fd = socket(16, SOCK_RAW, 0);
 if (rth->fd < 0) {
  perror("Cannot open netlink socket");
  return -1;
 }
 if (setsockopt(rth->fd,1,7,&sndbuf,sizeof(sndbuf)) < 0) {
  perror("SO_SNDBUF");
  return -1;
 }
 if (setsockopt(rth->fd,1,8,&rcvbuf,sizeof(rcvbuf)) < 0) {
  perror("SO_RCVBUF");
  return -1;
 }
 memset(&rth->local, 0, sizeof(rth->local));
 rth->local.nl_family = 16;
 rth->local.nl_groups = 0;
 if (bind(rth->fd, (struct sockaddr *)&rth->local, sizeof(rth->local)) < 0) {
  perror("Cannot bind netlink socket");
  return -1;
 }
 addr_len = sizeof(rth->local);
 if (getsockname(rth->fd, (struct sockaddr *)&rth->local, &addr_len) < 0) {
  perror("Cannot getsockname");
  return -1;
 }
 if (addr_len != sizeof(rth->local)) {
  fprintf(stderr, "Wrong address length %d\n", addr_len);
  return -1;
 }
 if (rth->local.nl_family != 16) {
  fprintf(stderr, "Wrong address family %d\n", rth->local.nl_family);
  return -1;
 }
 rth->seq = time(((void *)0));
 return 0;
}

variable_types: struct rtnl_handle { int fd; struct sockaddr_nl { unsigned short nl_family; unsigned short nl_pad; unsigned int nl_pid; unsigned int nl_groups; } local; struct sockaddr_nl peer; unsigned int seq; unsigned int dump; } *

variable_types: sndbuf int

variable_types: rcvbuf int

user_defined_types: struct rtnl_handle { int fd; struct sockaddr_nl local; struct sockaddr_nl peer; unsigned int seq; unsigned int dump; }

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


decompiled_code:
__int64 __fastcall rtnl_talk(int *a1, char *a2)
{
int v3; // eax
int v4; // ebx
int v5; // edi
int v6; // edi
int v7; // eax
unsigned int v8; // er13
__int64 v9; // rdx
int v10; // eax
char *v11; // r15
signed int v12; // er12
__int64 v13; // r12
const char *v14; // rsi
unsigned int v15; // er12
int *v17; // rax
__int64 v18; // [rsp+14h] [rbp-4094h] BYREF
int v19; // [rsp+1Ch] [rbp-408Ch]
char *v20; // [rsp+20h] [rbp-4088h] BYREF
__int64 v21; // [rsp+28h] [rbp-4080h]
struct msghdr message; // [rsp+30h] [rbp-4078h] BYREF
char s[16440]; // [rsp+70h] [rbp-4038h] BYREF

v21 = *(unsigned int *)a2;
message.msg_name = &v18;
message.msg_iov = (iovec *)&v20;
v18 = 16LL;
v3 = a1[7];
v20 = a2;
v4 = v3 + 1;
message.msg_namelen = 12;
a1[7] = v3 + 1;
*((_WORD *)a2 + 3) |= 4u;
*((_DWORD *)a2 + 2) = v3 + 1;
v5 = *a1;
message.msg_iovlen = 1LL;
message.msg_control = 0LL;
message.msg_controllen = 0LL;
message.msg_flags = 0;
v19 = 0;
if ( (int)sendmsg(v5, &message, 0) < 0 )
{
v15 = -1;
perror("Cannot talk to rtnetlink");
return v15;
}
memset(s, 0, 0x4000uLL);
v20 = s;
while ( 1 )
{
while ( 1 )
{
v6 = *a1;
v21 = 0x4000LL;
v7 = recvmsg(v6, &message, 0);
v8 = v7;
if ( v7 >= 0 )
break;
if ( *_errno_location() != 4 )
perror("OVERRUN");
}
if ( !v7 )
{
v15 = -1;
fwrite("EOF on netlink\n", 1uLL, 0xFuLL, stderr);
return v15;
}
v9 = message.msg_namelen;
if ( message.msg_namelen != 12 )
{
v14 = "sender address length == %d\n";
goto LABEL_17;
}
v10 = HIDWORD(v18);
v11 = s;
LABEL_7:
if ( v8 > 0xF )
break;
LABEL_14:
if ( (message.msg_flags & 0x20) != 0 )
{
fwrite("Message truncated\n", 1uLL, 0x12uLL, stderr);
}
else if ( v8 )
{
v9 = v8;
v14 = "!!!Remnant of size %d\n";
LABEL_17:
v15 = -1;
fprintf(stderr, v14, v9);
return v15;
}
}
while ( 1 )
{
v12 = *(_DWORD *)v11;
if ( *(_DWORD *)v11 - 16 < 0 || (int)v8 < v12 )
{
if ( (message.msg_flags & 0x20) != 0 )
{
v15 = -1;
fwrite("Truncated message\n", 1uLL, 0x12uLL, stderr);
}
else
{
fprintf(stderr, "!!!malformed message: len=%d\n", (unsigned int)v12);
v15 = -1;
}
return v15;
}
if ( v10 || *((_QWORD *)v11 + 1) != __PAIR64__(a1[2], v4) )
goto LABEL_7;
if ( *((_WORD *)v11 + 2) == 2 )
break;
v13 = (v12 + 3) & 0xFFFFFFFC;
v8 -= v13;
v11 += v13;
fwrite("Unexpected reply!!!\n", 1uLL, 0x14uLL, stderr);
v10 = HIDWORD(v18);
if ( v8 <= 0xF )
goto LABEL_14;
}
if ( (unsigned int)(*(_DWORD *)v11 - 16) <= 0x13 )
{
v15 = -1;
fwrite("ERROR truncated\n", 1uLL, 0x10uLL, stderr);
}
else
{
v17 = _errno_location();
v15 = *((_DWORD *)v11 + 4);
*v17 = -v15;
if ( v15 )
{
v15 = -1;
perror("RTNETLINK answers");
}
}
return v15;
}

canonical_decompiled_code:
__int64 __fastcall func10(int *a1, char *a2)
{
int v3; // eax
int v4; // ebx
int v5; // edi
int v6; // edi
int v7; // eax
unsigned int v8; // er13
__int64 v9; // rdx
int v10; // eax
char *v11; // r15
signed int v12; // er12
__int64 v13; // r12
const char *v14; // rsi
unsigned int v15; // er12
int *v17; // rax
__int64 v18; // [rsp+14h] [rbp-4094h] BYREF
int v19; // [rsp+1Ch] [rbp-408Ch]
char *v20; // [rsp+20h] [rbp-4088h] BYREF
__int64 v21; // [rsp+28h] [rbp-4080h]
struct msghdr message; // [rsp+30h] [rbp-4078h] BYREF
char s[16440]; // [rsp+70h] [rbp-4038h] BYREF

v21 = *(unsigned int *)a2;
message.msg_name = &v18;
message.msg_iov = (iovec *)&v20;
v18 = 16LL;
v3 = a1[7];
v20 = a2;
v4 = v3 + 1;
message.msg_namelen = 12;
a1[7] = v3 + 1;
*((_WORD *)a2 + 3) |= 4u;
*((_DWORD *)a2 + 2) = v3 + 1;
v5 = *a1;
message.msg_iovlen = 1LL;
message.msg_control = 0LL;
message.msg_controllen = 0LL;
message.msg_flags = 0;
v19 = 0;
if ( (int)sendmsg(v5, &message, 0) < 0 )
{
v15 = -1;
perror("Cannot talk to rtnetlink");
return v15;
}
memset(s, 0, 0x4000uLL);
v20 = s;
while ( 1 )
{
while ( 1 )
{
v6 = *a1;
v21 = 0x4000LL;
v7 = recvmsg(v6, &message, 0);
v8 = v7;
if ( v7 >= 0 )
break;
if ( *_errno_location() != 4 )
perror("OVERRUN");
}
if ( !v7 )
{
v15 = -1;
fwrite("EOF on netlink\n", 1uLL, 0xFuLL, stderr);
return v15;
}
v9 = message.msg_namelen;
if ( message.msg_namelen != 12 )
{
v14 = "sender address length == %d\n";
goto LABEL_17;
}
v10 = HIDWORD(v18);
v11 = s;
LABEL_7:
if ( v8 > 0xF )
break;
LABEL_14:
if ( (message.msg_flags & 0x20) != 0 )
{
fwrite("Message truncated\n", 1uLL, 0x12uLL, stderr);
}
else if ( v8 )
{
v9 = v8;
v14 = "!!!Remnant of size %d\n";
LABEL_17:
v15 = -1;
fprintf(stderr, v14, v9);
return v15;
}
}
while ( 1 )
{
v12 = *(_DWORD *)v11;
if ( *(_DWORD *)v11 - 16 < 0 || (int)v8 < v12 )
{
if ( (message.msg_flags & 0x20) != 0 )
{
v15 = -1;
fwrite("Truncated message\n", 1uLL, 0x12uLL, stderr);
}
else
{
fprintf(stderr, "!!!malformed message: len=%d\n", (unsigned int)v12);
v15 = -1;
}
return v15;
}
if ( v10 || *((_QWORD *)v11 + 1) != __PAIR64__(a1[2], v4) )
goto LABEL_7;
if ( *((_WORD *)v11 + 2) == 2 )
break;
v13 = (v12 + 3) & 0xFFFFFFFC;
v8 -= v13;
v11 += v13;
fwrite("Unexpected reply!!!\n", 1uLL, 0x14uLL, stderr);
v10 = HIDWORD(v18);
if ( v8 <= 0xF )
goto LABEL_14;
}
if ( (unsigned int)(*(_DWORD *)v11 - 16) <= 0x13 )
{
v15 = -1;
fwrite("ERROR truncated\n", 1uLL, 0x10uLL, stderr);
}
else
{
v17 = _errno_location();
v15 = *((_DWORD *)v11 + 4);
*v17 = -v15;
if ( v15 )
{
v15 = -1;
perror("RTNETLINK answers");
}
}
return v15;
}

original_code:
int rtnl_talk(struct rtnl_handle *rtnl, struct nlmsghdr *n) {
 int status;
 unsigned seq;
 struct nlmsghdr *h;
 struct sockaddr_nl nladdr;
 struct iovec iov = { (void*)n, n->nlmsg_len };
 char buf[16384];
 struct msghdr msg = {
  (void*)&nladdr, sizeof(nladdr),
  &iov, 1,
  ((void *)0), 0,
  0
 };
 memset(&nladdr, 0, sizeof(nladdr));
 nladdr.nl_family = 16;
 nladdr.nl_pid = 0;
 nladdr.nl_groups = 0;
 n->nlmsg_seq = seq = ++rtnl->seq;
 n->nlmsg_flags |= 0x04;
 status = sendmsg(rtnl->fd, &msg, 0);
 if (status < 0) {
  perror("Cannot talk to rtnetlink");
  return -1;
 }
 memset(buf,0,sizeof(buf));
 iov.iov_base = buf;
 while (1) {
  iov.iov_len = sizeof(buf);
  status = recvmsg(rtnl->fd, &msg, 0);
  if (status < 0) {
   if ((*__errno_location ()) == 4)
    continue;
   perror("OVERRUN");
   continue;
  }
  if (status == 0) {
   fprintf(stderr, "EOF on netlink\n");
   return -1;
  }
  if (msg.msg_namelen != sizeof(nladdr)) {
   fprintf(stderr, "sender address length == %d\n", msg.msg_namelen);
   return -1;
  }
  for (h = (struct nlmsghdr*)buf; status >= sizeof(*h); ) {
   int len = h->nlmsg_len;
   int l = len - sizeof(*h);
   if (l<0 || len>status) {
    if (msg.msg_flags & MSG_TRUNC) {
     fprintf(stderr, "Truncated message\n");
     return -1;
    }
    fprintf(stderr, "!!!malformed message: len=%d\n", len);
    return -1;
   }
   if (nladdr.nl_pid != 0 ||
     h->nlmsg_pid != rtnl->local.nl_pid ||
     h->nlmsg_seq != seq)
    continue;
   if (h->nlmsg_type == 0x2) {
    struct nlmsgerr *err = (struct nlmsgerr*)((void*)(((char*)h) + ((0) + ((int) ( ((sizeof(struct nlmsghdr))+4U -1) & ~(4U -1) )))));
    if (l < sizeof(struct nlmsgerr)) {
     fprintf(stderr, "ERROR truncated\n");
    } else {
     (*__errno_location ()) = -err->error;
     if ((*__errno_location ()) == 0)
      return 0;
     perror("RTNETLINK answers");
    }
    return -1;
   }
   fprintf(stderr, "Unexpected reply!!!\n");
   status -= ( ((len)+4U -1) & ~(4U -1) );
   h = (struct nlmsghdr*)((char*)h + ( ((len)+4U -1) & ~(4U -1) ));
  }
  if (msg.msg_flags & MSG_TRUNC) {
   fprintf(stderr, "Message truncated\n");
   continue;
  }
  if (status) {
   fprintf(stderr, "!!!Remnant of size %d\n", status);
   return -1;
  }
 }
 return 0;
}

canonical_original_code:
int rtnl_talk(struct rtnl_handle *rtnl, struct nlmsghdr *n) {
 int status;
 unsigned int seq;
 struct nlmsghdr *h;
 struct sockaddr_nl nladdr;
 struct iovec iov = { (void*)n, n->nlmsg_len };
 char buf[16384];
 struct msghdr msg = {
  (void*)&nladdr, sizeof(nladdr),
  &iov, 1,
  ((void *)0), 0,
  0
 };
 memset(&nladdr, 0, sizeof(nladdr));
 nladdr.nl_family = 16;
 nladdr.nl_pid = 0;
 nladdr.nl_groups = 0;
 n->nlmsg_seq = seq = ++rtnl->seq;
 n->nlmsg_flags |= 0x04;
 status = sendmsg(rtnl->fd, &msg, 0);
 if (status < 0) {
  perror("Cannot talk to rtnetlink");
  return -1;
 }
 memset(buf,0,sizeof(buf));
 iov.iov_base = buf;
 while (1) {
  iov.iov_len = sizeof(buf);
  status = recvmsg(rtnl->fd, &msg, 0);
  if (status < 0) {
   if ((*__errno_location ()) == 4)
    continue;
   perror("OVERRUN");
   continue;
  }
  if (status == 0) {
   fprintf(stderr, "EOF on netlink\n");
   return -1;
  }
  if (msg.msg_namelen != sizeof(nladdr)) {
   fprintf(stderr, "sender address length == %d\n", msg.msg_namelen);
   return -1;
  }
  for (h = (struct nlmsghdr *)buf; status >= sizeof(*h); ) {
   int len = h->nlmsg_len;
   int l = len - sizeof(*h);
   if (l<0 || len>status) {
    if (msg.msg_flags & MSG_TRUNC) {
     fprintf(stderr, "Truncated message\n");
     return -1;
    }
    fprintf(stderr, "!!!malformed message: len=%d\n", len);
    return -1;
   }
   if (nladdr.nl_pid != 0 ||
     h->nlmsg_pid != rtnl->local.nl_pid ||
     h->nlmsg_seq != seq)
    continue;
   if (h->nlmsg_type == 0x2) {
    struct nlmsgerr *err = (struct nlmsgerr*)((void*)(((char*)h) + ((0) + ((int) ( ((sizeof(struct nlmsghdr))+4U -1) & ~(4U -1) )))));
    if (l < sizeof(struct nlmsgerr)) {
     fprintf(stderr, "ERROR truncated\n");
    } else {
     (*__errno_location ()) = -err->error;
     if ((*__errno_location ()) == 0)
      return 0;
     perror("RTNETLINK answers");
    }
    return -1;
   }
   fprintf(stderr, "Unexpected reply!!!\n");
   status -= ( ((len)+4U -1) & ~(4U -1) );
   h = (struct nlmsghdr *)((char *)h + ( ((len)+4U -1) & ~(4U -1) ));
  }
  if (msg.msg_flags & MSG_TRUNC) {
   fprintf(stderr, "Message truncated\n");
   continue;
  }
  if (status) {
   fprintf(stderr, "!!!Remnant of size %d\n", status);
   return -1;
  }
 }
 return 0;
}

variable_types: status int

variable_types:
seq
unsigned int

variable_types: struct sockaddr_nl { unsigned short nl_family; unsigned short nl_pad; unsigned int nl_pid; unsigned int nl_groups; }

variable_types:
buf
char [16384]

variable_types: struct msghdr { void *msg_name; unsigned int msg_namelen; struct iovec { void *iov_base; unsigned long iov_len; } *msg_iov; unsigned long msg_iovlen; void *msg_control; unsigned long msg_controllen; int msg_flags; }

variable_types: l int

variable_types: struct nlmsgerr { int error; struct nlmsghdr { unsigned int nlmsg_len; unsigned short nlmsg_type; unsigned short nlmsg_flags; unsigned int nlmsg_seq; unsigned int nlmsg_pid; } msg; } *

user_defined_types: struct msghdr { void *msg_name; unsigned int msg_namelen; struct iovec *msg_iov; unsigned long msg_iovlen; void *msg_control; unsigned long msg_controllen; int msg_flags; }

user_defined_types: struct nlmsgerr { int error; struct nlmsghdr msg; }


decompiled_code:
int __fastcall rtnl_close(int *a1)
{
return close(*a1);
}

canonical_decompiled_code:
int __fastcall func11(int *a1)
{
return close(*a1);
}

original_code:
void rtnl_close(struct rtnl_handle *rth) {
 close(rth->fd);
}

user_defined_types: struct sockaddr_nl { unsigned short nl_family; unsigned short nl_pad; unsigned int nl_pid; unsigned int nl_groups; }


decompiled_code:
_BOOL8 __fastcall password_valid(const char *a1, const char *a2)
{
return strcmp(a1, a2) == 0;
}

canonical_decompiled_code:
_BOOL8 __fastcall func0(const char *a1, const char *a2)
{
return strcmp(a1, a2) == 0;
}

original_code:
static int password_valid(char *pw, void *priv)
{
 return !strcmp(pw, (char *)priv);
}

variable_types:
pw
char *

variable_types:
priv
void *


decompiled_code:
int redisplay_password()
{
fwrite("\rPassword: ", 1uLL, 0xBuLL, rl_outstream);
return fflush(rl_outstream);
}

canonical_decompiled_code:
int func1()
{
fwrite("\rPassword: ", 1uLL, 0xBuLL, rl_outstream);
return fflush(rl_outstream);
}

original_code:
static void redisplay_password(void)
{
 fprintf(rl_outstream, "\rPassword: ");
 fflush(rl_outstream);
}

canonical_original_code:
static void redisplay_password()
{
 fprintf(rl_outstream, "\rPassword: ");
 fflush(rl_outstream);
}


decompiled_code:
__int64 __fastcall cli_mask_apply(_DWORD *a1, int a2)
{
if ( a1 )
{
while ( *a1 )
{
if ( (*a1 & a2) == 0 )
return 0LL;
++a1;
}
}
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func0(_DWORD *a1, int a2)
{
if ( a1 )
{
while ( *a1 )
{
if ( (*a1 & a2) == 0 )
return 0LL;
++a1;
}
}
return 1LL;
}

original_code:
static __inline__ int cli_mask_apply(uint32_t *mask, uint32_t filter) {
 if (!mask)
  return 1;
 while (*mask) {
  if (!(*mask & filter))
   return 0;
  mask++;
 }
 return 1;
}

variable_types:
mask
unsigned int *

variable_types:
filter
unsigned int


decompiled_code:
__int64 __fastcall valid_mac(char *a1, int a2)
{
char v2; // al
char *v3; // rdi
int v4; // ecx
unsigned int v5; // er8
bool v6; // al

v2 = *a1;
if ( *a1 )
{
v3 = a1 + 1;
v4 = 1;
v5 = 0;
do
{
if ( v2 == 46 )
{
if ( !v5 )
return v5;
++v4;
v5 = 0;
}
else
{
if ( (unsigned __int8)(v2 - 48) > 9u && (unsigned __int8)((v2 & 0xDF) - 65) > 5u )
return 0LL;
if ( (int)++v5 > 4 )
return 0LL;
}
v2 = *v3++;
}
while ( v2 );
v5 = 0;
if ( v4 > 3 )
return v5;
v6 = v4 == 3;
}
else
{
v6 = 0;
}
return v6 | (unsigned __int8)(a2 != 0);
}

canonical_decompiled_code:
__int64 __fastcall func1(char *a1, int a2)
{
char v2; // al
char *v3; // rdi
int v4; // ecx
unsigned int v5; // er8
bool v6; // al

v2 = *a1;
if ( *a1 )
{
v3 = a1 + 1;
v4 = 1;
v5 = 0;
do
{
if ( v2 == 46 )
{
if ( !v5 )
return v5;
++v4;
v5 = 0;
}
else
{
if ( (unsigned __int8)(v2 - 48) > 9u && (unsigned __int8)((v2 & 0xDF) - 65) > 5u )
return 0LL;
if ( (int)++v5 > 4 )
return 0LL;
}
v2 = *v3++;
}
while ( v2 );
v5 = 0;
if ( v4 > 3 )
return v5;
v6 = v4 == 3;
}
else
{
v6 = 0;
}
return v6 | (unsigned __int8)(a2 != 0);
}

original_code:
static int valid_mac(const char *token, int part, void *priv)
{
 int digits = 0, group = 1, i;
 for (i = 0; token[i] != '\0'; i++) {
  if (token[i] == '.') {
   if (!digits)
    return 0;
   digits = 0;
   group ++;
   continue;
  }
  if (!(((token[i]) >= '0' && (token[i]) <= '9') || ((token[i]) >= 'a' && (token[i]) <= 'f') || ((token[i]) >= 'A' && (token[i]) <= 'F')))
   return 0;
  if (++digits > 4)
   return 0;
 }
 if (group > 3)
  return 0;
 return part || group == 3;
}

canonical_original_code:
static int valid_mac(char *token, int part, void *priv)
{
 int digits = 0; int group = 1; int i;
 for (i = 0; token[i] != '\0'; i++) {
  if (token[i] == '.') {
   if (!digits)
    return 0;
   digits = 0;
   group ++;
   continue;
  }
  if (!(((token[i]) >= '0' && (token[i]) <= '9') || ((token[i]) >= 'a' && (token[i]) <= 'f') || ((token[i]) >= 'A' && (token[i]) <= 'F')))
   return 0;
  if (++digits > 4)
   return 0;
 }
 if (group > 3)
  return 0;
 return part || group == 3;
}

variable_types:
token
char *

variable_types: part int

variable_types: digits int

variable_types: group int

variable_types: i int


decompiled_code:
__int64 __fastcall valid_ip(char *a1, int a2)
{
char v2; // al
char *v3; // rdi
int v4; // ecx
unsigned int v5; // er8
int v6; // edx
unsigned __int8 v7; // al
bool v8; // al

v2 = *a1;
if ( *a1 )
{
v3 = a1 + 1;
v4 = 1;
v5 = 0;
v6 = 0;
do
{
if ( v2 == 46 )
{
if ( !v5 )
return v5;
++v4;
v5 = 0;
v6 = 0;
}
else
{
v7 = v2 - 48;
if ( v7 > 9u )
return 0LL;
++v5;
v6 = (char)v7 + 10 * v6;
if ( v6 > 255 )
return 0LL;
}
v2 = *v3++;
}
while ( v2 );
v5 = 0;
if ( v4 > 4 )
return v5;
v8 = v4 == 4;
}
else
{
v8 = 0;
}
return v8 | (unsigned __int8)(a2 != 0);
}

canonical_decompiled_code:
__int64 __fastcall func2(char *a1, int a2)
{
char v2; // al
char *v3; // rdi
int v4; // ecx
unsigned int v5; // er8
int v6; // edx
unsigned __int8 v7; // al
bool v8; // al

v2 = *a1;
if ( *a1 )
{
v3 = a1 + 1;
v4 = 1;
v5 = 0;
v6 = 0;
do
{
if ( v2 == 46 )
{
if ( !v5 )
return v5;
++v4;
v5 = 0;
v6 = 0;
}
else
{
v7 = v2 - 48;
if ( v7 > 9u )
return 0LL;
++v5;
v6 = (char)v7 + 10 * v6;
if ( v6 > 255 )
return 0LL;
}
v2 = *v3++;
}
while ( v2 );
v5 = 0;
if ( v4 > 4 )
return v5;
v8 = v4 == 4;
}
else
{
v8 = 0;
}
return v8 | (unsigned __int8)(a2 != 0);
}

original_code:
static int valid_ip(const char *token, int part, void *priv)
{
 int x = 0, digits = 0, group = 1, i;
 for (i = 0; token[i] != '\0'; i++) {
  if (token[i] == '.') {
   if (!digits)
    return 0;
   digits = 0;
   x = 0;
   group ++;
   continue;
  }
  if (token[i] < '0' || token[i] > '9')
   return 0;
  ++digits;
  if ((x = x * 10 + (token[i] - '0')) > 255)
   return 0;
 }
 if (group > 4)
  return 0;
 return part || group == 4;
}

canonical_original_code:
static int valid_ip(char *token, int part, void *priv)
{
 int x = 0; int digits = 0; int group = 1; int i;
 for (i = 0; token[i] != '\0'; i++) {
  if (token[i] == '.') {
   if (!digits)
    return 0;
   digits = 0;
   x = 0;
   group ++;
   continue;
  }
  if (token[i] < '0' || token[i] > '9')
   return 0;
  ++digits;
  if ((x = x * 10 + (token[i] - '0')) > 255)
   return 0;
 }
 if (group > 4)
  return 0;
 return part || group == 4;
}

variable_types: x int


decompiled_code:
__int64 __fastcall swcli_valid_number(const char *a1, __int64 a2, unsigned int *a3)
{
char v3; // al
char *v5; // rdx
unsigned int v6; // er8
int v8; // eax
int v9; // edx
int v10; // esi
__int64 v11; // rax

if ( !a3 )
return 1LL;
if ( !a1 )
_assert_fail("token", "lib/tokenizers.c", 0xFu, "swcli_valid_number");
v3 = *a1;
v5 = (char *)(a1 + 1);
if ( *a1 )
{
while ( (unsigned __int8)(v3 - 48) <= 9u )
{
v3 = *v5++;
if ( !v3 )
goto LABEL_9;
}
return 0;
}
LABEL_9:
v8 = atoi(a1);
v6 = *a3;
v9 = v8;
if ( !*a3 )
{
if ( (int)a3[1] <= v8 )
v6 = (int)a3[2] >= v8;
return v6;
}
if ( v6 == 1 )
{
v10 = a3[1];
v11 = 2LL;
if ( v10 > 0 )
{
while ( a3[v11] != v9 )
{
if ( (int)++v11 - 1 > v10 )
return 0;
}
return v6;
}
return 0;
}
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func3(const char *a1, __int64 a2, unsigned int *a3)
{
char v3; // al
char *v5; // rdx
unsigned int v6; // er8
int v8; // eax
int v9; // edx
int v10; // esi
__int64 v11; // rax

if ( !a3 )
return 1LL;
if ( !a1 )
_assert_fail("token", "lib/tokenizers.c", 0xFu, "swcli_valid_number");
v3 = *a1;
v5 = (char *)(a1 + 1);
if ( *a1 )
{
while ( (unsigned __int8)(v3 - 48) <= 9u )
{
v3 = *v5++;
if ( !v3 )
goto LABEL_9;
}
return 0;
}
LABEL_9:
v8 = atoi(a1);
v6 = *a3;
v9 = v8;
if ( !*a3 )
{
if ( (int)a3[1] <= v8 )
v6 = (int)a3[2] >= v8;
return v6;
}
if ( v6 == 1 )
{
v10 = a3[1];
v11 = 2LL;
if ( v10 > 0 )
{
while ( a3[v11] != v9 )
{
if ( (int)++v11 - 1 > v10 )
return 0;
}
return v6;
}
return 0;
}
return 1LL;
}

original_code:
static int swcli_valid_number(const char *token, int part, void *priv)
{
 int i, val;
 int *valid = priv;
 if (!valid)
  return 1;
 ((void) sizeof ((token) ? 1 : 0), __extension__ ({ if (token) ; else __assert_fail ("token", "lib/tokenizers.c", 15, __extension__ __PRETTY_FUNCTION__); }));
 for (i = 0; token[i] != '\0'; i++)
  if (token[i] < '0' || token[i] > '9')
   return 0;
 val = atoi(token);
 switch (valid[0]) {
 case VALID_LIMITS:
  return val >= valid[1] && val <= valid[2];
 case VALID_LIST:
  for (i = 2; i < valid[1] + 2; i++)
   if (val == valid[i])
    return 1;
  return 0;
 }
 return 1;
}

canonical_original_code:
static int swcli_valid_number(char *token, int part, void *priv)
{
 int i; int val;
 int *valid = priv;
 if (!valid)
  return 1;
 ((void) sizeof ((token) ? 1 : 0), __extension__ ({ if (token) ; else __assert_fail ("token", "lib/tokenizers.c", 15, __extension__ __PRETTY_FUNCTION__); }));
 for (i = 0; token[i] != '\0'; i++)
  if (token[i] < '0' || token[i] > '9')
   return 0;
 val = atoi(token);
 switch (valid[0]) {
 case VALID_LIMITS:
  return val >= valid[1] && val <= valid[2];
 case VALID_LIST:
  for (i = 2; i < valid[1] + 2; i++)
   if (val == valid[i])
    return 1;
  return 0;
 }
 return 1;
}

variable_types: val int

variable_types:
valid
int *


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

if ( !ptr )
_assert_fail("s", "cdp_client.c", 0x38u, "cdp_session_end");
v2 = (void *)*((_QWORD *)ptr + 9);
if ( v2 )
free(v2);
if ( *(_DWORD *)ptr != -1 )
mq_close();
if ( *((_DWORD *)ptr + 1) != -1 )
{
mq_close();
mq_unlink((char *)ptr + 40);
}
free(ptr);
}

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

if ( !ptr )
_assert_fail("s", "cdp_client.c", 0x38u, "cdp_session_end");
v2 = (void *)*((_QWORD *)ptr + 9);
if ( v2 )
free(v2);
if ( *(_DWORD *)ptr != -1 )
mq_close();
if ( *((_DWORD *)ptr + 1) != -1 )
{
mq_close();
mq_unlink((char *)ptr + 40);
}
free(ptr);
}

original_code:
void cdp_session_end(struct cdp_session *s)
{
 ((void) sizeof ((s) ? 1 : 0), __extension__ ({ if (s) ; else __assert_fail ("s", "cdp_client.c", 56, __extension__ __PRETTY_FUNCTION__); }));
 if (s->response)
  free(s->response);
 if (s->sq != -1)
  mq_close(s->sq);
 if (s->rq != -1) {
  mq_close(s->rq);
  mq_unlink(s->rq_name);
 }
 free(s);
}

variable_types: struct cdp_session { int sq; char sq_name[32]; char *response; int max_msg_len; } *


original_code:
struct cdp_session *cdp_session_start(void)
{
 struct cdp_session *s;
 struct mq_attr attr;
 if (!(s = (struct cdp_session *)malloc(sizeof(struct cdp_session))))
  return ((void *)0);
 memset(s, 0, sizeof(struct cdp_session));
 s->sq = s->rq = -1;
 memset(s->sq_name, 0, sizeof(s->sq_name));
 snprintf(s->sq_name, sizeof(s->sq_name), "/lisa-cdp-%d", 0);
 s->sq_name[sizeof(s->sq_name)-1] = '\0';
 if ((s->sq = mq_open(s->sq_name, 01)) < 0)
  goto out_err;
 memset(s->rq_name, 0, sizeof(s->rq_name));
 snprintf(s->rq_name, sizeof(s->rq_name), "/lisa-cdp-%d", getpid());
 s->rq_name[sizeof(s->rq_name)-1] = '\0';
 if ((s->rq = mq_open(s->rq_name, 0100|00, 0666, ((void *)0))) < 0)
  goto out_err;
 if (mq_getattr(s->rq, &attr) < 0)
  goto out_err;
 s->max_msg_len = attr.mq_msgsize;
 if (!(s->response = malloc(s->max_msg_len)))
  goto out_err;
 return s;
out_err:
 cdp_session_end(s);
 return ((void *)0);
}

canonical_original_code:
struct cdp_session *cdp_session_start()
{
 struct cdp_session *s;
 struct mq_attr attr;
 if (!(s = (struct cdp_session *)malloc(sizeof(struct cdp_session))))
  return ((void *)0);
 memset(s, 0, sizeof(struct cdp_session));
 s->sq = s->rq = -1;
 memset(s->sq_name, 0, sizeof(s->sq_name));
 snprintf(s->sq_name, sizeof(s->sq_name), "/lisa-cdp-%d", 0);
 s->sq_name[sizeof(s->sq_name)-1] = '\0';
 if ((s->sq = mq_open(s->sq_name, 01)) < 0)
  goto out_err;
 memset(s->rq_name, 0, sizeof(s->rq_name));
 snprintf(s->rq_name, sizeof(s->rq_name), "/lisa-cdp-%d", getpid());
 s->rq_name[sizeof(s->rq_name)-1] = '\0';
 if ((s->rq = mq_open(s->rq_name, 0100|00, 0666, ((void *)0))) < 0)
  goto out_err;
 if (mq_getattr(s->rq, &attr) < 0)
  goto out_err;
 s->max_msg_len = attr.mq_msgsize;
 if (!(s->response = malloc(s->max_msg_len)))
  goto out_err;
 return s;
out_err:
 cdp_session_end(s);
 return ((void *)0);
}

variable_types: struct mq_attr { long mq_flags; long mq_maxmsg; long mq_msgsize; long mq_curmsgs; long __pad[4]; }

return_type: struct cdp_session { int sq; char sq_name[32]; char *response; int max_msg_len; } *


decompiled_code:
__int64 __fastcall cdp_session_recv(__int64 a1)
{
__int64 v1; // rdx
__int64 v2; // rsi
__int64 v3; // rdi
__int64 result; // rax
unsigned int v5; // ebx
time_t timer; // [rsp+8h] [rbp-30h] BYREF
__int128 v7; // [rsp+10h] [rbp-28h] BYREF

if ( !a1 )
_assert_fail("s", "cdp_client.c", 0x4Bu, "cdp_session_recv");
v7 = 0LL;
time(&timer);
v1 = *(int *)(a1 + 80);
v2 = *(_QWORD *)(a1 + 72);
v3 = *(unsigned int *)(a1 + 4);
*(_QWORD *)&v7 = timer + 3;
LODWORD(result) = mq_timedreceive(v3, v2, v1, 0LL, &v7);
v5 = result;
if ( (int)result >= 0 )
return (unsigned int)result;
fprintf(stderr, "No message received from cdpd in %d seconds.\nDisabling cdp in this session.\n", 3LL);
return v5;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1)
{
__int64 v1; // rdx
__int64 v2; // rsi
__int64 v3; // rdi
__int64 result; // rax
unsigned int v5; // ebx
time_t timer; // [rsp+8h] [rbp-30h] BYREF
__int128 v7; // [rsp+10h] [rbp-28h] BYREF

if ( !a1 )
_assert_fail("s", "cdp_client.c", 0x4Bu, "cdp_session_recv");
v7 = 0LL;
time(&timer);
v1 = *(int *)(a1 + 80);
v2 = *(_QWORD *)(a1 + 72);
v3 = *(unsigned int *)(a1 + 4);
*(_QWORD *)&v7 = timer + 3;
LODWORD(result) = mq_timedreceive(v3, v2, v1, 0LL, &v7);
v5 = result;
if ( (int)result >= 0 )
return (unsigned int)result;
fprintf(stderr, "No message received from cdpd in %d seconds.\nDisabling cdp in this session.\n", 3LL);
return v5;
}

original_code:
int cdp_session_recv(struct cdp_session *s)
{
 struct timespec ts;
 time_t ns;
 int err;
 ((void) sizeof ((s) ? 1 : 0), __extension__ ({ if (s) ; else __assert_fail ("s", "cdp_client.c", 75, __extension__ __PRETTY_FUNCTION__); }));
 memset(&ts, 0, sizeof(ts));
 time(&ns);
 ts.tv_sec = ns + 3;
 if ((err = mq_timedreceive(s->rq, s->response, s->max_msg_len, ((void *)0), &ts)) < 0) {
  fprintf(stderr, "No message received from cdpd in %d seconds.\n"
   "Disabling cdp in this session.\n", 3);
 }
 return err;
}

canonical_original_code:
int cdp_session_recv(struct cdp_session *s)
{
 struct timespec ts;
 long ns;
 int err;
 ((void) sizeof ((s) ? 1 : 0), __extension__ ({ if (s) ; else __assert_fail ("s", "cdp_client.c", 75, __extension__ __PRETTY_FUNCTION__); }));
 memset(&ts, 0, sizeof(ts));
 time(&ns);
 ts.tv_sec = ns + 3;
 if ((err = mq_timedreceive(s->rq, s->response, s->max_msg_len, ((void *)0), &ts)) < 0) {
  fprintf(stderr, "No message received from cdpd in %d seconds.\n"
   "Disabling cdp in this session.\n", 3);
 }
 return err;
}

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

variable_types: ns long

variable_types: err int

user_defined_types: struct cdp_session { int sq; char sq_name[32]; char *response; int max_msg_len; }


decompiled_code:
__int64 __fastcall cdp_is_enabled(unsigned int *a1, int a2)
{
__pid_t v3; // eax
__int64 v4; // rdi
int v5; // eax
int v6; // eax
__int64 result; // rax
unsigned int v8; // [rsp+Ch] [rbp-6Ch]
unsigned int v9; // [rsp+Ch] [rbp-6Ch]
int v10[26]; // [rsp+10h] [rbp-68h] BYREF

if ( !a1 )
_assert_fail("session", "cdp_client.c", 0x5Eu, "cdp_is_enabled");
memset(v10, 0, 0x48uLL);
v10[0] = 5;
v10[18] = 0;
v3 = getpid();
v4 = *a1;
v10[1] = v3;
v10[2] = a2;
v5 = mq_send(v4, v10, 76LL, 0LL);
if ( v5 < 0 )
{
v8 = v5;
perror("cdp_session_send");
result = v8;
}
else
{
v6 = cdp_session_recv((__int64)a1);
if ( v6 < 0 )
{
v9 = v6;
perror("cdp_session_recv");
result = v9;
}
else
{
result = **((unsigned int **)a1 + 9);
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(unsigned int *a1, int a2)
{
__pid_t v3; // eax
__int64 v4; // rdi
int v5; // eax
int v6; // eax
__int64 result; // rax
unsigned int v8; // [rsp+Ch] [rbp-6Ch]
unsigned int v9; // [rsp+Ch] [rbp-6Ch]
int v10[26]; // [rsp+10h] [rbp-68h] BYREF

if ( !a1 )
_assert_fail("session", "cdp_client.c", 0x5Eu, "cdp_is_enabled");
memset(v10, 0, 0x48uLL);
v10[0] = 5;
v10[18] = 0;
v3 = getpid();
v4 = *a1;
v10[1] = v3;
v10[2] = a2;
v5 = mq_send(v4, v10, 76LL, 0LL);
if ( v5 < 0 )
{
v8 = v5;
perror("cdp_session_send");
result = v8;
}
else
{
v6 = func2((__int64)a1);
if ( v6 < 0 )
{
v9 = v6;
perror("cdp_session_recv");
result = v9;
}
else
{
result = **((unsigned int **)a1 + 9);
}
}
return result;
}

original_code:
int cdp_is_enabled(struct cdp_session *session, int if_index)
{
 struct cdp_request m;
 int err;
 ((void) sizeof ((session) ? 1 : 0), __extension__ ({ if (session) ; else __assert_fail ("session", "cdp_client.c", 94, __extension__ __PRETTY_FUNCTION__); }));
 memset(&m, 0, sizeof(m));
 m.type = CDP_IF_STATUS;
 m.pid = getpid();
 m.if_index = if_index;
 if ((err = ({ int r = mq_send(session->sq, (const char *)&m, sizeof(m), 0); r; })) < 0) {
  perror("cdp_session_send");
  return err;
 }
 if ((err = cdp_session_recv(session)) < 0) {
  perror("cdp_session_recv");
  return err;
 }
 return *((int *)session->response);
}

variable_types: struct cdp_request { int type; int pid; int if_index; char device_id[64]; }

variable_types: r int


decompiled_code:
__int64 __fastcall cdp_set_interface(unsigned int *a1, int a2, int a3)
{
__pid_t v4; // eax
__int64 v5; // rdi
int v6; // eax
unsigned int v8; // [rsp+Ch] [rbp-6Ch]
int v9[26]; // [rsp+10h] [rbp-68h] BYREF

if ( !a1 )
_assert_fail("session", "cdp_client.c", 0x76u, "cdp_set_interface");
memset(v9, 0, 0x48uLL);
v9[0] = (a3 == 0) + 3;
v9[18] = 0;
v4 = getpid();
v5 = *a1;
v9[1] = v4;
v9[2] = a2;
v6 = mq_send(v5, v9, 76LL, 0LL);
if ( v6 >= 0 )
return cdp_session_recv((__int64)a1);
v8 = v6;
perror("cdp_session_send");
return v8;
}

canonical_decompiled_code:
__int64 __fastcall func4(unsigned int *a1, int a2, int a3)
{
__pid_t v4; // eax
__int64 v5; // rdi
int v6; // eax
unsigned int v8; // [rsp+Ch] [rbp-6Ch]
int v9[26]; // [rsp+10h] [rbp-68h] BYREF

if ( !a1 )
_assert_fail("session", "cdp_client.c", 0x76u, "cdp_set_interface");
memset(v9, 0, 0x48uLL);
v9[0] = (a3 == 0) + 3;
v9[18] = 0;
v4 = getpid();
v5 = *a1;
v9[1] = v4;
v9[2] = a2;
v6 = mq_send(v5, v9, 76LL, 0LL);
if ( v6 >= 0 )
return func2((__int64)a1);
v8 = v6;
perror("cdp_session_send");
return v8;
}

original_code:
int cdp_set_interface(struct cdp_session *session, int if_index, int enabled)
{
 struct cdp_request m;
 int err;
 ((void) sizeof ((session) ? 1 : 0), __extension__ ({ if (session) ; else __assert_fail ("session", "cdp_client.c", 118, __extension__ __PRETTY_FUNCTION__); }));
 memset(&m, 0, sizeof(m));
 m.type = enabled? CDP_IF_ENABLE : CDP_IF_DISABLE;
 m.pid = getpid();
 m.if_index = if_index;
 if ((err = ({ int r = mq_send(session->sq, (const char *)&m, sizeof(m), 0); r; })) < 0) {
  perror("cdp_session_send");
  return err;
 }
 return cdp_session_recv(session);
}

variable_types: enabled int

user_defined_types: struct cdp_request { int type; int pid; int if_index; char device_id[64]; }


decompiled_code:
__int64 __fastcall cdp_get_neighbors(unsigned int *a1, int a2, const char *a3)
{
__pid_t v4; // eax
size_t v5; // rbx
int v6; // eax
unsigned int v8; // [rsp+Ch] [rbp-7Ch]
int v9[30]; // [rsp+10h] [rbp-78h] BYREF

if ( !a1 )
_assert_fail("session", "cdp_client.c", 0x89u, "cdp_get_neighbors");
memset(v9, 0, 0x48uLL);
v9[18] = 0;
v4 = getpid();
v9[2] = a2;
v9[1] = v4;
if ( a3 )
{
v5 = strlen(a3);
strncpy((char *)&v9[3], a3, v5);
*((_BYTE *)&v9[3] + v5) = 0;
}
v6 = mq_send(*a1, v9, 76LL, 0LL);
if ( v6 >= 0 )
return cdp_session_recv((__int64)a1);
v8 = v6;
perror("cdp_session_send");
return v8;
}

canonical_decompiled_code:
__int64 __fastcall func5(unsigned int *a1, int a2, const char *a3)
{
__pid_t v4; // eax
size_t v5; // rbx
int v6; // eax
unsigned int v8; // [rsp+Ch] [rbp-7Ch]
int v9[30]; // [rsp+10h] [rbp-78h] BYREF

if ( !a1 )
_assert_fail("session", "cdp_client.c", 0x89u, "cdp_get_neighbors");
memset(v9, 0, 0x48uLL);
v9[18] = 0;
v4 = getpid();
v9[2] = a2;
v9[1] = v4;
if ( a3 )
{
v5 = strlen(a3);
strncpy((char *)&v9[3], a3, v5);
*((_BYTE *)&v9[3] + v5) = 0;
}
v6 = mq_send(*a1, v9, 76LL, 0LL);
if ( v6 >= 0 )
return func2((__int64)a1);
v8 = v6;
perror("cdp_session_send");
return v8;
}

original_code:
int cdp_get_neighbors(struct cdp_session *session, int if_index, char *device_id)
{
 struct cdp_request m;
 int err;
 ((void) sizeof ((session) ? 1 : 0), __extension__ ({ if (session) ; else __assert_fail ("session", "cdp_client.c", 137, __extension__ __PRETTY_FUNCTION__); }));
 memset(&m, 0, sizeof(m));
 m.type = CDP_SHOW_NEIGHBORS;
 m.pid = getpid();
 m.if_index = if_index;
 if (device_id) {
  strncpy(m.device_id, device_id, strlen(device_id));
  m.device_id[strlen(device_id)] = '\0';
 }
 if ((err = ({ int r = mq_send(session->sq, (const char *)&m, sizeof(m), 0); r; })) < 0) {
  perror("cdp_session_send");
  return err;
 }
 return cdp_session_recv(session);
}


decompiled_code:
__int64 __fastcall cdp_get_interfaces(unsigned int *a1, int a2)
{
__pid_t v3; // eax
__int64 v4; // rdi
int v5; // eax
unsigned int v7; // [rsp+Ch] [rbp-6Ch]
int v8[26]; // [rsp+10h] [rbp-68h] BYREF

if ( !a1 )
_assert_fail("session", "cdp_client.c", 0xA1u, "cdp_get_interfaces");
memset(v8, 0, 0x48uLL);
v8[0] = 2;
v8[18] = 0;
v3 = getpid();
v4 = *a1;
v8[1] = v3;
v8[2] = a2;
v5 = mq_send(v4, v8, 76LL, 0LL);
if ( v5 >= 0 )
return cdp_session_recv((__int64)a1);
v7 = v5;
perror("cdp_session_send");
return v7;
}

canonical_decompiled_code:
__int64 __fastcall func6(unsigned int *a1, int a2)
{
__pid_t v3; // eax
__int64 v4; // rdi
int v5; // eax
unsigned int v7; // [rsp+Ch] [rbp-6Ch]
int v8[26]; // [rsp+10h] [rbp-68h] BYREF

if ( !a1 )
_assert_fail("session", "cdp_client.c", 0xA1u, "cdp_get_interfaces");
memset(v8, 0, 0x48uLL);
v8[0] = 2;
v8[18] = 0;
v3 = getpid();
v4 = *a1;
v8[1] = v3;
v8[2] = a2;
v5 = mq_send(v4, v8, 76LL, 0LL);
if ( v5 >= 0 )
return func2((__int64)a1);
v7 = v5;
perror("cdp_session_send");
return v7;
}

original_code:
int cdp_get_interfaces(struct cdp_session *session, int if_index)
{
 struct cdp_request m;
 int err;
 ((void) sizeof ((session) ? 1 : 0), __extension__ ({ if (session) ; else __assert_fail ("session", "cdp_client.c", 161, __extension__ __PRETTY_FUNCTION__); }));
 memset(&m, 0, sizeof(m));
 m.type = CDP_SHOW_INTF;
 m.pid = getpid();
 m.if_index = if_index;
 if ((err = ({ int r = mq_send(session->sq, (const char *)&m, sizeof(m), 0); r; })) < 0) {
  perror("cdp_session_send");
  return err;
 }
 return cdp_session_recv(session);
}


decompiled_code:
__int64 __fastcall cdp_get_stats(unsigned int *a1, __int64 a2)
{
__pid_t v3; // eax
__int64 v4; // rdi
int v5; // eax
unsigned int v7; // [rsp+Ch] [rbp-6Ch]
int v8[26]; // [rsp+10h] [rbp-68h] BYREF

if ( !a1 )
_assert_fail("session", "cdp_client.c", 0xB4u, "cdp_get_stats");
if ( !a2 )
_assert_fail("stats", "cdp_client.c", 0xB5u, "cdp_get_stats");
memset(v8, 0, 0x48uLL);
v8[0] = 1;
v8[18] = 0;
v3 = getpid();
v4 = *a1;
v8[1] = v3;
v5 = mq_send(v4, v8, 76LL, 0LL);
if ( v5 >= 0 )
return cdp_session_recv((__int64)a1);
v7 = v5;
perror("cdp_session_send");
return v7;
}

canonical_decompiled_code:
__int64 __fastcall func7(unsigned int *a1, __int64 a2)
{
__pid_t v3; // eax
__int64 v4; // rdi
int v5; // eax
unsigned int v7; // [rsp+Ch] [rbp-6Ch]
int v8[26]; // [rsp+10h] [rbp-68h] BYREF

if ( !a1 )
_assert_fail("session", "cdp_client.c", 0xB4u, "cdp_get_stats");
if ( !a2 )
_assert_fail("stats", "cdp_client.c", 0xB5u, "cdp_get_stats");
memset(v8, 0, 0x48uLL);
v8[0] = 1;
v8[18] = 0;
v3 = getpid();
v4 = *a1;
v8[1] = v3;
v5 = mq_send(v4, v8, 76LL, 0LL);
if ( v5 >= 0 )
return func2((__int64)a1);
v7 = v5;
perror("cdp_session_send");
return v7;
}

original_code:
int cdp_get_stats(struct cdp_session *session, struct cdp_traffic_stats *stats)
{
 struct cdp_request m;
 int err;
 ((void) sizeof ((session) ? 1 : 0), __extension__ ({ if (session) ; else __assert_fail ("session", "cdp_client.c", 180, __extension__ __PRETTY_FUNCTION__); }));
 ((void) sizeof ((stats) ? 1 : 0), __extension__ ({ if (stats) ; else __assert_fail ("stats", "cdp_client.c", 181, __extension__ __PRETTY_FUNCTION__); }));
 memset(&m, 0, sizeof(m));
 m.type = CDP_SHOW_STATS;
 m.pid = getpid();
 if ((err = ({ int r = mq_send(session->sq, (const char *)&m, sizeof(m), 0); r; })) < 0) {
  perror("cdp_session_send");
  return err;
 }
 if ((err = cdp_session_recv(session)) < 0)
  return err;
 stats = (struct cdp_traffic_stats *)session->response;
 return err;
}

variable_types: struct cdp_traffic_stats { unsigned int v1_in; unsigned int v2_in; unsigned int v1_out; unsigned int v2_out; } *


decompiled_code:
void __noreturn timedout2()
{
_BYTE v0[6]; // [rsp+0h] [rbp-28h] BYREF
__int16 v1; // [rsp+6h] [rbp-22h]

ioctl(0, 0x5405uLL, v0);
v1 |= 8u;
ioctl(0, 0x5406uLL, v0);
exit(0);
}

original_code:
static void
timedout2(int sig) {
 struct termio ti;
 ioctl(0, 0x5405, &ti);
 ti.c_lflag |= 0000010;
 ioctl(0, 0x5406, &ti);
 exit(0);
}

variable_types: sig int

variable_types: struct termio { unsigned short c_iflag; unsigned short c_oflag; unsigned short c_cflag; unsigned short c_lflag; unsigned char c_line; unsigned char c_cc[8]; }


timedout

decompiled_code:
void __noreturn timedout()
{
signal(14, (__sighandler_t)timedout2);
alarm(0xAu);
fprintf(stderr, "Login timed out after %d seconds\n", 6000LL);
signal(14, (__sighandler_t)((char *)timedout2 + 1));
alarm(0);
timedout2();
}

canonical_decompiled_code:
void __noreturn func1()
{
signal(14, (__sighandler_t)timedout2);
alarm(0xAu);
fprintf(stderr, "Login timed out after %d seconds\n", 6000LL);
signal(14, (__sighandler_t)((char *)timedout2 + 1));
alarm(0);
func0();
}

original_code:
static void
timedout(int sig) {
 signal(14, timedout2);
 alarm(10);
 fprintf(stderr, "Login timed out after %d seconds\n", timeout);
 signal(14, ((__sighandler_t) 1));
 alarm(0);
 timedout2(0);
}

canonical_original_code:
static void timedout(int sig) {
 signal(14, timedout2);
 alarm(10);
 fprintf(stderr, "Login timed out after %d seconds\n", timeout);
 signal(14, ((void (*)(int)) 1));
 alarm(0);
 timedout2(0);
}


decompiled_code:
int __fastcall check_ttyname(char *s1)
{
int result; // eax
struct stat v2; // [rsp+0h] [rbp-98h] BYREF

if ( lstat(s1, &v2)
|| (result = v2.st_mode & 0xF000, result != 0x2000)
|| v2.st_nlink > 1 && (result = strncmp(s1, "/dev/", 5uLL)) != 0 )
{
syslog(3, "FATAL: bad tty");
sleep(1u);
exit(1);
}
return result;
}

canonical_decompiled_code:
int __fastcall func2(char *s1)
{
int result; // eax
struct stat v2; // [rsp+0h] [rbp-98h] BYREF

if ( lstat(s1, &v2)
|| (result = v2.st_mode & 0xF000, result != 0x2000)
|| v2.st_nlink > 1 && (result = strncmp(s1, "/dev/", 5uLL)) != 0 )
{
syslog(3, "FATAL: bad tty");
sleep(1u);
exit(1);
}
return result;
}

original_code:
static void
check_ttyname(char *ttyn) {
 struct stat statbuf;
 if (lstat(ttyn, &statbuf)
     || !((((statbuf.st_mode)) & 0170000) == (0020000))
     || (statbuf.st_nlink > 1 && strncmp(ttyn, "/dev/", 5))) {
  syslog(3, "FATAL: bad tty");
  sleep(1);
  exit(1);
 }
}

variable_types:
ttyn
char *

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

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


opentty

decompiled_code:
int __fastcall opentty(const char *a1)
{
int v1; // eax
int v2; // ebp
unsigned int v3; // eax
int result; // eax
int i; // ebx
int v6; // edi
int j; // ebx
int *v8; // rax
char *v9; // rax

v1 = open(a1, 2050);
if ( v1 == -1 )
{
v8 = _errno_location();
v9 = strerror(*v8);
syslog(3, "FATAL: can't reopen tty: %s", v9);
sleep(1u);
exit(1);
}
v2 = v1;
v3 = fcntl(v1, 3);
BYTE1(v3) &= 0xF7u;
result = fcntl(v2, 4, v3);
if ( v2 > 0 )
{
for ( i = 0; i != v2; ++i )
{
v6 = i;
result = close(v6);
}
}
for ( j = 0; j != 3; ++j )
{
if ( v2 != j )
result = dup2(v2, j);
}
if ( v2 > 2 )
result = close(v2);
return result;
}

canonical_decompiled_code:
int __fastcall func3(const char *a1)
{
int v1; // eax
int v2; // ebp
unsigned int v3; // eax
int result; // eax
int i; // ebx
int v6; // edi
int j; // ebx
int *v8; // rax
char *v9; // rax

v1 = open(a1, 2050);
if ( v1 == -1 )
{
v8 = _errno_location();
v9 = strerror(*v8);
syslog(3, "FATAL: can't reopen tty: %s", v9);
sleep(1u);
exit(1);
}
v2 = v1;
v3 = fcntl(v1, 3);
BYTE1(v3) &= 0xF7u;
result = fcntl(v2, 4, v3);
if ( v2 > 0 )
{
for ( i = 0; i != v2; ++i )
{
v6 = i;
result = close(v6);
}
}
for ( j = 0; j != 3; ++j )
{
if ( v2 != j )
result = dup2(v2, j);
}
if ( v2 > 2 )
result = close(v2);
return result;
}

original_code:
static void
opentty(const char * tty) {
 int i, fd, flags;
 fd = open(tty, 02 | 04000);
 if (fd == -1) {
  syslog(3, "FATAL: can't reopen tty: %s",
         strerror((*__errno_location ())));
  sleep(1);
  exit(1);
 }
 flags = fcntl(fd, 3);
 flags &= ~04000;
 fcntl(fd, 4, flags);
 for (i = 0; i < fd; i++)
  close(i);
 for (i = 0; i < 3; i++)
  if (fd != i)
   dup2(fd, i);
 if (fd >= 3)
  close(fd);
}

canonical_original_code:
static void opentty(char *tty) {
 int i; int fd; int flags;
 fd = open(tty, 02 | 04000);
 if (fd == -1) {
  syslog(3, "FATAL: can't reopen tty: %s",
         strerror((*__errno_location ())));
  sleep(1);
  exit(1);
 }
 flags = fcntl(fd, 3);
 flags &= ~04000;
 fcntl(fd, 4, flags);
 for (i = 0; i < fd; i++)
  close(i);
 for (i = 0; i < 3; i++)
  if (fd != i)
   dup2(fd, i);
 if (fd >= 3)
  close(fd);
}

variable_types:
tty
char *

variable_types: i int

variable_types: fd int

variable_types: flags int


xstrncpy

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

result = strncpy(a1, a2, a3 - 1);
result[a3 - 1] = 0;
return result;
}

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

result = strncpy(a1, a2, a3 - 1);
result[a3 - 1] = 0;
return result;
}

original_code:
void
xstrncpy(char *dest, const char *src, size_t n) {
 strncpy(dest, src, n-1);
 dest[n-1] = 0;
}

canonical_original_code:
void xstrncpy(char *dest, char *src, unsigned long n) {
 strncpy(dest, src, n-1);
 dest[n-1] = 0;
}

variable_types:
dest
char *

variable_types:
src
char *

variable_types:
n
unsigned long


badlogin

decompiled_code:
void __fastcall badlogin(const char *a1)
{
if ( failures == 1 )
{
if ( hostname )
syslog(5, "LOGIN FAILURE FROM %s, %s", (const char *)hostname, a1);
else
syslog(5, "LOGIN FAILURE ON %s, %s", tty_name, a1);
}
else if ( hostname )
{
syslog(5, "%d LOGIN FAILURES FROM %s, %s", (unsigned int)failures, (const char *)hostname, a1);
}
else
{
syslog(5, "%d LOGIN FAILURES ON %s, %s", (unsigned int)failures, tty_name, a1);
}
}

canonical_decompiled_code:
void __fastcall func6(const char *a1)
{
if ( failures == 1 )
{
if ( hostname )
syslog(5, "LOGIN FAILURE FROM %s, %s", (const char *)hostname, a1);
else
syslog(5, "LOGIN FAILURE ON %s, %s", tty_name, a1);
}
else if ( hostname )
{
syslog(5, "%d LOGIN FAILURES FROM %s, %s", (unsigned int)failures, (const char *)hostname, a1);
}
else
{
syslog(5, "%d LOGIN FAILURES ON %s, %s", (unsigned int)failures, tty_name, a1);
}
}

original_code:
void
badlogin(const char *name) {
    if (failures == 1) {
 if (hostname)
   syslog(5, "LOGIN FAILURE FROM %s, %s",
   hostname, name);
 else
   syslog(5, "LOGIN FAILURE ON %s, %s",
   tty_name, name);
    } else {
 if (hostname)
   syslog(5, "%d LOGIN FAILURES FROM %s, %s",
   failures, hostname, name);
 else
   syslog(5, "%d LOGIN FAILURES ON %s, %s",
   failures, tty_name, name);
    }
}

canonical_original_code:
void badlogin(char *name) {
    if (failures == 1) {
 if (hostname)
   syslog(5, "LOGIN FAILURE FROM %s, %s",
   hostname, name);
 else
   syslog(5, "LOGIN FAILURE ON %s, %s",
   tty_name, name);
    } else {
 if (hostname)
   syslog(5, "%d LOGIN FAILURES FROM %s, %s",
   failures, hostname, name);
 else
   syslog(5, "%d LOGIN FAILURES ON %s, %s",
   failures, tty_name, name);
    }
}

variable_types:
name
char *


getloginname

decompiled_code:
int getloginname()
{
int v0; // er12
int v1; // ebx
char *v2; // rbp
int result; // eax

v0 = 51;
while ( 1 )
{
v1 = 53;
printf("\n%s login: ", thishost);
v2 = &nbuf_0;
fflush(stdout);
while ( 1 )
{
result = getchar();
if ( result == 10 )
break;
if ( result == -1 )
{
badlogin("EOF");
exit(0);
}
if ( v2 < byte_5E0 )
*v2++ = result;
if ( !--v1 )
{
fwrite("login name much too long.\n", 1uLL, 0x1AuLL, stderr);
badlogin("NAME too long");
exit(0);
}
}
if ( v2 > &nbuf_0 )
break;
LABEL_11:
if ( !--v0 )
{
fwrite("too many bare linefeeds.\n", 1uLL, 0x19uLL, stderr);
badlogin("EXCESSIVE linefeeds");
exit(0);
}
}
if ( nbuf_0 == 45 )
{
fwrite("login names may not start with '-'.\n", 1uLL, 0x24uLL, stderr);
goto LABEL_11;
}
*v2 = 0;
username = &nbuf_0;
return result;
}

canonical_decompiled_code:
int func7()
{
int v0; // er12
int v1; // ebx
char *v2; // rbp
int result; // eax

v0 = 51;
while ( 1 )
{
v1 = 53;
printf("\n%s login: ", thishost);
v2 = &nbuf_0;
fflush(stdout);
while ( 1 )
{
result = getchar();
if ( result == 10 )
break;
if ( result == -1 )
{
func6("EOF");
exit(0);
}
if ( v2 < byte_5E0 )
*v2++ = result;
if ( !--v1 )
{
fwrite("login name much too long.\n", 1uLL, 0x1AuLL, stderr);
func6("NAME too long");
exit(0);
}
}
if ( v2 > &nbuf_0 )
break;
LABEL_11:
if ( !--v0 )
{
fwrite("too many bare linefeeds.\n", 1uLL, 0x19uLL, stderr);
func6("EXCESSIVE linefeeds");
exit(0);
}
}
if ( nbuf_0 == 45 )
{
fwrite("login names may not start with '-'.\n", 1uLL, 0x24uLL, stderr);
goto LABEL_11;
}
*v2 = 0;
username = &nbuf_0;
return result;
}

original_code:
static void
getloginname(void) {
    int ch, cnt, cnt2;
    char *p;
    static char nbuf[32 + 1];
    cnt2 = 0;
    for (;;) {
 cnt = 0;
 printf("\n%s login: ", thishost); fflush(stdout);
 for (p = nbuf; (ch = getchar()) != '\n'; ) {
     if (ch == (-1)) {
  badlogin("EOF");
  exit(0);
     }
     if (p < nbuf + 32)
       *p++ = ch;
     cnt++;
     if (cnt > 32 + 20) {
  fprintf(stderr, "login name much too long.\n");
  badlogin("NAME too long");
  exit(0);
     }
 }
 if (p > nbuf) {
   if (nbuf[0] == '-')
     fprintf(stderr,
      "login names may not start with '-'.\n");
   else {
       *p = '\0';
       username = nbuf;
       break;
   }
 }
 cnt2++;
 if (cnt2 > 50) {
     fprintf(stderr, "too many bare linefeeds.\n");
     badlogin("EXCESSIVE linefeeds");
     exit(0);
 }
    }
}

canonical_original_code:
static void getloginname() {
    int ch; int cnt; int cnt2;
    char *p;
    static char nbuf[-1];
    cnt2 = 0;
    for (;;) {
 cnt = 0;
 printf("\n%s login: ", thishost); fflush(stdout);
 for (p = nbuf; (ch = getchar()) != '\n'; ) {
     if (ch == (-1)) {
  badlogin("EOF");
  exit(0);
     }
     if (p < nbuf + 32)
       *p++ = ch;
     cnt++;
     if (cnt > 32 + 20) {
  fprintf(stderr, "login name much too long.\n");
  badlogin("NAME too long");
  exit(0);
     }
 }
 if (p > nbuf) {
   if (nbuf[0] == '-')
     fprintf(stderr,
      "login names may not start with '-'.\n");
   else {
       *p = '\0';
       username = nbuf;
       break;
   }
 }
 cnt2++;
 if (cnt2 > 50) {
     fprintf(stderr, "too many bare linefeeds.\n");
     badlogin("EXCESSIVE linefeeds");
     exit(0);
 }
    }
}

variable_types: ch int

variable_types: cnt int

variable_types:
p
char *

variable_types:
nbuf
char [-1]


sleepexit

decompiled_code:
void __fastcall __noreturn sleepexit(int status)
{
sleep(5u);
exit(status);
}

canonical_decompiled_code:
void __fastcall __noreturn func8(int status)
{
sleep(5u);
exit(status);
}

original_code:
void
sleepexit(int eval) {
    sleep(5);
    exit(eval);
}

variable_types: eval int


checknologin

decompiled_code:
int checknologin()
{
int result; // eax
int v1; // ebp
int v2; // eax
int v3; // ebx
_BYTE v4[8216]; // [rsp+0h] [rbp-2018h] BYREF

result = open("/etc/nologin", 0, 0LL);
if ( result >= 0 )
{
v1 = result;
while ( 1 )
{
v3 = read(v1, v4, 0x2000uLL);
if ( v3 <= 0 )
break;
v2 = fileno(stdout);
write(v2, v4, v3);
}
close(v1);
sleepexit(0);
}
return result;
}

canonical_decompiled_code:
int func9()
{
int result; // eax
int v1; // ebp
int v2; // eax
int v3; // ebx
_BYTE v4[8216]; // [rsp+0h] [rbp-2018h] BYREF

result = open("/etc/nologin", 0, 0LL);
if ( result >= 0 )
{
v1 = result;
while ( 1 )
{
v3 = read(v1, v4, 0x2000uLL);
if ( v3 <= 0 )
break;
v2 = fileno(stdout);
write(v2, v4, v3);
}
close(v1);
func8(0);
}
return result;
}

original_code:
void
checknologin(void) {
    int fd, nchars;
    char tbuf[8192];
    if ((fd = open("/etc/nologin", 00, 0)) >= 0) {
 while ((nchars = read(fd, tbuf, sizeof(tbuf))) > 0)
   write(fileno(stdout), tbuf, nchars);
 close(fd);
 sleepexit(0);
    }
}

canonical_original_code:
void checknologin() {
    int fd; int nchars;
    char tbuf[8192];
    if ((fd = open("/etc/nologin", 00, 0)) >= 0) {
 while ((nchars = read(fd, tbuf, sizeof(tbuf))) > 0)
   write(fileno(stdout), tbuf, nchars);
 close(fd);
 sleepexit(0);
    }
}

variable_types: nchars int

variable_types:
tbuf
char [8192]