decompiled_code:
char *__fastcall fbc_get_hex_string(unsigned __int8 *a1, int a2, char *a3)
{
char *v3; // r13
unsigned __int8 *v4; // rbx
char *v5; // rbp
unsigned __int8 *v6; // r12
__int64 v7; // rdx
char *v8; // rdi

v3 = a3;
if ( a2 )
{
v4 = a1;
v5 = a3;
v6 = &a1[a2];
do
{
v7 = *v4;
v8 = v5;
++v4;
v5 += 2;
sprintf(v8, "%02x", v7);
}
while ( v4 != v6 );
}
return v3;
}

canonical_decompiled_code:
char *__fastcall func3(unsigned __int8 *a1, int a2, char *a3)
{
char *v3; // r13
unsigned __int8 *v4; // rbx
char *v5; // rbp
unsigned __int8 *v6; // r12
__int64 v7; // rdx
char *v8; // rdi

v3 = a3;
if ( a2 )
{
v4 = a1;
v5 = a3;
v6 = &a1[a2];
do
{
v7 = *v4;
v8 = v5;
++v4;
v5 += 2;
sprintf(v8, "%02x", v7);
}
while ( v4 != v6 );
}
return v3;
}

original_code:
const char *fbc_get_hex_string(Byte *buf, int len, char *hexstring)
{
 char *t = hexstring;
 while (len--) {
  sprintf(t, "%02x", (*buf++ & 0xff));
  t += 2;
 }
 return hexstring;
}

canonical_original_code:
char *fbc_get_hex_string(unsigned char *buf, int len, char *hexstring)
{
 char *t = hexstring;
 while (len--) {
  sprintf(t, "%02x", (*buf++ & 0xff));
  t += 2;
 }
 return hexstring;
}

variable_types:
buf
unsigned char *

variable_types:
hexstring
char *

variable_types:
t
char *


repo: chhquan/fibacap

variable_types:
addr
char *

variable_types:
dst
unsigned char *

variable_types: size int

return_type: void


decompiled_code:
int __fastcall fbc_ip_addr_pton(char *cp, void *buf)
{
return inet_pton(2, cp, buf);
}

canonical_decompiled_code:
int __fastcall func5(char *cp, void *buf)
{
return inet_pton(2, cp, buf);
}

original_code:
void fbc_ip_addr_pton(const char *addr, Byte *dst, int size)
{
 inet_pton(2, addr, dst);
}

canonical_original_code:
void fbc_ip_addr_pton(char *addr, unsigned char *dst, int size)
{
 inet_pton(2, addr, dst);
}


decompiled_code:
int __fastcall print_byte(unsigned __int8 a1)
{
int v1; // ebx

v1 = 7;
do
putchar((((int)a1 >> v1) & 1) + 48);
while ( v1-- != 0 );
return putchar(32);
}

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

v1 = 7;
do
putchar((((int)a1 >> v1) & 1) + 48);
while ( v1-- != 0 );
return putchar(32);
}

original_code:
void print_byte(Byte byte) {
 int c = 8;
 while (c--) {
  printf("%c", ((byte >> c) & 0x01) ? '1' : '0');
 }
 printf(" ");
}

canonical_original_code:
void print_byte(unsigned char byte) {
 int c = 8;
 while (c--) {
  printf("%c", ((byte >> c) & 0x01) ? '1' : '0');
 }
 printf(" ");
}

variable_types:
byte
unsigned char

variable_types: c int


decompiled_code:
int __fastcall print_hex(unsigned __int8 a1)
{
char v2; // di
unsigned __int8 v3; // bl

v2 = a1 >> 4;
if ( a1 > 0x9Fu )
{
v3 = a1 & 0xF;
putchar((unsigned __int8)(v2 + 55));
if ( v3 <= 9u )
goto LABEL_3;
}
else
{
v3 = a1 & 0xF;
putchar((unsigned __int8)(v2 + 48));
if ( v3 <= 9u )
{
LABEL_3:
putchar((unsigned __int8)(v3 + 48));
return putchar(32);
}
}
putchar((unsigned __int8)(v3 + 55));
return putchar(32);
}

canonical_decompiled_code:
int __fastcall func2(unsigned __int8 a1)
{
char v2; // di
unsigned __int8 v3; // bl

v2 = a1 >> 4;
if ( a1 > 0x9Fu )
{
v3 = a1 & 0xF;
putchar((unsigned __int8)(v2 + 55));
if ( v3 <= 9u )
goto LABEL_3;
}
else
{
v3 = a1 & 0xF;
putchar((unsigned __int8)(v2 + 48));
if ( v3 <= 9u )
{
LABEL_3:
putchar((unsigned __int8)(v3 + 48));
return putchar(32);
}
}
putchar((unsigned __int8)(v3 + 55));
return putchar(32);
}

canonical_original_code:
void print_hex(unsigned char byte) {
 int n = ((byte >> 4) & 0x0f);
 if (n < 10) {
  printf("%c", n + '0');
 } else {
  printf("%c", n - 10 + 'A');
 }
 n = (byte & 0x0f);
 if (n < 10) {
  printf("%c", n + '0');
 } else {
  printf("%c", n - 10 + 'A');
 }
 printf(" ");
}

variable_types: n int


decompiled_code:
int __fastcall print_char(unsigned __int8 a1)
{
int result; // eax

if ( (unsigned __int8)(a1 - 97) > 0x19u )
result = putchar(46);
else
result = putchar(a1);
return result;
}

canonical_decompiled_code:
int __fastcall func3(unsigned __int8 a1)
{
int result; // eax

if ( (unsigned __int8)(a1 - 97) > 0x19u )
result = putchar(46);
else
result = putchar(a1);
return result;
}

original_code:
void print_char(Byte byte) {
 if ('a' <= byte && byte <= 'z') {
  printf("%c", byte);
 } else {
  printf(".");
 }
}

canonical_original_code:
void print_char(unsigned char byte) {
 if ('a' <= byte && byte <= 'z') {
  printf("%c", byte);
 } else {
  printf(".");
 }
}


decompiled_code:
int __fastcall print_raw(unsigned __int8 *a1, int a2)
{
__int64 v2; // rbx

if ( a2 > 0 )
{
v2 = 2LL;
print_hex(*a1);
while ( v2 != a2 + 1 )
{
print_hex(a1[v2 - 1]);
if ( (v2 & 3) == 0 )
putchar(10);
++v2;
}
}
puts("\n");
return puts("\n");
}

original_code:
void print_raw(Byte const *buf, int length)
{
 int i = 0;
 i = 0;
 while (i < length) {
  print_hex(buf[i++]);
  if (! (i % 4)) {
   printf("\n");
  }
 }
 printf("\n\n");
 printf("\n\n");
}

canonical_original_code:
void print_raw(unsigned char *buf, int length)
{
 int i = 0;
 i = 0;
 while (i < length) {
  print_hex(buf[i++]);
  if (! (i % 4)) {
   printf("\n");
  }
 }
 printf("\n\n");
 printf("\n\n");
}

variable_types: length int

variable_types: i int


decompiled_code:
__int64 __fastcall fbc_arp_hardware_protocol_to_fbc_protocol(__int16 a1, char *a2)
{
__int64 result; // rax

if ( a1 == 1 )
{
result = 82LL;
strcpy(a2, "ETHER");
}
else
{
*a2 = 0;
}
return result;
}

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

if ( a1 == 1 )
{
result = 82LL;
strcpy(a2, "ETHER");
}
else
{
*a2 = 0;
}
return result;
}

original_code:
void fbc_arp_hardware_protocol_to_fbc_protocol(unsigned short hp, protocol_t fp)
{
 switch (hp) {
  case 1:
   strcpy((fp), ("ETHER"));
   break;
  default:
   strcpy((fp), (""));
   break;
 }
}

canonical_original_code:
void fbc_arp_hardware_protocol_to_fbc_protocol(unsigned short hp, char fp[16])
{
 switch (hp) {
  case 1:
   strcpy((fp), ("ETHER"));
   break;
  default:
   strcpy((fp), (""));
   break;
 }
}

variable_types:
hp
unsigned short

variable_types:
fp
char [16]


decompiled_code:
__int64 __fastcall fbc_arp_opcode_to_string(__int16 a1, char *a2)
{
__int64 result; // rax

if ( a2 )
{
switch ( a1 )
{
case 1:
result = 0x54534555514552LL;
*(_QWORD *)a2 = 0x54534555514552LL;
break;
case 2:
strcpy(a2, "REPLY");
break;
case 3:
result = 0x5453455551455252LL;
strcpy(a2, "RREQUEST");
break;
case 4:
strcpy(a2, "RREPLY");
break;
case 8:
strcpy(a2, "InREQUEST");
result = 84LL;
break;
case 9:
result = 0x594C5045526E49LL;
*(_QWORD *)a2 = 0x594C5045526E49LL;
break;
case 10:
*(_DWORD *)a2 = 4931918;
break;
default:
result = 0x4E574F4E4B4E55LL;
*(_QWORD *)a2 = 0x4E574F4E4B4E55LL;
break;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func5(__int16 a1, char *a2)
{
__int64 result; // rax

if ( a2 )
{
switch ( a1 )
{
case 1:
result = 0x54534555514552LL;
*(_QWORD *)a2 = 0x54534555514552LL;
break;
case 2:
strcpy(a2, "REPLY");
break;
case 3:
result = 0x5453455551455252LL;
strcpy(a2, "RREQUEST");
break;
case 4:
strcpy(a2, "RREPLY");
break;
case 8:
strcpy(a2, "InREQUEST");
result = 84LL;
break;
case 9:
result = 0x594C5045526E49LL;
*(_QWORD *)a2 = 0x594C5045526E49LL;
break;
case 10:
*(_DWORD *)a2 = 4931918;
break;
default:
result = 0x4E574F4E4B4E55LL;
*(_QWORD *)a2 = 0x4E574F4E4B4E55LL;
break;
}
}
return result;
}

original_code:
void fbc_arp_opcode_to_string(unsigned short op, char *opstring)
{
 if (! opstring) return;
 switch (op) {
  case 1:
   strcpy(opstring, "REQUEST");
   break;
  case 2:
   strcpy(opstring, "REPLY");
   break;
  case 3:
   strcpy(opstring, "RREQUEST");
   break;
  case 4:
   strcpy(opstring, "RREPLY");
   break;
  case 8:
   strcpy(opstring, "InREQUEST");
   break;
  case 9:
   strcpy(opstring, "InREPLY");
   break;
  case 10:
   strcpy(opstring, "NAK");
   break;
  default:
   strcpy(opstring, "UNKNOWN");
   break;
 }
}

variable_types:
op
unsigned short

variable_types:
opstring
char *


decompiled_code:
__int64 __fastcall fbc_network_protocol_to_fbc_protocol(__int16 a1, char *a2)
{
__int64 result; // rax

switch ( a1 )
{
case -32512:
strcpy(a2, "VLAN");
break;
case -31011:
strcpy(a2, "IPV6");
break;
case 2048:
result = 20553LL;
strcpy(a2, "IP");
break;
default:
result = 0x4E574F4E4B4E55LL;
*(_QWORD *)a2 = 0x4E574F4E4B4E55LL;
break;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int16 a1, char *a2)
{
__int64 result; // rax

switch ( a1 )
{
case -32512:
strcpy(a2, "VLAN");
break;
case -31011:
strcpy(a2, "IPV6");
break;
case 2048:
result = 20553LL;
strcpy(a2, "IP");
break;
default:
result = 0x4E574F4E4B4E55LL;
*(_QWORD *)a2 = 0x4E574F4E4B4E55LL;
break;
}
return result;
}

original_code:
void fbc_network_protocol_to_fbc_protocol(unsigned short np, protocol_t fp)
{
 switch (np) {
  case 0x0800:
   strcpy((fp), ("IP"));
   break;
  case 0x86dd:
   strcpy((fp), ("IPV6"));
   break;
  case 0x8100:
   strcpy((fp), ("VLAN"));
   break;
  default:
   strcpy((fp), ("UNKNOWN"));
   break;
 }
}

canonical_original_code:
void fbc_network_protocol_to_fbc_protocol(unsigned short np, char fp[16])
{
 switch (np) {
  case 0x0800:
   strcpy((fp), ("IP"));
   break;
  case 0x86dd:
   strcpy((fp), ("IPV6"));
   break;
  case 0x8100:
   strcpy((fp), ("VLAN"));
   break;
  default:
   strcpy((fp), ("UNKNOWN"));
   break;
 }
}

variable_types:
np
unsigned short


decompiled_code:
const char *__fastcall fbc_cut_tail_blank(const char *a1)
{
const char *result; // rax
char v2; // dl

result = (const char *)strlen(a1);
if ( (_DWORD)result )
{
result = &a1[(int)result];
do
{
v2 = *--result;
if ( (unsigned __int8)(v2 - 9) > 1u && v2 != 32 )
break;
*result = 0;
}
while ( a1 != result );
}
return result;
}

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

result = (const char *)strlen(a1);
if ( (_DWORD)result )
{
result = &a1[(int)result];
do
{
v2 = *--result;
if ( (unsigned __int8)(v2 - 9) > 1u && v2 != 32 )
break;
*result = 0;
}
while ( a1 != result );
}
return result;
}

original_code:
void fbc_cut_tail_blank(char *s) {
 int len = strlen(s);
 char *t = s + len;
 if (len == 0) return;
 do {
  --t;
  if (((*t) == ' ' || (*t) == '\t' || (*t) == '\n')) {
   *t = '\0';
  } else {
   break;
  }
 } while (t != s);
}

variable_types:
s
char *

variable_types: len int


decompiled_code:
__int64 __fastcall get_ip_checksum(__int64 a1, int a2)
{
return checksum(a1, (unsigned int)(a2 >> 1));
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, int a2)
{
return checksum(a1, (unsigned int)(a2 >> 1));
}

original_code:
unsigned short get_ip_checksum(Byte *header, int hlen)
{
 return checksum((unsigned short *)header, hlen >> 1);
}

canonical_original_code:
unsigned short get_ip_checksum(unsigned char *header, int hlen)
{
 return checksum((unsigned short *)header, hlen >> 1);
}

variable_types:
header
unsigned char *

variable_types: hlen int

return_type: unsigned short


repo: chiku/bootstrap-c

decompiled_code:
__int64 test_is_not_square_with_width_2_height_3()
{
tcase_fn_start("test_is_not_square_with_width_2_height_3", "rectangle_test.c", 40LL);
Rectangle_New(2.0, 3.0);
if ( !(unsigned int)Rectangle_IsSquare() )
return mark_point("rectangle_test.c", 43LL);
ck_assert_failed("rectangle_test.c", 43LL, "Assertion '!Rectangle_IsSquare(rectangle)' failed", 0LL, 0LL);
return test_is_square_when_width_1_height_1();
}

canonical_decompiled_code:
__int64 func0()
{
tcase_fn_start("test_is_not_square_with_width_2_height_3", "rectangle_test.c", 40LL);
Rectangle_New(2.0, 3.0);
if ( !(unsigned int)Rectangle_IsSquare() )
return mark_point("rectangle_test.c", 43LL);
ck_assert_failed("rectangle_test.c", 43LL, "Assertion '!Rectangle_IsSquare(rectangle)' failed", 0LL, 0LL);
return func1();
}

original_code:
static void test_is_not_square_with_width_2_height_3 (int _i __attribute__ ((unused))){ tcase_fn_start ("""test_is_not_square_with_width_2_height_3", "rectangle_test.c", 40);
{
  Rectangle rectangle = Rectangle_New(2.0, 3.0);
  (!Rectangle_IsSquare(rectangle)) ? _mark_point("rectangle_test.c", 43) : _ck_assert_failed("rectangle_test.c", 43, "Assertion '""!Rectangle_IsSquare(rectangle)""' failed" , ((void *)0), ((void *)0));
}
}

canonical_original_code:
static void test_is_not_square_with_width_2_height_3(int _i){ tcase_fn_start ("""test_is_not_square_with_width_2_height_3", "rectangle_test.c", 40);
{
  struct Rectangle rectangle = Rectangle_New(2.0, 3.0);
  (!Rectangle_IsSquare(rectangle)) ? _mark_point("rectangle_test.c", 43) : _ck_assert_failed("rectangle_test.c", 43, "Assertion '""!Rectangle_IsSquare(rectangle)""' failed" , ((void *)0), ((void *)0));
}
}

variable_types: struct Rectangle { double width; double height; }


decompiled_code:
__int64 test_is_square_when_width_1_height_1()
{
tcase_fn_start("test_is_square_when_width_1_height_1", "rectangle_test.c", 33LL);
Rectangle_New(1.0, 1.0);
if ( (unsigned int)Rectangle_IsSquare() )
return mark_point("rectangle_test.c", 36LL);
ck_assert_failed("rectangle_test.c", 36LL, "Assertion 'Rectangle_IsSquare(rectangle)' failed", 0LL, 0LL);
return test_perimeter_with_width_2_height_3_is_10();
}

canonical_decompiled_code:
__int64 func1()
{
tcase_fn_start("test_is_square_when_width_1_height_1", "rectangle_test.c", 33LL);
Rectangle_New(1.0, 1.0);
if ( (unsigned int)Rectangle_IsSquare() )
return mark_point("rectangle_test.c", 36LL);
ck_assert_failed("rectangle_test.c", 36LL, "Assertion 'Rectangle_IsSquare(rectangle)' failed", 0LL, 0LL);
return func2();
}

original_code:
static void test_is_square_when_width_1_height_1 (int _i __attribute__ ((unused))){ tcase_fn_start ("""test_is_square_when_width_1_height_1", "rectangle_test.c", 33);
{
  Rectangle rectangle = Rectangle_New(1.0, 1.0);
  (Rectangle_IsSquare(rectangle)) ? _mark_point("rectangle_test.c", 36) : _ck_assert_failed("rectangle_test.c", 36, "Assertion '""Rectangle_IsSquare(rectangle)""' failed" , ((void *)0), ((void *)0));
}
}

canonical_original_code:
static void test_is_square_when_width_1_height_1(int _i){ tcase_fn_start ("""test_is_square_when_width_1_height_1", "rectangle_test.c", 33);
{
  struct Rectangle rectangle = Rectangle_New(1.0, 1.0);
  (Rectangle_IsSquare(rectangle)) ? _mark_point("rectangle_test.c", 36) : _ck_assert_failed("rectangle_test.c", 36, "Assertion '""Rectangle_IsSquare(rectangle)""' failed" , ((void *)0), ((void *)0));
}
}

user_defined_types: struct Rectangle { double width; double height; }


decompiled_code:
__int64 test_perimeter_with_width_2_height_3_is_10()
{
tcase_fn_start("test_perimeter_with_width_2_height_3_is_10", "rectangle_test.c", 26LL);
Rectangle_New(2.0, 3.0);
if ( Rectangle_Perimeter() == 10.0 )
return mark_point("rectangle_test.c", 29LL);
ck_assert_failed("rectangle_test.c", 29LL, "Assertion 'Rectangle_Perimeter(rectangle) == 10.0' failed", 0LL, 0LL);
return test_perimeter_with_width_1_height_1_is_1();
}

canonical_decompiled_code:
__int64 func2()
{
tcase_fn_start("test_perimeter_with_width_2_height_3_is_10", "rectangle_test.c", 26LL);
Rectangle_New(2.0, 3.0);
if ( Rectangle_Perimeter() == 10.0 )
return mark_point("rectangle_test.c", 29LL);
ck_assert_failed("rectangle_test.c", 29LL, "Assertion 'Rectangle_Perimeter(rectangle) == 10.0' failed", 0LL, 0LL);
return func3();
}

original_code:
static void test_perimeter_with_width_2_height_3_is_10 (int _i __attribute__ ((unused))){ tcase_fn_start ("""test_perimeter_with_width_2_height_3_is_10", "rectangle_test.c", 26);
{
  Rectangle rectangle = Rectangle_New(2.0, 3.0);
  (Rectangle_Perimeter(rectangle) == 10.0) ? _mark_point("rectangle_test.c", 29) : _ck_assert_failed("rectangle_test.c", 29, "Assertion '""Rectangle_Perimeter(rectangle) == 10.0""' failed" , ((void *)0), ((void *)0));
}
}

canonical_original_code:
static void test_perimeter_with_width_2_height_3_is_10(int _i){ tcase_fn_start ("""test_perimeter_with_width_2_height_3_is_10", "rectangle_test.c", 26);
{
  struct Rectangle rectangle = Rectangle_New(2.0, 3.0);
  (Rectangle_Perimeter(rectangle) == 10.0) ? _mark_point("rectangle_test.c", 29) : _ck_assert_failed("rectangle_test.c", 29, "Assertion '""Rectangle_Perimeter(rectangle) == 10.0""' failed" , ((void *)0), ((void *)0));
}
}


decompiled_code:
__int64 test_perimeter_with_width_1_height_1_is_1()
{
tcase_fn_start("test_perimeter_with_width_1_height_1_is_1", "rectangle_test.c", 19LL);
Rectangle_New(1.0, 1.0);
if ( Rectangle_Perimeter() == 4.0 )
return mark_point("rectangle_test.c", 22LL);
ck_assert_failed("rectangle_test.c", 22LL, "Assertion 'Rectangle_Perimeter(rectangle) == 4.0' failed", 0LL, 0LL);
return test_area_with_width_2_height_3_is_6();
}

canonical_decompiled_code:
__int64 func3()
{
tcase_fn_start("test_perimeter_with_width_1_height_1_is_1", "rectangle_test.c", 19LL);
Rectangle_New(1.0, 1.0);
if ( Rectangle_Perimeter() == 4.0 )
return mark_point("rectangle_test.c", 22LL);
ck_assert_failed("rectangle_test.c", 22LL, "Assertion 'Rectangle_Perimeter(rectangle) == 4.0' failed", 0LL, 0LL);
return func4();
}

original_code:
static void test_perimeter_with_width_1_height_1_is_1 (int _i __attribute__ ((unused))){ tcase_fn_start ("""test_perimeter_with_width_1_height_1_is_1", "rectangle_test.c", 19);
{
  Rectangle rectangle = Rectangle_New(1.0, 1.0);
  (Rectangle_Perimeter(rectangle) == 4.0) ? _mark_point("rectangle_test.c", 22) : _ck_assert_failed("rectangle_test.c", 22, "Assertion '""Rectangle_Perimeter(rectangle) == 4.0""' failed" , ((void *)0), ((void *)0));
}
}

canonical_original_code:
static void test_perimeter_with_width_1_height_1_is_1(int _i){ tcase_fn_start ("""test_perimeter_with_width_1_height_1_is_1", "rectangle_test.c", 19);
{
  struct Rectangle rectangle = Rectangle_New(1.0, 1.0);
  (Rectangle_Perimeter(rectangle) == 4.0) ? _mark_point("rectangle_test.c", 22) : _ck_assert_failed("rectangle_test.c", 22, "Assertion '""Rectangle_Perimeter(rectangle) == 4.0""' failed" , ((void *)0), ((void *)0));
}
}


decompiled_code:
__int64 test_area_with_width_2_height_3_is_6()
{
tcase_fn_start("test_area_with_width_2_height_3_is_6", "rectangle_test.c", 12LL);
Rectangle_New(2.0, 3.0);
if ( Rectangle_Area() == 6.0 )
return mark_point("rectangle_test.c", 15LL);
ck_assert_failed("rectangle_test.c", 15LL, "Assertion 'Rectangle_Area(rectangle) == 6.0' failed", 0LL, 0LL);
return test_area_with_width_1_height_1_is_1();
}

canonical_decompiled_code:
__int64 func4()
{
tcase_fn_start("test_area_with_width_2_height_3_is_6", "rectangle_test.c", 12LL);
Rectangle_New(2.0, 3.0);
if ( Rectangle_Area() == 6.0 )
return mark_point("rectangle_test.c", 15LL);
ck_assert_failed("rectangle_test.c", 15LL, "Assertion 'Rectangle_Area(rectangle) == 6.0' failed", 0LL, 0LL);
return func5();
}

original_code:
static void test_area_with_width_2_height_3_is_6 (int _i __attribute__ ((unused))){ tcase_fn_start ("""test_area_with_width_2_height_3_is_6", "rectangle_test.c", 12);
{
  Rectangle rectangle = Rectangle_New(2.0, 3.0);
  (Rectangle_Area(rectangle) == 6.0) ? _mark_point("rectangle_test.c", 15) : _ck_assert_failed("rectangle_test.c", 15, "Assertion '""Rectangle_Area(rectangle) == 6.0""' failed" , ((void *)0), ((void *)0));
}
}

canonical_original_code:
static void test_area_with_width_2_height_3_is_6(int _i){ tcase_fn_start ("""test_area_with_width_2_height_3_is_6", "rectangle_test.c", 12);
{
  struct Rectangle rectangle = Rectangle_New(2.0, 3.0);
  (Rectangle_Area(rectangle) == 6.0) ? _mark_point("rectangle_test.c", 15) : _ck_assert_failed("rectangle_test.c", 15, "Assertion '""Rectangle_Area(rectangle) == 6.0""' failed" , ((void *)0), ((void *)0));
}
}


decompiled_code:
__int64 test_area_with_width_1_height_1_is_1()
{
double v0; // xmm0_8

tcase_fn_start("test_area_with_width_1_height_1_is_1", "rectangle_test.c", 5LL);
Rectangle_New(1.0, 1.0);
v0 = Rectangle_Area();
if ( v0 == 1.0 )
return mark_point("rectangle_test.c", 8LL);
ck_assert_failed("rectangle_test.c", 8LL, "Assertion 'Rectangle_Area(rectangle) == 1.0' failed", 0LL, 0LL);
return rectangle_suite(v0, 1.0, 1.0);
}

canonical_decompiled_code:
__int64 func5()
{
double v0; // xmm0_8

tcase_fn_start("test_area_with_width_1_height_1_is_1", "rectangle_test.c", 5LL);
Rectangle_New(1.0, 1.0);
v0 = Rectangle_Area();
if ( v0 == 1.0 )
return mark_point("rectangle_test.c", 8LL);
ck_assert_failed("rectangle_test.c", 8LL, "Assertion 'Rectangle_Area(rectangle) == 1.0' failed", 0LL, 0LL);
return func6(v0, 1.0, 1.0);
}

original_code:
static void test_area_with_width_1_height_1_is_1 (int _i __attribute__ ((unused))){ tcase_fn_start ("""test_area_with_width_1_height_1_is_1", "rectangle_test.c", 5);
{
  Rectangle rectangle = Rectangle_New(1.0, 1.0);
  (Rectangle_Area(rectangle) == 1.0) ? _mark_point("rectangle_test.c", 8) : _ck_assert_failed("rectangle_test.c", 8, "Assertion '""Rectangle_Area(rectangle) == 1.0""' failed" , ((void *)0), ((void *)0));
}
}

canonical_original_code:
static void test_area_with_width_1_height_1_is_1(int _i){ tcase_fn_start ("""test_area_with_width_1_height_1_is_1", "rectangle_test.c", 5);
{
  struct Rectangle rectangle = Rectangle_New(1.0, 1.0);
  (Rectangle_Area(rectangle) == 1.0) ? _mark_point("rectangle_test.c", 8) : _ck_assert_failed("rectangle_test.c", 8, "Assertion '""Rectangle_Area(rectangle) == 1.0""' failed" , ((void *)0), ((void *)0));
}
}


decompiled_code:
void Rectangle_New()
{
;
}

canonical_decompiled_code:
void func0()
{
;
}

original_code:
Rectangle Rectangle_New(double width, double height)
{
  Rectangle rectangle = {width, height};
  return rectangle;
}

canonical_original_code:
struct Rectangle Rectangle_New(double width, double height)
{
  struct Rectangle rectangle = {width, height};
  return rectangle;
}

variable_types: width double

variable_types: height double

return_type: struct Rectangle { double width; double height; }


decompiled_code:
double __fastcall Rectangle_Area(double a1, double a2)
{
return a1 * a2;
}

canonical_decompiled_code:
double __fastcall func1(double a1, double a2)
{
return a1 * a2;
}

original_code:
double Rectangle_Area(Rectangle self)
{
  return self.width * self.height;
}

canonical_original_code:
double Rectangle_Area(struct Rectangle self)
{
  return self.width * self.height;
}

return_type: double


decompiled_code:
double __fastcall Rectangle_Perimeter(double a1, double a2)
{
return a1 + a2 + a1 + a2;
}

canonical_decompiled_code:
double __fastcall func2(double a1, double a2)
{
return a1 + a2 + a1 + a2;
}

original_code:
double Rectangle_Perimeter(Rectangle self)
{
  return 2 * (self.width + self.height);
}

canonical_original_code:
double Rectangle_Perimeter(struct Rectangle self)
{
  return 2 * (self.width + self.height);
}


decompiled_code:
_BOOL8 __fastcall Rectangle_IsSquare(double a1, double a2)
{
return a1 == a2;
}

canonical_decompiled_code:
_BOOL8 __fastcall func3(double a1, double a2)
{
return a1 == a2;
}

original_code:
int Rectangle_IsSquare(Rectangle self)
{
  return (self.width == self.height);
}

canonical_original_code:
int Rectangle_IsSquare(struct Rectangle self)
{
  return (self.width == self.height);
}

return_type: int


main

canonical_name: main

repo: chindesaurus/credit-card-validation

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
void *v3; // rax
void *v4; // rbp

v3 = malloc(0x11uLL);
if ( !v3 )
__assert_fail("input != NULL", "credit.c", 0x26u, "main");
v4 = v3;
do
{
printf("Enter credit card number: ");
getInput(v4);
}
while ( !(unsigned __int8)isNumeric(v4, argv) );
if ( (unsigned __int8)luhn(v4) )
{
printf("valid ");
checkPrefix(v4);
}
else
{
puts("invalid");
}
free(v4);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
void *v3; // rax
void *v4; // rbp

v3 = malloc(0x11uLL);
if ( !v3 )
__assert_fail("input != NULL", "credit.c", 0x26u, "main");
v4 = v3;
do
{
printf("Enter credit card number: ");
func10(v4);
}
while ( !(unsigned __int8)func7(v4, argv) );
if ( (unsigned __int8)func9(v4) )
{
printf("valid ");
func11(v4);
}
else
{
puts("invalid");
}
free(v4);
return 0;
}

original_code:
int
main(int argc, char **argv) {
    char *input = malloc((16 + 1) * sizeof(*input));
    ((input != ((void *)0)) ? (void) (0) : __assert_fail ("input != NULL", "credit.c", 38, __extension__ __PRETTY_FUNCTION__));
    do {
        printf("Enter credit card number: ");
        getInput(input);
    } while (isNumeric(input) == 0);
    if (luhn(input) == 0)
        printf("invalid\n");
    else {
        printf("valid ");
        checkPrefix(input);
    }
    free(input);
    return 0;
}

variable_types: argc int

variable_types:
argv
char **

variable_types:
input
char *


isNumeric

decompiled_code:
__int64 __fastcall isNumeric(char *a1)
{
char *v1; // rbp
__int64 v2; // rbx
const unsigned __int16 *v3; // rax

if ( !a1 )
return 0LL;
v1 = a1;
v2 = *a1;
if ( !(_BYTE)v2 )
return 1LL;
v3 = *__ctype_b_loc();
while ( (v3[v2] & 0x800) != 0 )
{
v2 = *++v1;
if ( !(_BYTE)v2 )
return 1LL;
}
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func7(char *a1)
{
char *v1; // rbp
__int64 v2; // rbx
const unsigned __int16 *v3; // rax

if ( !a1 )
return 0LL;
v1 = a1;
v2 = *a1;
if ( !(_BYTE)v2 )
return 1LL;
v3 = *__ctype_b_loc();
while ( (v3[v2] & 0x800) != 0 )
{
v2 = *++v1;
if ( !(_BYTE)v2 )
return 1LL;
}
return 0LL;
}

original_code:
_Bool
isNumeric(char *s) {
    if (s == ((void *)0))
        return 0;
    while (*s != '\0') {
        if (! ((*__ctype_b_loc ())[(int) ((*s))] & (unsigned short int) _ISdigit))
            return 0;
        s++;
    }
    return 1;
}

canonical_original_code:
_Bool isNumeric(char *s) {
    if (s == ((void *)0))
        return 0;
    while (*s != '\0') {
        if (! ((*__ctype_b_loc ())[(int) ((*s))] & (unsigned short) _ISdigit))
            return 0;
        s++;
    }
    return 1;
}


addDigits

decompiled_code:
__int64 __fastcall addDigits(int a1)
{
return (unsigned int)(a1 % 10 + a1 / 10);
}

canonical_decompiled_code:
__int64 __fastcall func8(int a1)
{
return (unsigned int)(a1 % 10 + a1 / 10);
}

original_code:
int
addDigits(int n) {
    return (n / 10) + (n % 10);
}

variable_types: n int


luhn

original_code:
_Bool
luhn(char *s) {
    int sum = 0;
    int digit, i;
    int length = strlen(s);
    if (! (length >= 13 && length <= 16))
        return 0;
    if (length % 2 == 0) {
        for (i = 0; i < length; i++) {
            digit = s[i] - '0';
            if (i % 2 == 0)
                sum += addDigits(2 * digit);
            else
                sum += digit;
        }
    }
    else {
        for (i = 0; i < length; i++) {
            digit = s[i] - '0';
            if (i % 2 == 0)
                sum += digit;
            else
                sum += addDigits(2 * digit);
        }
    }
    return (sum % 10 == 0);
}

canonical_original_code:
_Bool luhn(char *s) {
    int sum = 0;
    int digit; int i;
    int length = strlen(s);
    if (! (length >= 13 && length <= 16))
        return 0;
    if (length % 2 == 0) {
        for (i = 0; i < length; i++) {
            digit = s[i] - '0';
            if (i % 2 == 0)
                sum += addDigits(2 * digit);
            else
                sum += digit;
        }
    }
    else {
        for (i = 0; i < length; i++) {
            digit = s[i] - '0';
            if (i % 2 == 0)
                sum += digit;
            else
                sum += addDigits(2 * digit);
        }
    }
    return (sum % 10 == 0);
}

variable_types: sum int

variable_types: digit int

variable_types: i int

variable_types: length int


getInput

decompiled_code:
int __fastcall getInput(void *ptr)
{
int v1; // er13
__int64 i; // rbp
int result; // eax
char v5; // bl

v1 = 17;
for ( i = 0LL; ; ++i )
{
result = fgetc(_bss_start);
v5 = result;
if ( result == -1 || result == 10 )
break;
if ( v1 <= (int)i )
{
v1 *= 2;
ptr = realloc(ptr, v1);
if ( !ptr )
__assert_fail("buffer != NULL", "credit.c", 0x8Du, "getInput");
}
*((_BYTE *)ptr + i) = v5;
}
*((_BYTE *)ptr + (int)i) = 0;
return result;
}

canonical_decompiled_code:
int __fastcall func10(void *ptr)
{
int v1; // er13
__int64 i; // rbp
int result; // eax
char v5; // bl

v1 = 17;
for ( i = 0LL; ; ++i )
{
result = fgetc(_bss_start);
v5 = result;
if ( result == -1 || result == 10 )
break;
if ( v1 <= (int)i )
{
v1 *= 2;
ptr = realloc(ptr, v1);
if ( !ptr )
__assert_fail("buffer != NULL", "credit.c", 0x8Du, "getInput");
}
*((_BYTE *)ptr + i) = v5;
}
*((_BYTE *)ptr + (int)i) = 0;
return result;
}

original_code:
void
getInput(char *buffer) {
    int length = 0;
    int capacity = 16 + 1;
    int c;
    while ( (c = fgetc(stdin)) != '\n' && c != (-1)) {
        if (length + 1 > capacity) {
            capacity *= 2;
            buffer = realloc(buffer, capacity * sizeof(*buffer));
            ((buffer != ((void *)0)) ? (void) (0) : __assert_fail ("buffer != NULL", "credit.c", 141, __extension__ __PRETTY_FUNCTION__));
        }
        buffer[length++] = c;
    }
    buffer[length] = '\0';
}

variable_types:
buffer
char *

variable_types: capacity int

variable_types: c int


checkPrefix

decompiled_code:
int __fastcall checkPrefix(__int64 a1)
{
int v1; // eax
char v3; // dl
char v4; // al

v1 = strlen((const char *)a1);
if ( v1 != 13 && v1 != 16 )
{
LABEL_3:
if ( v1 == 15 && *(_BYTE *)a1 == 51 )
{
v4 = *(_BYTE *)(a1 + 1);
if ( v4 == 52 || v4 == 55 )
return puts("American Express");
}
return puts("\nThis number is syntactically valid, but it is not a Visa, Mastercard, Discover, or American Express.");
}
v3 = *(_BYTE *)a1;
if ( *(_BYTE *)a1 == 52 )
return puts("Visa");
if ( v1 != 16 )
goto LABEL_3;
if ( v3 != 53 )
{
if ( v3 == 54 && *(_BYTE *)(a1 + 1) == 48 && *(_BYTE *)(a1 + 2) == 49 && *(_BYTE *)(a1 + 3) == 49 )
return puts("Discover");
return puts("\nThis number is syntactically valid, but it is not a Visa, Mastercard, Discover, or American Express.");
}
return puts("Mastercard");
}

canonical_decompiled_code:
int __fastcall func11(__int64 a1)
{
int v1; // eax
char v3; // dl
char v4; // al

v1 = strlen((const char *)a1);
if ( v1 != 13 && v1 != 16 )
{
LABEL_3:
if ( v1 == 15 && *(_BYTE *)a1 == 51 )
{
v4 = *(_BYTE *)(a1 + 1);
if ( v4 == 52 || v4 == 55 )
return puts("American Express");
}
return puts("\nThis number is syntactically valid, but it is not a Visa, Mastercard, Discover, or American Express.");
}
v3 = *(_BYTE *)a1;
if ( *(_BYTE *)a1 == 52 )
return puts("Visa");
if ( v1 != 16 )
goto LABEL_3;
if ( v3 != 53 )
{
if ( v3 == 54 && *(_BYTE *)(a1 + 1) == 48 && *(_BYTE *)(a1 + 2) == 49 && *(_BYTE *)(a1 + 3) == 49 )
return puts("Discover");
return puts("\nThis number is syntactically valid, but it is not a Visa, Mastercard, Discover, or American Express.");
}
return puts("Mastercard");
}

original_code:
void
checkPrefix(char *s) {
    int length = strlen(s);
    if ((length == 13 || length == 16) && s[0] == '4')
        printf("Visa\n");
    else if (length == 16 && s[0] == '5')
        printf("Mastercard\n");
    else if (length == 16 && s[0] == '6' && s[1] == '0' && s[2] == '1' && s[3] == '1')
        printf("Discover\n");
    else if (length == 15 && s[0] == '3' && (s[1] == '4' || s[1] == '7'))
        printf("American Express\n");
    else
        printf("\nThis number is syntactically valid, but it is not a Visa, Mastercard, Discover, or American Express.\n");
}

variable_types:
s
char *


main

repo: chindesaurus/ghost

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // er14
int v4; // er13
unsigned int v5; // er12
const unsigned __int16 **v6; // rax
_BYTE *v7; // rbp
const unsigned __int16 **v8; // rbx
const __int32_t **v9; // r15
__int32_t v10; // edx
__int64 v11; // rax
char v12; // r8
int result; // eax
char v14; // [rsp+Fh] [rbp-69h]
__int128 v15; // [rsp+10h] [rbp-68h] BYREF
char v16[29]; // [rsp+20h] [rbp-58h] BYREF

greet(argc, argv, envp);
if ( argc == 2 )
{
v3 = atoi(argv[1]);
if ( v3 <= 1 )
{
fwrite("Invalid argument. N must be an integer >= 2.\n", 1uLL, 0x2DuLL, stderr);
result = 2;
}
else if ( (unsigned __int8)load("./words.txt") )
{
memset(v16, 0, sizeof(v16));
v15 = 0LL;
v4 = 0;
v5 = 1;
v6 = __ctype_b_loc();
v7 = root;
v8 = v6;
v9 = __ctype_tolower_loc();
while ( 1 )
{
while ( 1 )
{
printf("\nCurrent word fragment: %s\n", (const char *)&v15);
do
{
printf("Player %i says letter: ", v5);
__isoc99_scanf();
__isoc99_scanf();
}
while ( ((*v8)[v14] & 0x400) == 0 );
v10 = (*v9)[v14];
v14 = v10;
v11 = (char)v10 - 97;
if ( *(_QWORD *)&v7[8 * v11 + 8] )
break;
printf("There's no word that begins with \"%s%c\".\n", (const char *)&v15, (unsigned int)(char)v10);
puts("Try again.");
}
*((_BYTE *)&v15 + v4) = v10;
v7 = *(_BYTE **)&v7[8 * v11 + 8];
if ( *v7 )
{
if ( v4 > 2 )
break;
}
++v4;
v5 = (int)v5 % v3 + 1;
}
printf("\nPlayer %i loses!\n", v5);
printf("He/She spelled the word \"%s\".\n", (const char *)&v15);
puts("Thanks for playing!\n");
v12 = unload(0.0);
result = 0;
if ( !v12 )
{
fprintf(stderr, "Could not unload %s.\n", "./words.txt");
result = 4;
}
}
else
{
fprintf(stderr, "Could not load %s.\n", "./words.txt");
result = 3;
}
}
else
{
fwrite("Usage: ghost N\nwhere N is the number of players.\n", 1uLL, 0x31uLL, stderr);
result = 1;
}
return result;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // er14
int v4; // er13
unsigned int v5; // er12
const unsigned __int16 **v6; // rax
_BYTE *v7; // rbp
const unsigned __int16 **v8; // rbx
const __int32_t **v9; // r15
__int32_t v10; // edx
__int64 v11; // rax
char v12; // r8
int result; // eax
char v14; // [rsp+Fh] [rbp-69h]
__int128 v15; // [rsp+10h] [rbp-68h] BYREF
char v16[29]; // [rsp+20h] [rbp-58h] BYREF

func8(argc, argv, envp);
if ( argc == 2 )
{
v3 = atoi(argv[1]);
if ( v3 <= 1 )
{
fwrite("Invalid argument. N must be an integer >= 2.\n", 1uLL, 0x2DuLL, stderr);
result = 2;
}
else if ( (unsigned __int8)func9("./words.txt") )
{
memset(v16, 0, sizeof(v16));
v15 = 0LL;
v4 = 0;
v5 = 1;
v6 = __ctype_b_loc();
v7 = root;
v8 = v6;
v9 = __ctype_tolower_loc();
while ( 1 )
{
while ( 1 )
{
printf("\nCurrent word fragment: %s\n", (const char *)&v15);
do
{
printf("Player %i says letter: ", v5);
__isoc99_scanf();
__isoc99_scanf();
}
while ( ((*v8)[v14] & 0x400) == 0 );
v10 = (*v9)[v14];
v14 = v10;
v11 = (char)v10 - 97;
if ( *(_QWORD *)&v7[8 * v11 + 8] )
break;
printf("There's no word that begins with \"%s%c\".\n", (const char *)&v15, (unsigned int)(char)v10);
puts("Try again.");
}
*((_BYTE *)&v15 + v4) = v10;
v7 = *(_BYTE **)&v7[8 * v11 + 8];
if ( *v7 )
{
if ( v4 > 2 )
break;
}
++v4;
v5 = (int)v5 % v3 + 1;
}
printf("\nPlayer %i loses!\n", v5);
printf("He/She spelled the word \"%s\".\n", (const char *)&v15);
puts("Thanks for playing!\n");
v12 = func11(0.0);
result = 0;
if ( !v12 )
{
fprintf(stderr, "Could not unload %s.\n", "./words.txt");
result = 4;
}
}
else
{
fprintf(stderr, "Could not load %s.\n", "./words.txt");
result = 3;
}
}
else
{
fwrite("Usage: ghost N\nwhere N is the number of players.\n", 1uLL, 0x31uLL, stderr);
result = 1;
}
return result;
}

original_code:
int
main(int argc, char **argv) {
    greet();
    if (argc != 2) {
        fprintf(stderr, "Usage: ghost N\nwhere N is the number of players.\n");
        return 1;
    }
    int N = atoi(argv[1]);
    if (N < 2) {
        fprintf(stderr, "Invalid argument. N must be an integer >= 2.\n");
        return 2;
    }
    _Bool loaded = load("./words.txt");
    if (!loaded) {
        fprintf(stderr, "Could not load %s.\n", "./words.txt");
        return 3;
    }
    int curr_player = 1;
    int letter_count = 0;
    char fragment[45] = "";
    char c;
    node *letter = root;
    while (1) {
        printf("\nCurrent word fragment: %s\n", fragment);
        do {
            printf("Player %i says letter: ", curr_player);
            scanf(" %c", &c);
            scanf("%*[^\n]%*c");
        } while (!((*__ctype_b_loc ())[(int) ((c))] & (unsigned short int) _ISalpha));
        c = tolower(c);
        int index = c - 'a';
        if (letter->children[index] == ((void *)0)) {
            printf("There's no word that begins with \"%s%c\".\n", fragment, c);
            printf("Try again.\n");
            continue;
        }
        else {
            fragment[letter_count] = c;
            letter = letter->children[index];
            if (letter->is_word && letter_count >= 3)
                break;
            curr_player = (curr_player % N) + 1;
            letter_count += 1;
        }
    }
    printf("\nPlayer %i loses!\n", curr_player);
    printf("He/She spelled the word \"%s\".\n", fragment);
    printf("Thanks for playing!\n\n");
    _Bool unloaded = unload();
    if (!unloaded) {
        fprintf(stderr, "Could not unload %s.\n", "./words.txt");
        return 4;
    }
    return 0;
}

canonical_original_code:
int main(int argc, char **argv) {
    greet();
    if (argc != 2) {
        fprintf(stderr, "Usage: ghost N\nwhere N is the number of players.\n");
        return 1;
    }
    int N = atoi(argv[1]);
    if (N < 2) {
        fprintf(stderr, "Invalid argument. N must be an integer >= 2.\n");
        return 2;
    }
    _Bool loaded = load("./words.txt");
    if (!loaded) {
        fprintf(stderr, "Could not load %s.\n", "./words.txt");
        return 3;
    }
    int curr_player = 1;
    int letter_count = 0;
    char fragment[45] = "";
    char c;
    struct node *letter = root;
    while (1) {
        printf("\nCurrent word fragment: %s\n", fragment);
        do {
            printf("Player %i says letter: ", curr_player);
            scanf(" %c", &c);
            scanf("%*[^\n]%*c");
        } while (!((*__ctype_b_loc ())[(int) ((c))] & (unsigned short) _ISalpha));
        c = tolower(c);
        int index = c - 'a';
        if (letter->children[index] == ((void *)0)) {
            printf("There's no word that begins with \"%s%c\".\n", fragment, c);
            printf("Try again.\n");
            continue;
        }
        else {
            fragment[letter_count] = c;
            letter = letter->children[index];
            if (letter->is_word && letter_count >= 3)
                break;
            curr_player = (curr_player % N) + 1;
            letter_count += 1;
        }
    }
    printf("\nPlayer %i loses!\n", curr_player);
    printf("He/She spelled the word \"%s\".\n", fragment);
    printf("Thanks for playing!\n\n");
    _Bool unloaded = unload();
    if (!unloaded) {
        fprintf(stderr, "Could not unload %s.\n", "./words.txt");
        return 4;
    }
    return 0;
}

variable_types: N int

variable_types:
fragment
char [45]

variable_types: c char

variable_types: struct node { _Bool is_word; struct node *children[26]; } *

variable_types: index int


clear

decompiled_code:
int clear()
{
printf("\x1B[2J");
return printf("\x1B[%d;%dH", 0LL, 0LL);
}

canonical_decompiled_code:
int func7()
{
printf("\x1B[2J");
return printf("\x1B[%d;%dH", 0LL, 0LL);
}


freeNode

original_code:
void
freeNode(node *curr) {
    if (curr == ((void *)0))
        return;
    for (int i = 0; i < 26; i++) {
        if (curr->children[i] != ((void *)0))
            freeNode(curr->children[i]);
        free(curr->children[i]);
    }
}

canonical_original_code:
void freeNode(struct node *curr) {
    if (curr == ((void *)0))
        return;
    for (int i = 0; i < 26; i++) {
        if (curr->children[i] != ((void *)0))
            freeNode(curr->children[i]);
        free(curr->children[i]);
    }
}

user_defined_types: struct node { _Bool is_word; struct node *children[26]; }


unload

decompiled_code:
__int64 unload()
{
freeNode((__int64)root);
free(root);
return 1LL;
}

canonical_decompiled_code:
__int64 func11()
{
func10((__int64)root);
free(root);
return 1LL;
}

original_code:
_Bool
unload(void) {
    freeNode(root);
    free(root);
    return 1;
}

canonical_original_code:
_Bool unload() {
    freeNode(root);
    free(root);
    return 1;
}


parent

repo: chitr/SimpleHeapLib

decompiled_code:
unsigned __int64 __fastcall parent(__int64 a1)
{
return (unsigned __int64)(a1 - 1) >> 1;
}

canonical_decompiled_code:
unsigned __int64 __fastcall func6(__int64 a1)
{
return (unsigned __int64)(a1 - 1) >> 1;
}

original_code:
uint64_t parent(uint64_t heap_list_index){
 return (heap_list_index - 1) >> 1;
}

canonical_original_code:
unsigned long parent(unsigned long heap_list_index){
 return (heap_list_index - 1) >> 1;
}

return_type: unsigned long


lchild

decompiled_code:
__int64 __fastcall lchild(__int64 a1)
{
return 2 * a1 + 1;
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1)
{
return 2 * a1 + 1;
}

original_code:
uint64_t lchild(uint64_t heap_list_index){
 return (heap_list_index << 1) + 1;
}

canonical_original_code:
unsigned long lchild(unsigned long heap_list_index){
 return (heap_list_index << 1) + 1;
}


rchild

decompiled_code:
__int64 __fastcall rchild(__int64 a1)
{
return 2 * a1 + 2;
}

canonical_decompiled_code:
__int64 __fastcall func8(__int64 a1)
{
return 2 * a1 + 2;
}

original_code:
uint64_t rchild(uint64_t heap_list_index){
 return (heap_list_index << 1) + 2;
}

canonical_original_code:
unsigned long rchild(unsigned long heap_list_index){
 return (heap_list_index << 1) + 2;
}


buildBinHeap

decompiled_code:
__int64 __fastcall buildBinHeap(__int64 a1, unsigned __int64 a2)
{
void *v2; // rax
__int64 result; // rax

if ( !a1 )
return 4LL;
v2 = realloc(*(void **)a1, 20 * a2);
if ( !v2 )
return 7LL;
*(_QWORD *)a1 = v2;
result = 0LL;
*(_QWORD *)(a1 + 8) = a2;
if ( *(_QWORD *)(a1 + 16) > a2 )
*(_QWORD *)(a1 + 16) = a2;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func9(__int64 a1, unsigned __int64 a2)
{
void *v2; // rax
__int64 result; // rax

if ( !a1 )
return 4LL;
v2 = realloc(*(void **)a1, 20 * a2);
if ( !v2 )
return 7LL;
*(_QWORD *)a1 = v2;
result = 0LL;
*(_QWORD *)(a1 + 8) = a2;
if ( *(_QWORD *)(a1 + 16) > a2 )
*(_QWORD *)(a1 + 16) = a2;
return result;
}

original_code:
H_return_t
buildBinHeap(Binary_Heap_t *p_heap,uint64_t heap_size){
    H_return_t ret=H_SUCCESS;
    if(!p_heap ) {
        ret = H_INPUT_ERROR;
        goto end;
    }
    Binary_HeapNode_t *p_resize_heap_list=((void *)0);
    if(!(p_resize_heap_list = realloc(p_heap->heap_list,
                    sizeof(Binary_HeapNode_t) * heap_size))) {
        ret = H_MEM_ERROR;
        goto end;
    }
    p_heap->heap_list=p_resize_heap_list;
    p_heap->maxSize = heap_size;
    if(p_heap->currSize >p_heap->maxSize)
        p_heap->currSize = p_heap->maxSize;
end:
    return ret;
}

canonical_original_code:
enum H_return buildBinHeap(struct Binary_Heap_t__ *p_heap, unsigned long heap_size){
    enum H_return ret = H_SUCCESS;
    if(!p_heap ) {
        ret = H_INPUT_ERROR;
        goto end;
    }
    struct Binary_HeapNode_t__ *p_resize_heap_list = ((void *)0);
    if(!(p_resize_heap_list = realloc(p_heap->heap_list,
                    sizeof(Binary_HeapNode_t) * heap_size))) {
        ret = H_MEM_ERROR;
        goto end;
    }
    p_heap->heap_list=p_resize_heap_list;
    p_heap->maxSize = heap_size;
    if(p_heap->currSize >p_heap->maxSize)
        p_heap->currSize = p_heap->maxSize;
end:
    return ret;
}

variable_types: struct Binary_Heap_t__ { struct Binary_HeapNode_t__ { unsigned long key; unsigned int data_tracer; void *heapdata; } *heap_list; unsigned long maxSize; unsigned long currSize; unsigned long append_size; enum Heap_type { H_MAX=0, H_MIN=1 } type; union pthread_mutex_t { struct __pthread_mutex_s { int __lock; unsigned int __count; int __owner; unsigned int __nusers; int __kind; short __spins; short __elision; struct __pthread_internal_list { struct __pthread_internal_list *__prev; struct __pthread_internal_list *__next; } __list; } __data; char __size[40]; long __align; } heap_list_lock; int (*compare)(void *, void *); int (*release)(void *); } *

variable_types: enum H_return { H_SUCCESS=0, H_ERROR=1, H_EMPTY=2, H_FULL=3, H_INPUT_ERROR=4, H_NOTFOUND=5, H_EXISTS=6, H_MEM_ERROR=7, H_RESIZE=8 }

user_defined_types: struct Binary_Heap_t__ { struct Binary_HeapNode_t__ *heap_list; unsigned long maxSize; unsigned long currSize; unsigned long append_size; enum Heap_type type; union pthread_mutex_t heap_list_lock; int (*compare)(void *, void *); int (*release)(void *); }

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

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


deleteBinHeap

decompiled_code:
__int64 __fastcall deleteBinHeap(void **a1)
{
void *v1; // rdi

if ( !a1 )
return 4LL;
v1 = *a1;
if ( v1 )
free(v1);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func10(void **a1)
{
void *v1; // rdi

if ( !a1 )
return 4LL;
v1 = *a1;
if ( v1 )
free(v1);
return 0LL;
}

original_code:
H_return_t
deleteBinHeap(Binary_Heap_t* p_heap){
    H_return_t ret=H_SUCCESS;
    if(!p_heap ) {
        ret = H_INPUT_ERROR;
        goto end;
    }
    if (p_heap->heap_list != ((void *)0))
        free(p_heap->heap_list);
end:
    return ret;
}

canonical_original_code:
enum H_return deleteBinHeap(struct Binary_Heap_t__ *p_heap){
    enum H_return ret = H_SUCCESS;
    if(!p_heap ) {
        ret = H_INPUT_ERROR;
        goto end;
    }
    if (p_heap->heap_list != ((void *)0))
        free(p_heap->heap_list);
end:
    return ret;
}

return_type: enum H_return { H_SUCCESS=0, H_ERROR=1, H_EMPTY=2, H_FULL=3, H_INPUT_ERROR=4, H_NOTFOUND=5, H_EXISTS=6, H_MEM_ERROR=7, H_RESIZE=8 }

user_defined_types: struct Binary_HeapNode_t__ { unsigned long key; unsigned int data_tracer; void *heapdata; }

user_defined_types: struct __pthread_internal_list { struct __pthread_internal_list *__prev; struct __pthread_internal_list *__next; }


elementCount

decompiled_code:
__int64 __fastcall elementCount(__int64 a1)
{
return *(_QWORD *)(a1 + 16);
}

canonical_decompiled_code:
__int64 __fastcall func11(__int64 a1)
{
return *(_QWORD *)(a1 + 16);
}

original_code:
uint64_t
elementCount( Binary_Heap_t* p_heap) {
    return p_heap->currSize;
}

canonical_original_code:
unsigned long elementCount(struct Binary_Heap_t__ *p_heap) {
    return p_heap->currSize;
}


swap

original_code:
H_return_t
swap(Binary_Heap_t* p_heap, uint64_t heap_list_index1 , uint64_t heap_list_index2){
    H_return_t ret=H_SUCCESS;
    if(!p_heap ) {
        ret = H_INPUT_ERROR;
        goto end;
    }
    if(heap_list_index1==heap_list_index2)
        goto end;
    Binary_HeapNode_t temp = p_heap->heap_list[heap_list_index1];
    p_heap->heap_list[heap_list_index1] = p_heap->heap_list[heap_list_index2];
    p_heap->heap_list[heap_list_index2] = temp;
end:
    return ret;
}

canonical_original_code:
enum H_return swap(struct Binary_Heap_t__ *p_heap, unsigned long heap_list_index1, unsigned long heap_list_index2){
    enum H_return ret = H_SUCCESS;
    if(!p_heap ) {
        ret = H_INPUT_ERROR;
        goto end;
    }
    if(heap_list_index1==heap_list_index2)
        goto end;
    struct Binary_HeapNode_t__ temp = p_heap->heap_list[heap_list_index1];
    p_heap->heap_list[heap_list_index1] = p_heap->heap_list[heap_list_index2];
    p_heap->heap_list[heap_list_index2] = temp;
end:
    return ret;
}

variable_types: struct Binary_HeapNode_t__ { unsigned long key; unsigned int data_tracer; void *heapdata; }

user_defined_types: enum H_return { H_SUCCESS=0, H_ERROR=1, H_EMPTY=2, H_FULL=3, H_INPUT_ERROR=4, H_NOTFOUND=5, H_EXISTS=6, H_MEM_ERROR=7, H_RESIZE=8 }


moveUp

original_code:
H_return_t
moveUp(Binary_Heap_t* p_heap, uint64_t heap_list_index){
    H_return_t ret=H_SUCCESS;
    if(!p_heap ) {
        ret = H_INPUT_ERROR;
        goto end;
    }
    Heap_type_t heap_type = p_heap->type;
    while((heap_list_index > 0)
            &&((H_MIN==heap_type)?
                (p_heap->heap_list[parent(heap_list_index)].key
                 > p_heap->heap_list[heap_list_index].key):
                (p_heap->heap_list[parent(heap_list_index)].key
                 < p_heap->heap_list[heap_list_index].key)
              )){
        swap(p_heap, parent(heap_list_index), heap_list_index);
        heap_list_index = parent(heap_list_index);
    }
end:
    return ret;
}

canonical_original_code:
enum H_return moveUp(struct Binary_Heap_t__ *p_heap, unsigned long heap_list_index){
    enum H_return ret = H_SUCCESS;
    if(!p_heap ) {
        ret = H_INPUT_ERROR;
        goto end;
    }
    enum Heap_type heap_type = p_heap->type;
    while((heap_list_index > 0)
            &&((H_MIN==heap_type)?
                (p_heap->heap_list[parent(heap_list_index)].key
                 > p_heap->heap_list[heap_list_index].key):
                (p_heap->heap_list[parent(heap_list_index)].key
                 < p_heap->heap_list[heap_list_index].key)
              )){
        swap(p_heap, parent(heap_list_index), heap_list_index);
        heap_list_index = parent(heap_list_index);
    }
end:
    return ret;
}


moveDown

original_code:
H_return_t
moveDown(Binary_Heap_t* p_heap, uint64_t heap_list_index) {
    H_return_t ret=H_SUCCESS;
    if(!p_heap ) {
        ret = H_INPUT_ERROR;
        goto end;
    }
    Heap_type_t heap_type = p_heap->type;
    uint64_t left ,right , lkey ,rkey;
    uint64_t next_heap_list_index =0, next_key;
    int do_loop = 1;
    if(heap_list_index == p_heap->currSize -1 )
        goto end;
    while ( do_loop ) {
        left = lchild(heap_list_index);
        right = rchild(heap_list_index);
        lkey = left < p_heap->currSize ? p_heap->heap_list[left].key :
            ((H_MIN==heap_type)? (18446744073709551615UL) : 0) ;
        rkey = right < p_heap->currSize ? p_heap->heap_list[right].key :
            ((H_MIN==heap_type)? (18446744073709551615UL) : 0);
        next_heap_list_index = (H_MIN==heap_type)?
            ((lkey < rkey) ? left : right):
            ((lkey > rkey) ? left : right);
        next_key = (H_MIN==heap_type)?
            ((lkey < rkey) ? lkey : rkey):
            ((lkey > rkey) ? lkey : rkey);
        if (((H_MIN==heap_type)?
                    (p_heap->heap_list[heap_list_index].key > next_key):
                    (p_heap->heap_list[heap_list_index].key < next_key))) {
            swap(p_heap, heap_list_index, next_heap_list_index);
            heap_list_index = next_heap_list_index;
        } else {
            break;
        }
    }
end:
    return ret;
}

canonical_original_code:
enum H_return moveDown(struct Binary_Heap_t__ *p_heap, unsigned long heap_list_index) {
    enum H_return ret = H_SUCCESS;
    if(!p_heap ) {
        ret = H_INPUT_ERROR;
        goto end;
    }
    enum Heap_type heap_type = p_heap->type;
    unsigned long left; unsigned long right; unsigned long lkey; unsigned long rkey;
    unsigned long next_heap_list_index = 0; unsigned long next_key;
    int do_loop = 1;
    if(heap_list_index == p_heap->currSize -1 )
        goto end;
    while ( do_loop ) {
        left = lchild(heap_list_index);
        right = rchild(heap_list_index);
        lkey = left < p_heap->currSize ? p_heap->heap_list[left].key :
            ((H_MIN==heap_type)? (18446744073709551615UL) : 0) ;
        rkey = right < p_heap->currSize ? p_heap->heap_list[right].key :
            ((H_MIN==heap_type)? (18446744073709551615UL) : 0);
        next_heap_list_index = (H_MIN==heap_type)?
            ((lkey < rkey) ? left : right):
            ((lkey > rkey) ? left : right);
        next_key = (H_MIN==heap_type)?
            ((lkey < rkey) ? lkey : rkey):
            ((lkey > rkey) ? lkey : rkey);
        if (((H_MIN==heap_type)?
                    (p_heap->heap_list[heap_list_index].key > next_key):
                    (p_heap->heap_list[heap_list_index].key < next_key))) {
            swap(p_heap, heap_list_index, next_heap_list_index);
            heap_list_index = next_heap_list_index;
        } else {
            break;
        }
    }
end:
    return ret;
}

variable_types:
left
unsigned long

variable_types:
right
unsigned long

variable_types:
lkey
unsigned long

variable_types:
rkey
unsigned long


getRoot

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

if ( !a1 || !a2 )
return 4LL;
result = 2LL;
if ( *(_QWORD *)(a1 + 16) )
{
v3 = *(_QWORD *)(*(_QWORD *)a1 + 12LL);
*a2 = **(_QWORD **)a1;
*(_QWORD *)((char *)a2 + 12) = v3;
result = 0LL;
}
return result;
}

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

if ( !a1 || !a2 )
return 4LL;
result = 2LL;
if ( *(_QWORD *)(a1 + 16) )
{
v3 = *(_QWORD *)(*(_QWORD *)a1 + 12LL);
*a2 = **(_QWORD **)a1;
*(_QWORD *)((char *)a2 + 12) = v3;
result = 0LL;
}
return result;
}

original_code:
H_return_t
getRoot( Binary_Heap_t* p_heap,Binary_HeapNode_t *p_root_node ){
    H_return_t ret=H_SUCCESS;
    if(!p_heap || !p_root_node) {
        ret = H_INPUT_ERROR;
        goto end;
    }
    if (p_heap->currSize == 0){
        ret = H_EMPTY;
        goto end;
    }
    p_root_node->key = p_heap->heap_list[0].key;
    p_root_node->heapdata = p_heap->heap_list[0].heapdata;
end:
    return ret;
}

canonical_original_code:
enum H_return getRoot(struct Binary_Heap_t__ *p_heap, struct Binary_HeapNode_t__ *p_root_node){
    enum H_return ret = H_SUCCESS;
    if(!p_heap || !p_root_node) {
        ret = H_INPUT_ERROR;
        goto end;
    }
    if (p_heap->currSize == 0){
        ret = H_EMPTY;
        goto end;
    }
    p_root_node->key = p_heap->heap_list[0].key;
    p_root_node->heapdata = p_heap->heap_list[0].heapdata;
end:
    return ret;
}


delRoot

original_code:
H_return_t
delRoot(Binary_Heap_t* p_heap ,Binary_HeapNode_t *p_root_node ) {
    H_return_t ret=H_SUCCESS;
    if(!p_heap || !p_root_node) {
        ret = H_INPUT_ERROR;
        goto end;
    }
    if (p_heap->currSize == 0){
        ret = H_EMPTY;
        goto end;
    }
    p_root_node->key = p_heap->heap_list[0].key;
    p_root_node->heapdata = p_heap->heap_list[0].heapdata;
    if(p_heap->currSize > 1 )
        swap(p_heap, 0, p_heap->currSize - 1);
    --(p_heap->currSize);
    ret = moveDown(p_heap, 0);
end:
    return ret;
}

canonical_original_code:
enum H_return delRoot(struct Binary_Heap_t__ *p_heap, struct Binary_HeapNode_t__ *p_root_node) {
    enum H_return ret = H_SUCCESS;
    if(!p_heap || !p_root_node) {
        ret = H_INPUT_ERROR;
        goto end;
    }
    if (p_heap->currSize == 0){
        ret = H_EMPTY;
        goto end;
    }
    p_root_node->key = p_heap->heap_list[0].key;
    p_root_node->heapdata = p_heap->heap_list[0].heapdata;
    if(p_heap->currSize > 1 )
        swap(p_heap, 0, p_heap->currSize - 1);
    --(p_heap->currSize);
    ret = moveDown(p_heap, 0);
end:
    return ret;
}


original_code:
H_return_t
lookup_data_in_heap(Binary_Heap_t* p_heap ,Binary_HeapNode_t *p_lookup_node,
        uint64_t *p_index ){
    H_return_t ret=H_SUCCESS;
    if(!p_heap || !p_lookup_node) {
        ret = H_INPUT_ERROR;
        goto end;
    }
    if (p_heap->currSize == 0){
        ret = H_EMPTY;
        goto end;
    }
    register int64_t array_index = p_heap->currSize - 1;
    for(; array_index >= 0; array_index--){
        if(p_lookup_node->data_tracer == p_heap->heap_list[array_index].data_tracer) {
            if (!p_heap->compare(p_lookup_node->heapdata,
                        p_heap->heap_list[array_index].heapdata)) {
                if(p_index)
                    *p_index = array_index;
                goto end;
            }
        }
        if(array_index && (!(array_index % 300)))
            usleep(1);
    }
    ret = H_NOTFOUND;
end:
    return ret;
}

canonical_original_code:
enum H_return lookup_data_in_heap(struct Binary_Heap_t__ *p_heap, struct Binary_HeapNode_t__ *p_lookup_node, unsigned long *p_index){
    enum H_return ret = H_SUCCESS;
    if(!p_heap || !p_lookup_node) {
        ret = H_INPUT_ERROR;
        goto end;
    }
    if (p_heap->currSize == 0){
        ret = H_EMPTY;
        goto end;
    }
    register long array_index = p_heap->currSize - 1;
    for(; array_index >= 0; array_index--){
        if(p_lookup_node->data_tracer == p_heap->heap_list[array_index].data_tracer) {
            if (!p_heap->compare(p_lookup_node->heapdata,
                        p_heap->heap_list[array_index].heapdata)) {
                if(p_index)
                    *p_index = array_index;
                goto end;
            }
        }
        if(array_index && (!(array_index % 300)))
            usleep(1);
    }
    ret = H_NOTFOUND;
end:
    return ret;
}


delNode

original_code:
H_return_t
delNode(Binary_Heap_t* p_heap ,Binary_HeapNode_t *p_del_node){
    H_return_t ret=H_SUCCESS;
    if(!p_heap || !p_del_node) {
        ret = H_INPUT_ERROR;
        goto end;
    }
    if (p_heap->currSize == 0){
        ret = H_EMPTY;
        goto end;
    }
    uint64_t index = 0;
    if(ret = lookup_data_in_heap( p_heap , p_del_node,&index )){
        goto end;
    }
    p_del_node->heapdata = p_heap->heap_list[index].heapdata;
    p_del_node->key = p_heap->heap_list[index].key;
 p_del_node->data_tracer = p_heap->heap_list[index].data_tracer;
    if((p_heap->currSize-index)>1)
        swap(p_heap, index , p_heap->currSize - 1);
    --(p_heap->currSize);
    ret = moveDown(p_heap, index);
end:
    return ret;
}

canonical_original_code:
enum H_return delNode(struct Binary_Heap_t__ *p_heap, struct Binary_HeapNode_t__ *p_del_node){
    enum H_return ret = H_SUCCESS;
    if(!p_heap || !p_del_node) {
        ret = H_INPUT_ERROR;
        goto end;
    }
    if (p_heap->currSize == 0){
        ret = H_EMPTY;
        goto end;
    }
    unsigned long index = 0;
    if(ret = lookup_data_in_heap( p_heap , p_del_node,&index )){
        goto end;
    }
    p_del_node->heapdata = p_heap->heap_list[index].heapdata;
    p_del_node->key = p_heap->heap_list[index].key;
 p_del_node->data_tracer = p_heap->heap_list[index].data_tracer;
    if((p_heap->currSize-index)>1)
        swap(p_heap, index , p_heap->currSize - 1);
    --(p_heap->currSize);
    ret = moveDown(p_heap, index);
end:
    return ret;
}

variable_types:
index
unsigned long


insertNode

original_code:
H_return_t
insertNode(Binary_Heap_t* p_heap ,Binary_HeapNode_t *p_in_node,int *p_is_lookup_req, int *p_overwrite) {
 H_return_t ret=H_SUCCESS;
    if(!p_in_node) {
        ret = H_INPUT_ERROR;
        goto end;
    }
    uint64_t len_to_resize = p_heap->maxSize+p_heap->append_size;
    uint64_t index = -1;
    int do_resize=0;
    if((p_heap->maxSize == 0) || (p_heap->currSize >= p_heap->maxSize)) {
        do_resize =1;
        len_to_resize = p_heap->maxSize+p_heap->append_size;
    }else if((p_heap->maxSize /
                ((p_heap->append_size > p_heap->currSize) ?
                 p_heap->append_size : p_heap->currSize)) > 100) {
        len_to_resize = p_heap->maxSize / 2;
        do_resize =1;
    }
    if ((do_resize )){
        if(ret = buildBinHeap(p_heap,len_to_resize))
            goto end;
    }
    if(1 == *p_is_lookup_req){
        if(H_SUCCESS == (lookup_data_in_heap(p_heap ,p_in_node,&index)) ) {
            if (!p_overwrite || !(*p_overwrite)) {
                ret= H_EXISTS;
                goto end;
            }
        }
    }
    if (index == -1) {
        if (p_overwrite)
            *p_overwrite = 0;
        p_heap->heap_list[p_heap->currSize].heapdata = p_in_node->heapdata;
        p_heap->heap_list[p_heap->currSize].key = p_in_node->key;
        p_heap->heap_list[p_heap->currSize].data_tracer = p_in_node->data_tracer;
        uint64_t heap_list_index = (p_heap->currSize)++;
        ret = moveUp(p_heap, heap_list_index);
    } else {
        int increased = (p_heap->heap_list[index].key < p_in_node->key);
        if (p_heap->release) {
            p_heap->release(&p_heap->heap_list[index]);
        }
        p_heap->heap_list[index].heapdata = p_in_node->heapdata;
        p_heap->heap_list[index].key = p_in_node->key;
        p_heap->heap_list[index].data_tracer = p_in_node->data_tracer;
        if ((p_heap->type == H_MIN && increased) ||
                (p_heap->type == H_MAX && !increased)) {
            ret = moveDown(p_heap, index);
        } else {
            ret = moveUp(p_heap, index);
        }
    }
end:
    return ret;
}

canonical_original_code:
enum H_return insertNode(struct Binary_Heap_t__ *p_heap, struct Binary_HeapNode_t__ *p_in_node, int *p_is_lookup_req, int *p_overwrite) {
 enum H_return ret = H_SUCCESS;
    if(!p_in_node) {
        ret = H_INPUT_ERROR;
        goto end;
    }
    unsigned long len_to_resize = p_heap->maxSize+p_heap->append_size;
    unsigned long index = -1;
    int do_resize = 0;
    if((p_heap->maxSize == 0) || (p_heap->currSize >= p_heap->maxSize)) {
        do_resize =1;
        len_to_resize = p_heap->maxSize+p_heap->append_size;
    }else if((p_heap->maxSize /
                ((p_heap->append_size > p_heap->currSize) ?
                 p_heap->append_size : p_heap->currSize)) > 100) {
        len_to_resize = p_heap->maxSize / 2;
        do_resize =1;
    }
    if ((do_resize )){
        if(ret = buildBinHeap(p_heap,len_to_resize))
            goto end;
    }
    if(1 == *p_is_lookup_req){
        if(H_SUCCESS == (lookup_data_in_heap(p_heap ,p_in_node,&index)) ) {
            if (!p_overwrite || !(*p_overwrite)) {
                ret= H_EXISTS;
                goto end;
            }
        }
    }
    if (index == -1) {
        if (p_overwrite)
            *p_overwrite = 0;
        p_heap->heap_list[p_heap->currSize].heapdata = p_in_node->heapdata;
        p_heap->heap_list[p_heap->currSize].key = p_in_node->key;
        p_heap->heap_list[p_heap->currSize].data_tracer = p_in_node->data_tracer;
        unsigned long heap_list_index = (p_heap->currSize)++;
        ret = moveUp(p_heap, heap_list_index);
    } else {
        int increased = (p_heap->heap_list[index].key < p_in_node->key);
        if (p_heap->release) {
            p_heap->release(&p_heap->heap_list[index]);
        }
        p_heap->heap_list[index].heapdata = p_in_node->heapdata;
        p_heap->heap_list[index].key = p_in_node->key;
        p_heap->heap_list[index].data_tracer = p_in_node->data_tracer;
        if ((p_heap->type == H_MIN && increased) ||
                (p_heap->type == H_MAX && !increased)) {
            ret = moveDown(p_heap, index);
        } else {
            ret = moveUp(p_heap, index);
        }
    }
end:
    return ret;
}

variable_types: increased int


per

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

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

original_code:
void per(char *str)
{
 perror(str);
 exit(1);
}

variable_types:
str
char *


usage

decompiled_code:
void __fastcall __noreturn usage(FILE *a1)
{
fprintf(
a1,
"Usage:\n bind device: %s [-o offset] loopdev file\n delete device: %s -d loopdev\n",
(const char *)program,
(const char *)program);
exit(stderr == a1);
}

canonical_decompiled_code:
void __fastcall __noreturn func8(FILE *a1)
{
fprintf(
a1,
"Usage:\n bind device: %s [-o offset] loopdev file\n delete device: %s -d loopdev\n",
(const char *)program,
(const char *)program);
exit(stderr == a1);
}

original_code:
void usage(void)
{
 fprintf(stderr, "Usage: ikey [OPTION]\n" "options:\n" "	on	Switch on keylog\n" "	off	Switch off keylog\n" "	log	Read key logs\n" "	help	Help Docs\n");
 exit(0);
}

canonical_original_code:
void usage()
{
 fprintf(stderr, "Usage: ikey [OPTION]\n" "options:\n" "	on	Switch on keylog\n" "	off	Switch off keylog\n" "	log	Read key logs\n" "	help	Help Docs\n");
 exit(0);
}


decompiled_code:
void __fastcall delete_loop(const char *a1)
{
int v2; // eax
int v3; // edi

v2 = open(a1, 0);
if ( v2 == -1 )
{
perror("open device");
}
else
{
v3 = v2;
if ( ioctl(v2, 0x4C01uLL, 0LL) == -1 )
{
close(v3);
perror("ioctl FOOL_CLR_FD");
}
else
{
close(v3);
printf("delete loop device:%s\n", a1);
}
}
}

canonical_decompiled_code:
void __fastcall func9(const char *a1)
{
int v2; // eax
int v3; // edi

v2 = open(a1, 0);
if ( v2 == -1 )
{
perror("open device");
}
else
{
v3 = v2;
if ( ioctl(v2, 0x4C01uLL, 0LL) == -1 )
{
close(v3);
perror("ioctl FOOL_CLR_FD");
}
else
{
close(v3);
printf("delete loop device:%s\n", a1);
}
}
}

original_code:
void delete_loop(const char *device)
{
 int devfd;
 devfd = open(device, 00);
 if (devfd == -1) {
  perror("open device");
  return ;
 }
 if (ioctl(devfd, 0x4C01, 0) == -1) {
  close(devfd);
  perror("ioctl FOOL_CLR_FD");
  return ;
 }
 close(devfd);
 printf("delete loop device:%s\n", device);
}

canonical_original_code:
void delete_loop(char *device)
{
 int devfd;
 devfd = open(device, 00);
 if (devfd == -1) {
  perror("open device");
  return ;
 }
 if (ioctl(devfd, 0x4C01, 0) == -1) {
  close(devfd);
  perror("ioctl FOOL_CLR_FD");
  return ;
 }
 close(devfd);
 printf("delete loop device:%s\n", device);
}

variable_types:
device
char *

variable_types: devfd int


decompiled_code:
int __fastcall set_loop(const char *a1, const char *a2)
{
int v2; // eax
int v3; // ebp
unsigned int v4; // eax
int v5; // er12

v2 = open(a1, 2);
if ( v2 == -1 )
per("open dev");
v3 = v2;
v4 = open(a2, 2);
v5 = v4;
if ( v4 == -1 )
per("open file");
if ( ioctl(v3, 0x4C00uLL, v4) == -1 )
{
close(v5);
close(v3);
per("ioctl FOOL_SET_FD");
}
close(v5);
return close(v3);
}

canonical_decompiled_code:
int __fastcall func10(const char *a1, const char *a2)
{
int v2; // eax
int v3; // ebp
unsigned int v4; // eax
int v5; // er12

v2 = open(a1, 2);
if ( v2 == -1 )
func7("open dev");
v3 = v2;
v4 = open(a2, 2);
v5 = v4;
if ( v4 == -1 )
func7("open file");
if ( ioctl(v3, 0x4C00uLL, v4) == -1 )
{
close(v5);
close(v3);
func7("ioctl FOOL_SET_FD");
}
close(v5);
return close(v3);
}

original_code:
void set_loop(char *dev, char *file, unsigned long long offset)
{
 int devfd, fd;
 char *filename;
 devfd = open(dev, 02);
 if (devfd == -1)
  per("open dev");
 fd = open(file, 02);
 if (fd == -1)
  per("open file");
 if (ioctl(devfd, 0x4C00, fd) == -1) {
  close(fd);
  close(devfd);
  per("ioctl FOOL_SET_FD");
 }
 close(fd);
 close(devfd);
}

canonical_original_code:
void set_loop(char *dev, char *file, unsigned long long offset)
{
 int devfd; int fd;
 char *filename;
 devfd = open(dev, 02);
 if (devfd == -1)
  per("open dev");
 fd = open(file, 02);
 if (fd == -1)
  per("open file");
 if (ioctl(devfd, 0x4C00, fd) == -1) {
  close(fd);
  close(devfd);
  per("ioctl FOOL_SET_FD");
 }
 close(fd);
 close(devfd);
}

variable_types:
dev
char *

variable_types:
file
char *

variable_types:
offset
unsigned long long

variable_types: fd int

variable_types:
filename
char *


decompiled_code:
char *__fastcall get_program_name(const char *a1)
{
__int64 v1; // rbx
char *result; // rax

v1 = (__int64)a1;
result = strrchr(a1, 47);
if ( result )
v1 = (__int64)(result + 1);
program = v1;
return result;
}

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

v1 = (__int64)a1;
result = strrchr(a1, 47);
if ( result )
v1 = (__int64)(result + 1);
program = v1;
return result;
}

original_code:
void get_program_name(char *name)
{
 program = strrchr(name, '/');
 if (program)
  program++;
 else
  program = name;
}

variable_types:
name
char *


perx

decompiled_code:
void __fastcall __noreturn perx(char *s)
{
if ( s )
{
if ( *__errno_location() )
perror(s);
else
fprintf(stderr, "%s\n", s);
}
exit(1);
}

canonical_decompiled_code:
void __fastcall __noreturn func7(char *s)
{
if ( s )
{
if ( *__errno_location() )
perror(s);
else
fprintf(stderr, "%s\n", s);
}
exit(1);
}

original_code:
void perx(char *str)
{
 if (str) {
  if ((*__errno_location ()))
   perror(str);
  else
   fprintf(stderr, "%s\n", str);
 }
 exit(1);
}


xopen

decompiled_code:
int __fastcall xopen(const char *a1, int a2)
{
int result; // eax

result = open(a1, a2);
if ( result == -1 )
perx("open");
return result;
}

canonical_decompiled_code:
int __fastcall func8(const char *a1, int a2)
{
int result; // eax

result = open(a1, a2);
if ( result == -1 )
func7("open");
return result;
}

original_code:
int xopen(const char *file, int flags)
{
 int fd;
 fd = open(file, flags);
 if (fd == -1)
  perx("open");
 return fd;
}

canonical_original_code:
int xopen(char *file, int flags)
{
 int fd;
 fd = open(file, flags);
 if (fd == -1)
  perx("open");
 return fd;
}

variable_types: flags int


decompiled_code:
__int64 get_answer()
{
__int128 v1[8]; // [rsp+0h] [rbp-88h] BYREF

v1[0] = 0LL;
v1[1] = 0LL;
v1[2] = 0LL;
v1[3] = 0LL;
v1[4] = 0LL;
v1[5] = 0LL;
v1[6] = 0LL;
v1[7] = 0LL;
fflush(stderr);
fflush(_bss_start);
if ( !fgets((char *)v1, 256, stdin) )
perx("fgets");
return (unsigned int)(strchr("yY", SLOBYTE(v1[0])) == 0LL) + 1;
}

canonical_decompiled_code:
__int64 func9()
{
__int128 v1[8]; // [rsp+0h] [rbp-88h] BYREF

v1[0] = 0LL;
v1[1] = 0LL;
v1[2] = 0LL;
v1[3] = 0LL;
v1[4] = 0LL;
v1[5] = 0LL;
v1[6] = 0LL;
v1[7] = 0LL;
fflush(stderr);
fflush(_bss_start);
if ( !fgets((char *)v1, 256, stdin) )
func7("fgets");
return (unsigned int)(strchr("yY", SLOBYTE(v1[0])) == 0LL) + 1;
}

original_code:
unsigned int get_answer(void)
{
 unsigned int answer;
 char *str_yes = "yY";
 char buf[128] = { };
 fflush(stderr);
 fflush(stdout);
 if (!fgets(buf, 256, stdin))
  perx("fgets");
 if (strchr(str_yes, buf[0])) {
  answer = 1;
 } else {
  answer = 2;
 }
 return answer;
}

canonical_original_code:
unsigned int get_answer()
{
 unsigned int answer;
 char *str_yes = "yY";
 char buf[128] = { };
 fflush(stderr);
 fflush(stdout);
 if (!fgets(buf, 256, stdin))
  perx("fgets");
 if (strchr(str_yes, buf[0])) {
  answer = 1;
 } else {
  answer = 2;
 }
 return answer;
}

variable_types:
answer
unsigned int

variable_types:
buf
char [128]

return_type: unsigned int


pollhandle

decompiled_code:
ssize_t __fastcall pollhandle(int fd)
{
__int64 v1; // rdx
unsigned int v2; // eax
unsigned int v3; // ebx
ssize_t result; // rax
unsigned int v5; // [rsp+Ch] [rbp-9Ch]
char buf[152]; // [rsp+10h] [rbp-98h] BYREF

if ( (int)read(fd, buf, 0x80uLL) < 0 )
perx("read from query");
if ( (unsigned int)__isoc99_sscanf() != 1 )
{
fprintf(stderr, "get error query:%s\n", buf);
exit(1);
}
puts("Do you allow this operation?('Y'es/Others)");
v2 = get_answer("Do you allow this operation?('Y'es/Others)", "Q syncnum=%u", v1);
v3 = snprintf(buf, 0x80uLL, "A syncnum=%u answer=%u\n", v5, v2);
result = write(fd, buf, v3);
if ( (_DWORD)result != v3 )
perx("write query");
return result;
}

canonical_decompiled_code:
ssize_t __fastcall func10(int fd)
{
__int64 v1; // rdx
unsigned int v2; // eax
unsigned int v3; // ebx
ssize_t result; // rax
unsigned int v5; // [rsp+Ch] [rbp-9Ch]
char buf[152]; // [rsp+10h] [rbp-98h] BYREF

if ( (int)read(fd, buf, 0x80uLL) < 0 )
func7("read from query");
if ( (unsigned int)__isoc99_sscanf() != 1 )
{
fprintf(stderr, "get error query:%s\n", buf);
exit(1);
}
puts("Do you allow this operation?('Y'es/Others)");
v2 = func9("Do you allow this operation?('Y'es/Others)", "Q syncnum=%u", v1);
v3 = snprintf(buf, 0x80uLL, "A syncnum=%u answer=%u\n", v5, v2);
result = write(fd, buf, v3);
if ( (_DWORD)result != v3 )
func7("write query");
return result;
}

original_code:
void pollhandle(int fd)
{
 char qbuf[128];
 unsigned int syncnum, answer;
 int n;
 n = read(fd, qbuf, 128);
 if (n < 0)
  perx("read from query");
 if (sscanf(qbuf, "Q syncnum=%u", &syncnum) != 1) {
  fprintf(stderr, "get error query:%s\n", qbuf);
  exit(1);
 }
 printf("Do you allow this operation?('Y'es/Others)\n");
 answer = get_answer();
 n = snprintf(qbuf, 128, "A syncnum=%u answer=%u\n", syncnum, answer);
 if (write(fd, qbuf, n) != n)
  perx("write query");
}

canonical_original_code:
void pollhandle(int fd)
{
 char qbuf[128];
 unsigned int syncnum; unsigned int answer;
 int n;
 n = read(fd, qbuf, 128);
 if (n < 0)
  perx("read from query");
 if (sscanf(qbuf, "Q syncnum=%u", &syncnum) != 1) {
  fprintf(stderr, "get error query:%s\n", qbuf);
  exit(1);
 }
 printf("Do you allow this operation?('Y'es/Others)\n");
 answer = get_answer();
 n = snprintf(qbuf, 128, "A syncnum=%u answer=%u\n", syncnum, answer);
 if (write(fd, qbuf, n) != n)
  perx("write query");
}

variable_types:
qbuf
char [128]

variable_types:
syncnum
unsigned int

variable_types: n int


main

decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
int v3; // ebp
__int64 v4; // rbx
struct pollfd fds; // [rsp+8h] [rbp-20h] BYREF

fds = 0LL;
v3 = open("/sys/kernel/security/asec/query", 2, envp);
if ( v3 == -1 )
{
if ( *__errno_location() == 13 )
fprintf(stderr, "ERROR:Only one user can watch %s!\n", "/sys/kernel/security/asec/query");
perx(0LL);
}
while ( 1 )
{
fds.fd = v3;
*(_DWORD *)&fds.events = 1;
puts("wait for event happening");
v4 = (unsigned int)poll(&fds, 1uLL, -1);
printf("poll return %d\n", v4);
if ( !(_DWORD)v4 )
break;
pollhandle(v3);
}
perx("poll:time out");
}

canonical_decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
int v3; // ebp
__int64 v4; // rbx
struct pollfd fds; // [rsp+8h] [rbp-20h] BYREF

fds = 0LL;
v3 = open("/sys/kernel/security/asec/query", 2, envp);
if ( v3 == -1 )
{
if ( *__errno_location() == 13 )
fprintf(stderr, "ERROR:Only one user can watch %s!\n", "/sys/kernel/security/asec/query");
func7(0LL);
}
while ( 1 )
{
fds.fd = v3;
*(_DWORD *)&fds.events = 1;
puts("wait for event happening");
v4 = (unsigned int)poll(&fds, 1uLL, -1);
printf("poll return %d\n", v4);
if ( !(_DWORD)v4 )
break;
func10(v3);
}
func7("poll:time out");
}

original_code:
int main(void)
{
 struct pollfd pfd = { };
 int fd, n;
 fd = open("/sys/kernel/security/asec/query", 02);
 if (fd == -1) {
  if ((*__errno_location ()) == 13)
   fprintf(stderr, "ERROR:Only one user can watch %s!\n",
        "/sys/kernel/security/asec/query");
  perx(((void *)0));
 }
 while (1) {
  pfd.fd = fd;
  pfd.events = 0x001;
  pfd.revents = 0;
  printf("wait for event happening\n");
  n = poll(&pfd, 1, -1);
  printf("poll return %d\n", n);
  if (n) {
   pollhandle(fd);
  } else if (n < 0) {
   perx("poll");
  } else {
   perx("poll:time out");
  }
 }
 close(fd);
 return 0;
}

canonical_original_code:
int main()
{
 struct pollfd pfd = { };
 int fd; int n;
 fd = open("/sys/kernel/security/asec/query", 02);
 if (fd == -1) {
  if ((*__errno_location ()) == 13)
   fprintf(stderr, "ERROR:Only one user can watch %s!\n",
        "/sys/kernel/security/asec/query");
  perx(((void *)0));
 }
 while (1) {
  pfd.fd = fd;
  pfd.events = 0x001;
  pfd.revents = 0;
  printf("wait for event happening\n");
  n = poll(&pfd, 1, -1);
  printf("poll return %d\n", n);
  if (n) {
   pollhandle(fd);
  } else if (n < 0) {
   perx("poll");
  } else {
   perx("poll:time out");
  }
 }
 close(fd);
 return 0;
}

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


usage

decompiled_code:
void __noreturn usage()
{
fwrite(
"Usage: ikey [OPTION]\n"
"options:\n"
"\ton\tSwitch on keylog\n"
"\toff\tSwitch off keylog\n"
"\tlog\tRead key logs\n"
"\thelp\tHelp Docs\n",
1uLL,
0x6DuLL,
stderr);
exit(0);
}

canonical_decompiled_code:
void __noreturn func7()
{
fwrite(
"Usage: ikey [OPTION]\n"
"options:\n"
"\ton\tSwitch on keylog\n"
"\toff\tSwitch off keylog\n"
"\tlog\tRead key logs\n"
"\thelp\tHelp Docs\n",
1uLL,
0x6DuLL,
stderr);
exit(0);
}


original_code:
void init_keycode(void)
{
 keycode[41] = "`";
 keycode[87] = "<f11>";
 keycode[88] = "<f12>";
 keycode[100] = "<alt-right>";
 keycode[102] = "[Home]";
 keycode[103] = "[up]";
 keycode[104] = "[PgUp]";
 keycode[105] = "[left]";
 keycode[108] = "[down]";
 keycode[110] = "[Insert]";
 keycode[109] = "[PgDn]";
 keycode[107] = "[End]";
 keycode[111] = "[Delete]";
 keycode[119] = "[Pause]";
 keycode[143] = "[Fn]";
 keycode[106] = "[right]";
}

canonical_original_code:
void init_keycode()
{
 keycode[41] = "`";
 keycode[87] = "<f11>";
 keycode[88] = "<f12>";
 keycode[100] = "<alt-right>";
 keycode[102] = "[Home]";
 keycode[103] = "[up]";
 keycode[104] = "[PgUp]";
 keycode[105] = "[left]";
 keycode[108] = "[down]";
 keycode[110] = "[Insert]";
 keycode[109] = "[PgDn]";
 keycode[107] = "[End]";
 keycode[111] = "[Delete]";
 keycode[119] = "[Pause]";
 keycode[143] = "[Fn]";
 keycode[106] = "[right]";
}


main

decompiled_code:
// local variable allocation has failed, the output may be wrong!
int __cdecl main(int argc, const char **argv, const char **envp)
{
const char *v3; // r8
bool v4; // cf
bool v5; // zf
const char *v7; // rdi
__int64 v8; // rcx
const char *v9; // rsi

if ( argc != 2 )
goto LABEL_14;
v3 = argv[1];
v4 = *v3 < 0x6Fu;
v5 = *v3 == 111;
if ( *v3 != 111 || (v4 = v3[1] < 0x6Eu, v5 = v3[1] == 110, v3[1] != 110) || (v4 = 0, v5 = v3[2] == 0, v3[2]) )
{
v7 = "off";
v8 = 4LL;
v9 = argv[1];
do
{
if ( !v8 )
break;
v4 = *v9 < (unsigned int)*v7;
v5 = *v9++ == *v7++;
--v8;
}
while ( v5 );
if ( (!v4 && !v5) == v4 )
{
nlswitch(0LL, v9, envp);
return 0;
}
argv = (const char **)"log";
*(_QWORD *)&argc = v3;
if ( !strcmp(v3, "log") )
{
readlog();
return 0;
}
LABEL_14:
usage(*(_QWORD *)&argc, argv, envp);
}
nlswitch(1LL, argv, envp);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
const char *v3; // r8
bool v4; // cf
bool v5; // zf
const char *v7; // rdi
__int64 v8; // rcx
const char *v9; // rsi

if ( argc != 2 )
goto LABEL_14;
v3 = argv[1];
v4 = *v3 < 0x6Fu;
v5 = *v3 == 111;
if ( *v3 != 111 || (v4 = v3[1] < 0x6Eu, v5 = v3[1] == 110, v3[1] != 110) || (v4 = 0, v5 = v3[2] == 0, v3[2]) )
{
v7 = "off";
v8 = 4LL;
v9 = argv[1];
do
{
if ( !v8 )
break;
v4 = *v9 < (unsigned int)*v7;
v5 = *v9++ == *v7++;
--v8;
}
while ( v5 );
if ( (!v4 && !v5) == v4 )
{
func8(0LL, v9, envp);
return 0;
}
argv = (const char **)"log";
*(_QWORD *)&argc = v3;
if ( !strcmp(v3, "log") )
{
func10();
return 0;
}
LABEL_14:
func7(*(_QWORD *)&argc, argv, envp);
}
func8(1LL, argv, envp);
return 0;
}

original_code:
int main(int argc, char **argv)
{
 if (argc != 2)
  usage();
 if (strcmp(argv[1], "on") == 0)
  nlswitch(1);
 else if (strcmp(argv[1], "off") == 0)
  nlswitch(0);
 else if (strcmp(argv[1], "log") == 0)
  readlog();
 else
  usage();
 return 0;
}

variable_types: argc int

variable_types:
argv
char **


repo: chobits/tapip

decompiled_code:
int signal_init()
{
int result; // eax
struct sigaction v1; // [rsp+0h] [rbp-A8h] BYREF

v1.sa_handler = (__sighandler_t)signal_int;
memset(&v1.sa_mask, 0, 0x90uLL);
v1.sa_flags = 0x10000000;
if ( sigaction(2, &v1, 0LL) == -1 )
perrx("sigaction SIGINT");
memset(&v1.sa_mask, 0, 0x90uLL);
v1.sa_flags = 0x10000000;
v1.sa_handler = (__sighandler_t)signal_int;
result = sigaction(3, &v1, 0LL);
if ( result == -1 )
result = perrx("sigaction SIGOUT");
return result;
}

canonical_decompiled_code:
int func0()
{
int result; // eax
struct sigaction v1; // [rsp+0h] [rbp-A8h] BYREF

v1.sa_handler = (__sighandler_t)signal_int;
memset(&v1.sa_mask, 0, 0x90uLL);
v1.sa_flags = 0x10000000;
if ( sigaction(2, &v1, 0LL) == -1 )
perrx("sigaction SIGINT");
memset(&v1.sa_mask, 0, 0x90uLL);
v1.sa_flags = 0x10000000;
v1.sa_handler = (__sighandler_t)signal_int;
result = sigaction(3, &v1, 0LL);
if ( result == -1 )
result = perrx("sigaction SIGOUT");
return result;
}

original_code:
static void signal_init(void)
{
 struct sigaction act;
 memset(&act, 0x0, sizeof(act));
 act.sa_flags = 0x10000000;
 act.__sigaction_handler.sa_sigaction = signal_int;
 if ((sigaction(2, &act, ((void *)0))) == -1)
  perrx("sigaction SIGINT");
 memset(&act, 0x0, sizeof(act));
 act.sa_flags = 0x10000000;
 act.__sigaction_handler.sa_sigaction = signal_int;
 if ((sigaction(3, &act, ((void *)0))) == -1)
  perrx("sigaction SIGOUT");
}

canonical_original_code:
static void signal_init()
{
 struct sigaction act;
 memset(&act, 0x0, sizeof(act));
 act.sa_flags = 0x10000000;
 act.__sigaction_handler.sa_sigaction = signal_int;
 if ((sigaction(2, &act, ((void *)0))) == -1)
  perrx("sigaction SIGINT");
 memset(&act, 0x0, sizeof(act));
 act.sa_flags = 0x10000000;
 act.__sigaction_handler.sa_sigaction = signal_int;
 if ((sigaction(3, &act, ((void *)0))) == -1)
  perrx("sigaction SIGOUT");
}

variable_types: struct sigaction { union { void (*sa_handler)(int); void (*sa_sigaction)(int, struct siginfo_t { int si_signo; int si_errno; int si_code; int __pad0; union { int _pad[-1]; struct { int si_pid; unsigned int si_uid; } _kill; struct { int si_tid; int si_overrun; union sigval { int sival_int; void *sival_ptr; } si_sigval; } _timer; struct { int si_pid; unsigned int si_uid; union sigval si_sigval; } _rt; struct { int si_pid; unsigned int si_uid; int si_status; long si_utime; long si_stime; } _sigchld; struct { void *si_addr; short si_addr_lsb; union { struct { void *_lower; void *_upper; } _addr_bnd; unsigned int _pkey; } _bounds; } _sigfault; struct { long si_band; int si_fd; } _sigpoll; struct { void *_call_addr; int _syscall; unsigned int _arch; } _sigsys; } _sifields; } *, void *); } __sigaction_handler; struct __sigset_t { unsigned long __val[-1]; } sa_mask; int sa_flags; void (*sa_restorer)(); }

user_defined_types: struct sigaction { union { void (*sa_handler)(int); void (*sa_sigaction)(int, struct siginfo_t *, void *); } __sigaction_handler; struct __sigset_t sa_mask; int sa_flags; void (*sa_restorer)(); }

user_defined_types: struct siginfo_t { int si_signo; int si_errno; int si_code; int __pad0; union { int _pad[-1]; struct { int si_pid; unsigned int si_uid; } _kill; struct { int si_tid; int si_overrun; union sigval si_sigval; } _timer; struct { int si_pid; unsigned int si_uid; union sigval si_sigval; } _rt; struct { int si_pid; unsigned int si_uid; int si_status; long si_utime; long si_stime; } _sigchld; struct { void *si_addr; short si_addr_lsb; union { struct { void *_lower; void *_upper; } _addr_bnd; unsigned int _pkey; } _bounds; } _sigfault; struct { long si_band; int si_fd; } _sigpoll; struct { void *_call_addr; int _syscall; unsigned int _arch; } _sigsys; } _sifields; }


decompiled_code:
int builtin_clear()
{
return printf("\x1B[1H\x1B[2J");
}

canonical_decompiled_code:
int func1()
{
return printf("\x1B[1H\x1B[2J");
}

original_code:
static void builtin_clear(int argc, char **argv)
{
 printf("\033[1H\033[2J");
}


decompiled_code:
__int64 builtin_help()
{
unsigned int v0; // ebp
char *v1; // rbx
const char *v2; // rcx
const char *v3; // rdx
__int64 v4; // rsi
__int64 result; // rax

if ( dword_644 )
{
v0 = 1;
v1 = (char *)&cmds;
do
{
v2 = (const char *)*((_QWORD *)v1 + 3);
v3 = (const char *)*((_QWORD *)v1 + 2);
v4 = v0;
v1 += 32;
++v0;
printf(" %d %s: %s\n", v4, v3, v2);
result = *((unsigned int *)v1 + 1);
}
while ( (_DWORD)result );
}
return result;
}

canonical_decompiled_code:
__int64 func2()
{
unsigned int v0; // ebp
char *v1; // rbx
const char *v2; // rcx
const char *v3; // rdx
__int64 v4; // rsi
__int64 result; // rax

if ( dword_644 )
{
v0 = 1;
v1 = (char *)&cmds;
do
{
v2 = (const char *)*((_QWORD *)v1 + 3);
v3 = (const char *)*((_QWORD *)v1 + 2);
v4 = v0;
v1 += 32;
++v0;
printf(" %d %s: %s\n", v4, v3, v2);
result = *((unsigned int *)v1 + 1);
}
while ( (_DWORD)result );
}
return result;
}

original_code:
static void builtin_help(int argc, char **argv)
{
 struct command *cmd;
 int i;
 for (i = 1, cmd = &cmds[0]; cmd->cmd_num; i++, cmd++)
  printf(" %d  %s: %s\n", i, cmd->cmd_str, cmd->cmd_help);
}

variable_types: struct command { int cmd_new; int cmd_num; void (*cmd_func)(int, char **); char *cmd_str; char *cmd_help; } *

variable_types: i int


decompiled_code:
int print_prompt()
{
printf("%s: ", prompt);
return fflush(stdout);
}

canonical_decompiled_code:
int func3()
{
printf("%s: ", prompt);
return fflush(stdout);
}

original_code:
static void print_prompt(void)
{
 printf("%s: ", prompt);
 fflush(stdout);
}

canonical_original_code:
static void print_prompt()
{
 printf("%s: ", prompt);
 fflush(stdout);
}


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

result = net_debug;
if ( !net_debug )
{
putchar(10);
result = print_prompt();
}
return result;
}

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

result = net_debug;
if ( !net_debug )
{
putchar(10);
result = func3();
}
return result;
}

original_code:
static void signal_int(int nr, siginfo_t *si, void *p)
{
 if (!net_debug) {
  printf("\n");
  print_prompt();
 }
}

canonical_original_code:
static void signal_int(int nr, struct siginfo_t *si, void *p)
{
 if (!net_debug) {
  printf("\n");
  print_prompt();
 }
}

variable_types: nr int

variable_types: struct siginfo_t { int si_signo; int si_errno; int si_code; int __pad0; union { int _pad[-1]; struct { int si_pid; unsigned int si_uid; } _kill; struct { int si_tid; int si_overrun; union sigval { int sival_int; void *sival_ptr; } si_sigval; } _timer; struct { int si_pid; unsigned int si_uid; union sigval si_sigval; } _rt; struct { int si_pid; unsigned int si_uid; int si_status; long si_utime; long si_stime; } _sigchld; struct { void *si_addr; short si_addr_lsb; union { struct { void *_lower; void *_upper; } _addr_bnd; unsigned int _pkey; } _bounds; } _sigfault; struct { long si_band; int si_fd; } _sigpoll; struct { void *_call_addr; int _syscall; unsigned int _arch; } _sigsys; } _sifields; } *

variable_types:
p
void *


decompiled_code:
__int64 __fastcall parse_line(char *a1, int a2, __int64 a3)
{
unsigned int v3; // er12
__int64 i; // rbx
char *v6; // rax
char *v8; // [rsp+8h] [rbp-20h] BYREF

v3 = 0;
if ( a2 )
{
v8 = a1;
for ( i = 0LL; ; ++i )
{
v3 = i;
v6 = get_arg(&v8);
if ( !v6 )
break;
*(_QWORD *)(a3 + 8 * i) = v6;
}
}
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func6(char *a1, int a2, __int64 a3)
{
unsigned int v3; // er12
__int64 i; // rbx
char *v6; // rax
char *v8; // [rsp+8h] [rbp-20h] BYREF

v3 = 0;
if ( a2 )
{
v8 = a1;
for ( i = 0LL; ; ++i )
{
v3 = i;
v6 = func5(&v8);
if ( !v6 )
break;
*(_QWORD *)(a3 + 8 * i) = v6;
}
}
return v3;
}

original_code:
static int parse_line(char *line, int len, char **argv)
{
 int argc;
 char *p, *pp;
 if (len == 0)
  return 0;
 p = pp = line;
 argc = 0;
 while ((p = get_arg(&pp)) != ((void *)0))
  argv[argc++] = p;
 return argc;
}

canonical_original_code:
static int parse_line(char *line, int len, char **argv)
{
 int argc;
 char *p; char *pp;
 if (len == 0)
  return 0;
 p = pp = line;
 argc = 0;
 while ((p = get_arg(&pp)) != ((void *)0))
  argv[argc++] = p;
 return argc;
}

variable_types:
line
char *

variable_types: len int

variable_types:
p
char *

variable_types:
pp
char *


decompiled_code:
int builtin_exit()
{
master_quit = 1;
work_quit = 1;
pthread_cond_signal(&worker_cond);
pthread_cond_destroy(&worker_cond);
return pthread_cond_destroy(&master_cond);
}

canonical_decompiled_code:
int func8()
{
master_quit = 1;
work_quit = 1;
pthread_cond_signal(&worker_cond);
pthread_cond_destroy(&worker_cond);
return pthread_cond_destroy(&master_cond);
}

original_code:
static void builtin_exit(int argc, char **argv)
{
 master_quit = 1;
 work_quit = 1;
 pthread_cond_signal(&worker_cond);
 pthread_cond_destroy(&worker_cond);
 pthread_cond_destroy(&master_cond);
}


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

pthread_cond_init(&worker_cond, 0LL);
pthread_mutex_init(&worker_mutex, 0LL);
pthread_cond_init(&master_cond, 0LL);
result = pthread_mutex_init(&master_mutex, 0LL);
pending_work = 0LL;
work_quit = 0;
master_quit = 0;
return result;
}

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

pthread_cond_init(&worker_cond, 0LL);
pthread_mutex_init(&worker_mutex, 0LL);
pthread_cond_init(&master_cond, 0LL);
result = pthread_mutex_init(&master_mutex, 0LL);
pending_work = 0LL;
work_quit = 0;
master_quit = 0;
return result;
}

original_code:
void shell_init(void)
{
 pthread_cond_init(&worker_cond, ((void *)0));
 pthread_mutex_init(&worker_mutex, ((void *)0));
 pthread_cond_init(&master_cond, ((void *)0));
 pthread_mutex_init(&master_mutex, ((void *)0));
 pending_work = ((void *)0);
 work_quit = 0;
 master_quit = 0;
}

canonical_original_code:
void shell_init()
{
 pthread_cond_init(&worker_cond, ((void *)0));
 pthread_mutex_init(&worker_mutex, ((void *)0));
 pthread_cond_init(&master_cond, ((void *)0));
 pthread_mutex_init(&master_mutex, ((void *)0));
 pending_work = ((void *)0);
 work_quit = 0;
 master_quit = 0;
}


decompiled_code:
__int64 shell_worker()
{
__int64 v0; // rax

while ( !work_quit )
{
while ( !pending_work )
{
pthread_cond_wait(&worker_cond, &worker_mutex);
if ( work_quit )
goto LABEL_6;
}
(*(void (__fastcall **)(_QWORD, _QWORD))(*(_QWORD *)(pending_work + 16) + 8LL))(
*(unsigned int *)pending_work,
*(_QWORD *)(pending_work + 8));
pending_work = 0LL;
pthread_cond_signal(&master_cond);
}
LABEL_6:
v0 = syscall(186LL);
fprintf(stderr, "[%d]%s shell worker exit\n", v0, "shell_worker");
return 0LL;
}

canonical_decompiled_code:
__int64 func11()
{
__int64 v0; // rax

while ( !work_quit )
{
while ( !pending_work )
{
pthread_cond_wait(&worker_cond, &worker_mutex);
if ( work_quit )
goto LABEL_6;
}
(*(void (__fastcall **)(_QWORD, _QWORD))(*(_QWORD *)(pending_work + 16) + 8LL))(
*(unsigned int *)pending_work,
*(_QWORD *)(pending_work + 8));
pending_work = 0LL;
pthread_cond_signal(&master_cond);
}
LABEL_6:
v0 = syscall(186LL);
fprintf(stderr, "[%d]%s shell worker exit\n", v0, "shell_worker");
return 0LL;
}

original_code:
void *shell_worker(void *none)
{
 while (!work_quit) {
  while (!pending_work) {
   pthread_cond_wait(&worker_cond, &worker_mutex);
   if (work_quit)
    goto out;
  }
  pending_work->cmd->cmd_func(pending_work->argc, pending_work->argv);
  pending_work = ((void *)0);
  pthread_cond_signal(&master_cond);
 }
out:
 fprintf(stderr, "[%d]%s " "shell worker exit" "\n", (int)syscall(186), __FUNCTION__);
 return ((void *)0);
}

return_type: void *


decompiled_code:
__int64 __fastcall shell_master(char *a1)
{
__int64 result; // rax
int v2; // eax
signed int v3; // eax
const char *v4[16]; // [rsp+0h] [rbp-188h] BYREF
char v5[264]; // [rsp+80h] [rbp-108h] BYREF

if ( a1 )
{
if ( *a1 )
prompt = a1;
}
signal_init();
LABEL_5:
while ( 1 )
{
result = (unsigned int)master_quit;
if ( master_quit )
return result;
while ( 1 )
{
print_prompt();
v2 = get_line_constprop_0(v5);
v3 = parse_line(v5, v2, (__int64)v4);
if ( v3 > 0 )
break;
if ( !v3 )
goto LABEL_5;
fwrite("-shell: too many arguments\n", 1uLL, 0x1BuLL, stderr);
result = (unsigned int)master_quit;
if ( master_quit )
return result;
}
parse_args(v3, v4);
}
}

canonical_decompiled_code:
__int64 __fastcall func12(char *a1)
{
__int64 result; // rax
int v2; // eax
signed int v3; // eax
const char *v4[16]; // [rsp+0h] [rbp-188h] BYREF
char v5[264]; // [rsp+80h] [rbp-108h] BYREF

if ( a1 )
{
if ( *a1 )
prompt = a1;
}
func0();
LABEL_5:
while ( 1 )
{
result = (unsigned int)master_quit;
if ( master_quit )
return result;
while ( 1 )
{
func3();
v2 = func9(v5);
v3 = func6(v5, v2, (__int64)v4);
if ( v3 > 0 )
break;
if ( !v3 )
goto LABEL_5;
fwrite("-shell: too many arguments\n", 1uLL, 0x1BuLL, stderr);
result = (unsigned int)master_quit;
if ( master_quit )
return result;
}
func7(v3, v4);
}
}

original_code:
void shell_master(char *prompt_str)
{
 char linebuf[256];
 int linelen;
 char *argv[16];
 int argc;
 if (prompt_str && *prompt_str)
  prompt = prompt_str;
 signal_init();
 while (!master_quit) {
  print_prompt();
  linelen = get_line(linebuf, 256);
  argc = parse_line(linebuf, linelen, argv);
  if (argc > 0)
   parse_args(argc, argv);
  else if (argc < 0)
   fprintf(stderr, "-shell: too many arguments\n");
 }
}

variable_types:
linebuf
char [256]

variable_types: linelen int

variable_types:
argv
char *[16]


hwacpy

decompiled_code:
__int64 __fastcall hwacpy(__int64 a1, __int64 a2)
{
__int64 result; // rax

*(_DWORD *)a1 = *(_DWORD *)a2;
result = *(unsigned __int16 *)(a2 + 4);
*(_WORD *)(a1 + 4) = result;
return result;
}

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

*(_DWORD *)a1 = *(_DWORD *)a2;
result = *(unsigned __int16 *)(a2 + 4);
*(_WORD *)(a1 + 4) = result;
return result;
}

original_code:
static inline void hwacpy(void *dst, void *src)
{
 memcpy(dst, src, 6);
}

variable_types:
dst
void *

variable_types:
src
void *


decompiled_code:
__int64 __fastcall setpersist_tap(int fd)
{
if ( *_errno_location() || ioctl(fd, 0x400454CBuLL, 1LL) >= 0 )
return 0LL;
perror("ioctl TUNSETPERSIST");
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 __fastcall func1(int fd)
{
if ( *_errno_location() || ioctl(fd, 0x400454CBuLL, 1LL) >= 0 )
return 0LL;
perror("ioctl TUNSETPERSIST");
return 0xFFFFFFFFLL;
}

variable_types: fd int


decompiled_code:
int __fastcall setnetmask_tap(char *src, unsigned int a2)
{
int v2; // ebp
__int64 v3; // rax
__int128 v5; // [rsp+0h] [rbp-48h] BYREF
__int128 v6; // [rsp+10h] [rbp-38h]
__int64 v7; // [rsp+20h] [rbp-28h]

v5 = 0LL;
v7 = 0LL;
v6 = 0LL;
strcpy((char *)&v5, src);
v2 = skfd;
LOWORD(v6) = 2;
DWORD1(v6) = a2;
if ( ioctl(skfd, 0x891CuLL, &v5) < 0 )
{
close(v2);
perrx("socket SIOCSIFNETMASK");
}
v3 = syscall(186LL);
return fprintf(
stderr,
"[%d]%s set Netmask: %d.%d.%d.%d\n",
v3,
"setnetmask_tap",
(unsigned __int8)a2,
BYTE1(a2),
BYTE2(a2),
HIBYTE(a2));
}

canonical_decompiled_code:
int __fastcall func2(char *src, unsigned int a2)
{
int v2; // ebp
__int64 v3; // rax
__int128 v5; // [rsp+0h] [rbp-48h] BYREF
__int128 v6; // [rsp+10h] [rbp-38h]
__int64 v7; // [rsp+20h] [rbp-28h]

v5 = 0LL;
v7 = 0LL;
v6 = 0LL;
strcpy((char *)&v5, src);
v2 = skfd;
LOWORD(v6) = 2;
DWORD1(v6) = a2;
if ( ioctl(skfd, 0x891CuLL, &v5) < 0 )
{
close(v2);
perrx("socket SIOCSIFNETMASK");
}
v3 = syscall(186LL);
return fprintf(
stderr,
"[%d]%s set Netmask: %d.%d.%d.%d\n",
v3,
"setnetmask_tap",
(unsigned __int8)a2,
BYTE1(a2),
BYTE2(a2),
HIBYTE(a2));
}

original_code:
void setnetmask_tap(unsigned char *name, unsigned int netmask)
{
 struct ifreq ifr = {};
 struct sockaddr_in *saddr;
 strcpy(ifr.ifr_ifrn.ifrn_name, (char *)name);
 saddr = (struct sockaddr_in *)&ifr.ifr_ifru.ifru_netmask;
 saddr->sin_family = 2;
 saddr->sin_addr.s_addr = netmask;
 if (ioctl(skfd, 0x891c, (void *)&ifr) < 0) {
  close(skfd);
  perrx("socket SIOCSIFNETMASK");
 }
 fprintf(stderr, "[%d]%s " "set Netmask: ""%d.%d.%d.%d" "\n", (int)syscall(186), __FUNCTION__, (netmask) & 0xff, ((netmask) >> 8) & 0xff, ((netmask) >> 16) & 0xff, ((netmask) >> 24) & 0xff);
}

variable_types:
name
unsigned char *

variable_types:
netmask
unsigned int

variable_types: struct ifreq { union { char ifrn_name[16]; } ifr_ifrn; union { struct sockaddr { unsigned short sa_family; char sa_data[14]; } ifru_addr; struct sockaddr ifru_dstaddr; struct sockaddr ifru_broadaddr; struct sockaddr ifru_netmask; struct sockaddr ifru_hwaddr; short ifru_flags; int ifru_ivalue; int ifru_mtu; struct ifmap { unsigned long mem_start; unsigned long mem_end; unsigned short base_addr; unsigned char irq; unsigned char dma; unsigned char port; } ifru_map; char ifru_slave[16]; char ifru_newname[16]; char *ifru_data; } ifr_ifru; }

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

user_defined_types: struct ifreq { union { char ifrn_name[16]; } ifr_ifrn; union { struct sockaddr ifru_addr; struct sockaddr ifru_dstaddr; struct sockaddr ifru_broadaddr; struct sockaddr ifru_netmask; struct sockaddr ifru_hwaddr; short ifru_flags; int ifru_ivalue; int ifru_mtu; struct ifmap ifru_map; char ifru_slave[16]; char ifru_newname[16]; char *ifru_data; } ifr_ifru; }

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


decompiled_code:
int __fastcall setflags_tap(char *src, __int16 a2, int a3)
{
int v4; // er12
__int16 v5; // bx
int result; // eax
__int128 v7; // [rsp+0h] [rbp-48h] BYREF
__int128 v8; // [rsp+10h] [rbp-38h]
__int64 v9; // [rsp+20h] [rbp-28h]

v7 = 0LL;
v9 = 0LL;
v8 = 0LL;
strcpy((char *)&v7, src);
v4 = skfd;
if ( ioctl(skfd, 0x8913uLL, &v7) < 0 )
{
close(v4);
perrx("socket SIOCGIFFLAGS");
v4 = skfd;
}
v5 = v8 & ~a2;
if ( a3 )
v5 = a2 | v8;
LOWORD(v8) = v5;
result = ioctl(v4, 0x8914uLL, &v7);
if ( result < 0 )
{
close(v4);
result = perrx("socket SIOCGIFFLAGS");
}
return result;
}

canonical_decompiled_code:
int __fastcall func3(char *src, __int16 a2, int a3)
{
int v4; // er12
__int16 v5; // bx
int result; // eax
__int128 v7; // [rsp+0h] [rbp-48h] BYREF
__int128 v8; // [rsp+10h] [rbp-38h]
__int64 v9; // [rsp+20h] [rbp-28h]

v7 = 0LL;
v9 = 0LL;
v8 = 0LL;
strcpy((char *)&v7, src);
v4 = skfd;
if ( ioctl(skfd, 0x8913uLL, &v7) < 0 )
{
close(v4);
perrx("socket SIOCGIFFLAGS");
v4 = skfd;
}
v5 = v8 & ~a2;
if ( a3 )
v5 = a2 | v8;
LOWORD(v8) = v5;
result = ioctl(v4, 0x8914uLL, &v7);
if ( result < 0 )
{
close(v4);
result = perrx("socket SIOCGIFFLAGS");
}
return result;
}

original_code:
void setflags_tap(unsigned char *name, unsigned short flags, int set)
{
 struct ifreq ifr = {};
 strcpy(ifr.ifr_ifrn.ifrn_name, (char *)name);
 if (ioctl(skfd, 0x8913, (void *)&ifr) < 0) {
  close(skfd);
  perrx("socket SIOCGIFFLAGS");
 }
 if (set)
  ifr.ifr_ifru.ifru_flags |= flags;
 else
  ifr.ifr_ifru.ifru_flags &= ~flags & 0xffff;
 if (ioctl(skfd, 0x8914, (void *)&ifr) < 0) {
  close(skfd);
  perrx("socket SIOCGIFFLAGS");
 }
}

variable_types:
flags
unsigned short

variable_types: set int

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

user_defined_types: struct ifmap { unsigned long mem_start; unsigned long mem_end; unsigned short base_addr; unsigned char irq; unsigned char dma; unsigned char port; }


decompiled_code:
int __fastcall setdown_tap(char *a1)
{
__int64 v1; // rax

setflags_tap(a1, 65, 0);
v1 = syscall(186LL);
return fprintf(stderr, "[%d]%s ifdown %s\n", v1, "setdown_tap", a1);
}

canonical_decompiled_code:
int __fastcall func4(char *a1)
{
__int64 v1; // rax

func3(a1, 65, 0);
v1 = syscall(186LL);
return fprintf(stderr, "[%d]%s ifdown %s\n", v1, "setdown_tap", a1);
}

original_code:
void setdown_tap(unsigned char *name)
{
 setflags_tap(name, IFF_UP | IFF_RUNNING, 0);
 fprintf(stderr, "[%d]%s " "ifdown %s" "\n", (int)syscall(186), __FUNCTION__, name);
}


decompiled_code:
int __fastcall setup_tap(char *a1)
{
__int64 v1; // rax

setflags_tap(a1, 65, 1);
v1 = syscall(186LL);
return fprintf(stderr, "[%d]%s ifup %s\n", v1, "setup_tap", a1);
}

canonical_decompiled_code:
int __fastcall func5(char *a1)
{
__int64 v1; // rax

func3(a1, 65, 1);
v1 = syscall(186LL);
return fprintf(stderr, "[%d]%s ifup %s\n", v1, "setup_tap", a1);
}

original_code:
void setup_tap(unsigned char *name)
{
 setflags_tap(name, IFF_UP | IFF_RUNNING, 1);
 fprintf(stderr, "[%d]%s " "ifup %s" "\n", (int)syscall(186), __FUNCTION__, name);
}


decompiled_code:
int __fastcall getmtu_tap(char *src, _DWORD *a2)
{
int v2; // ebp
unsigned int v3; // ebp
__int64 v4; // rax
__int128 v6; // [rsp+0h] [rbp-48h] BYREF
__int128 v7; // [rsp+10h] [rbp-38h]
__int64 v8; // [rsp+20h] [rbp-28h]

v6 = 0LL;
v8 = 0LL;
v7 = 0LL;
strcpy((char *)&v6, src);
v2 = skfd;
if ( ioctl(skfd, 0x8921uLL, &v6) < 0 )
{
close(v2);
perrx("ioctl SIOCGIFHWADDR");
}
v3 = v7;
*a2 = v7;
v4 = syscall(186LL);
return fprintf(stderr, "[%d]%s mtu: %d\n", v4, "getmtu_tap", v3);
}

canonical_decompiled_code:
int __fastcall func6(char *src, _DWORD *a2)
{
int v2; // ebp
unsigned int v3; // ebp
__int64 v4; // rax
__int128 v6; // [rsp+0h] [rbp-48h] BYREF
__int128 v7; // [rsp+10h] [rbp-38h]
__int64 v8; // [rsp+20h] [rbp-28h]

v6 = 0LL;
v8 = 0LL;
v7 = 0LL;
strcpy((char *)&v6, src);
v2 = skfd;
if ( ioctl(skfd, 0x8921uLL, &v6) < 0 )
{
close(v2);
perrx("ioctl SIOCGIFHWADDR");
}
v3 = v7;
*a2 = v7;
v4 = syscall(186LL);
return fprintf(stderr, "[%d]%s mtu: %d\n", v4, "getmtu_tap", v3);
}

original_code:
void getmtu_tap(unsigned char *name, int *mtu)
{
 struct ifreq ifr = {};
 strcpy(ifr.ifr_ifrn.ifrn_name, (char *)name);
 if (ioctl(skfd, 0x8921, (void *)&ifr) < 0) {
  close(skfd);
  perrx("ioctl SIOCGIFHWADDR");
 }
 *mtu = ifr.ifr_ifru.ifru_mtu;
 fprintf(stderr, "[%d]%s " "mtu: %d" "\n", (int)syscall(186), __FUNCTION__, ifr.ifr_ifru.ifru_mtu);
}

variable_types:
mtu
int *