decompiled_code:
void __fastcall set_argvs(struct termios *termios_p, int a2, __int64 a3)
{
int v4; // ebx
__int64 v5; // rbp
char **v6; // r15

if ( a2 > 1 )
{
v4 = 1;
while ( 1 )
{
v5 = 8LL * v4;
v6 = (char **)(a3 + v5);
if ( !(unsigned int)check_speed(termios_p, *(char **)(a3 + v5)) )
goto LABEL_4;
if ( (unsigned int)check_special(termios_p, *v6, *(const char **)(a3 + v5 + 8)) )
{
if ( !(unsigned int)check_setting((__int64)termios_p, *v6) )
goto LABEL_4;
++v4;
fprintf(_bss_start, "%s: invalid argument `%s'\n", (const char *)program_name, *v6);
if ( a2 <= v4 )
return;
}
else
{
++v4;
LABEL_4:
if ( a2 <= ++v4 )
return;
}
}
}
}

canonical_decompiled_code:
void __fastcall func11(struct termios *termios_p, int a2, __int64 a3)
{
int v4; // ebx
__int64 v5; // rbp
char **v6; // r15

if ( a2 > 1 )
{
v4 = 1;
while ( 1 )
{
v5 = 8LL * v4;
v6 = (char **)(a3 + v5);
if ( !(unsigned int)func8(termios_p, *(char **)(a3 + v5)) )
goto LABEL_4;
if ( (unsigned int)func9(termios_p, *v6, *(const char **)(a3 + v5 + 8)) )
{
if ( !(unsigned int)func10((__int64)termios_p, *v6) )
goto LABEL_4;
++v4;
fprintf(_bss_start, "%s: invalid argument `%s'\n", (const char *)program_name, *v6);
if ( a2 <= v4 )
return;
}
else
{
++v4;
LABEL_4:
if ( a2 <= ++v4 )
return;
}
}
}
}

original_code:
void set_argvs( struct termios *ttyopts, int ac, char *av[] )
{
 int i;
 for (i = 1; i < ac; i++) {
  if ( check_speed(ttyopts, av[i]) == 0 ) {
   continue;
  }
  else if ( check_special(ttyopts, av[i], av[i+1]) == 0 ) {
   i++;
   continue;
  }
  else if ( check_setting(ttyopts, av[i]) == 0 ) {
   continue;
  }
  else {
   fprintf(stderr, "%s: invalid argument `%s'\n",
    program_name, av[i]);
  }
 }
}

canonical_original_code:
void set_argvs(struct termios *ttyopts, int ac, char *av[])
{
 int i;
 for (i = 1; i < ac; i++) {
  if ( check_speed(ttyopts, av[i]) == 0 ) {
   continue;
  }
  else if ( check_special(ttyopts, av[i], av[i+1]) == 0 ) {
   i++;
   continue;
  }
  else if ( check_setting(ttyopts, av[i]) == 0 ) {
   continue;
  }
  else {
   fprintf(stderr, "%s: invalid argument `%s'\n",
    program_name, av[i]);
  }
 }
}

variable_types:
av
char *[]


repo: pamolloy/sttyl

decompiled_code:
__int64 __fastcall is_special(char *s2)
{
const char *v2; // rdi
__int64 v3; // rbx

v2 = off_4040A8;
if ( !off_4040A8 )
return 0xFFFFFFFFLL;
v3 = 0LL;
while ( strcmp(v2, s2) )
{
++v3;
v2 = (&off_4040A8)[2 * v3];
if ( !v2 )
return 0xFFFFFFFFLL;
}
return (unsigned int)v3;
}

canonical_decompiled_code:
__int64 __fastcall func12(char *s2)
{
const char *v2; // rdi
__int64 v3; // rbx

v2 = off_4040A8;
if ( !off_4040A8 )
return 0xFFFFFFFFLL;
v3 = 0LL;
while ( strcmp(v2, s2) )
{
++v3;
v2 = (&off_4040A8)[2 * v3];
if ( !v2 )
return 0xFFFFFFFFLL;
}
return (unsigned int)v3;
}

original_code:
int is_special( char *av )
{
 int i;
 for (i = 0; special_table[i].name; i++) {
  if ( strcmp(special_table[i].name, av) == 0 ) {
   return i;
  }
 }
 return -1;
}

canonical_original_code:
int is_special(char *av)
{
 int i;
 for (i = 0; special_table[i].name; i++) {
  if ( strcmp(special_table[i].name, av) == 0 ) {
   return i;
  }
 }
 return -1;
}

variable_types:
av
char *

variable_types: i int

return_type: int


decompiled_code:
__int64 __fastcall set_special(struct termios *termios_p, int a2, char *a3)
{
if ( *a3 < 0 )
return 0xFFFFFFFFLL;
termios_p->c_cc[special_table[4 * a2]] = *a3;
if ( tcsetattr(0, 0, termios_p) == -1 )
{
perror("tcsetattr");
exit(1);
}
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func13(struct termios *termios_p, int a2, char *a3)
{
if ( *a3 < 0 )
return 0xFFFFFFFFLL;
termios_p->c_cc[special_table[4 * a2]] = *a3;
if ( tcsetattr(0, 0, termios_p) == -1 )
{
perror("tcsetattr");
exit(1);
}
return 0LL;
}

original_code:
int set_special( struct termios *ttyopts, int i, char *c)
{
 if ( (((*c) & ~0x7f) == 0) == 0 ) {
  return -1;
 }
 ttyopts->c_cc[special_table[i].constant] = *c;
 if (tcsetattr(0, 0, ttyopts) == -1) {
  perror("tcsetattr");
  exit(1);
 }
 return 0;
}

canonical_original_code:
int set_special(struct termios *ttyopts, int i, char *c)
{
 if ( (((*c) & ~0x7f) == 0) == 0 ) {
  return -1;
 }
 ttyopts->c_cc[special_table[i].constant] = *c;
 if (tcsetattr(0, 0, ttyopts) == -1) {
  perror("tcsetattr");
  exit(1);
 }
 return 0;
}

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

variable_types:
c
char *


decompiled_code:
int __fastcall print_character(int c)
{
int result; // eax

result = (*__ctype_b_loc())[c];
if ( (result & 0x4000) != 0 )
return putchar(c);
if ( c == 127 )
return printf("^?");
if ( (result & 2) != 0 )
result = printf("^%c", (unsigned int)(c + 64));
return result;
}

canonical_decompiled_code:
int __fastcall func14(int c)
{
int result; // eax

result = (*__ctype_b_loc())[c];
if ( (result & 0x4000) != 0 )
return putchar(c);
if ( c == 127 )
return printf("^?");
if ( (result & 2) != 0 )
result = printf("^%c", (unsigned int)(c + 64));
return result;
}

original_code:
void print_character( int c )
{
 if ( ((*__ctype_b_loc ())[(int) ((c))] & (unsigned short int) _ISprint) != 0 ) {
  putchar(c);
 }
 else if ( c == 127 ) {
  printf("^?");
 }
 else if ( ((*__ctype_b_loc ())[(int) ((c))] & (unsigned short int) _IScntrl) != 0 ) {
  printf("^%c", c - 1 + 'A');
 }
}

canonical_original_code:
void print_character(int c)
{
 if ( ((*__ctype_b_loc ())[(int) ((c))] & (unsigned short) _ISprint) != 0 ) {
  putchar(c);
 }
 else if ( c == 127 ) {
  printf("^?");
 }
 else if ( ((*__ctype_b_loc ())[(int) ((c))] & (unsigned short) _IScntrl) != 0 ) {
  printf("^%c", c - 1 + 'A');
 }
}

variable_types: c int

return_type: void


decompiled_code:
int __fastcall print_special(__int64 a1)
{
const char *v2; // rdi
int *v3; // rbx

v2 = off_4040A8;
if ( off_4040A8 )
{
v3 = special_table;
do
{
v3 += 4;
printf(v2);
printf(" = ");
print_character(*(unsigned __int8 *)(a1 + (unsigned int)*(v3 - 4) + 17));
printf("; ");
v2 = (const char *)*((_QWORD *)v3 + 1);
}
while ( v2 );
}
return putchar(10);
}

canonical_decompiled_code:
int __fastcall func15(__int64 a1)
{
const char *v2; // rdi
int *v3; // rbx

v2 = off_4040A8;
if ( off_4040A8 )
{
v3 = special_table;
do
{
v3 += 4;
printf(v2);
printf(" = ");
func14(*(unsigned __int8 *)(a1 + (unsigned int)*(v3 - 4) + 17));
printf("; ");
v2 = (const char *)*((_QWORD *)v3 + 1);
}
while ( v2 );
}
return putchar(10);
}

original_code:
void print_special( struct termios *ttyopts )
{
 int i;
 for (i = 0; special_table[i].name; i++) {
  printf(special_table[i].name);
  printf(" = ");
  print_character(ttyopts->c_cc[special_table[i].constant]);
  printf("; ");
 }
 printf("\n");
}

canonical_original_code:
void print_special(struct termios *ttyopts)
{
 int i;
 for (i = 0; special_table[i].name; i++) {
  printf(special_table[i].name);
  printf(" = ");
  print_character(ttyopts->c_cc[special_table[i].constant]);
  printf("; ");
 }
 printf("\n");
}

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


decompiled_code:
__int64 __fastcall is_setting(char *s2)
{
const char *v2; // rdi
__int64 v3; // rbx

v2 = off_4040E8;
if ( !off_4040E8 )
return 0xFFFFFFFFLL;
v3 = 0LL;
while ( strcmp(v2, s2) )
{
++v3;
v2 = (&off_4040E8)[4 * v3];
if ( !v2 )
return 0xFFFFFFFFLL;
}
return (unsigned int)v3;
}

canonical_decompiled_code:
__int64 __fastcall func16(char *s2)
{
const char *v2; // rdi
__int64 v3; // rbx

v2 = off_4040E8;
if ( !off_4040E8 )
return 0xFFFFFFFFLL;
v3 = 0LL;
while ( strcmp(v2, s2) )
{
++v3;
v2 = (&off_4040E8)[4 * v3];
if ( !v2 )
return 0xFFFFFFFFLL;
}
return (unsigned int)v3;
}

original_code:
int is_setting( char *av )
{
 int i;
 for ( i = 0; setting_table[i].name; i++ ) {
  if ( strcmp(setting_table[i].name, av) == 0 ) {
   return i;
  }
 }
 return -1;
}

canonical_original_code:
int is_setting(char *av)
{
 int i;
 for ( i = 0; setting_table[i].name; i++ ) {
  if ( strcmp(setting_table[i].name, av) == 0 ) {
   return i;
  }
 }
 return -1;
}


decompiled_code:
__int64 __fastcall set_setting(__int64 a1, int a2)
{
return (*((__int64 (__fastcall **)(char *, __int64))&setting_table + 4 * a2 + 3))(
(char *)&setting_table + 32 * a2,
a1);
}

canonical_decompiled_code:
__int64 __fastcall func17(__int64 a1, int a2)
{
return (*((__int64 (__fastcall **)(char *, __int64))&setting_table + 4 * a2 + 3))(
(char *)&setting_table + 32 * a2,
a1);
}

original_code:
void set_setting( struct termios *ttyopts, int i, int on )
{
 setting_table[i].setter(&setting_table[i], ttyopts, on);
}

canonical_original_code:
void set_setting(struct termios *ttyopts, int i, int on)
{
 setting_table[i].setter(&setting_table[i], ttyopts, on);
}

variable_types: on int


decompiled_code:
int __fastcall s_opt(_DWORD *a1, const struct termios *a2, int *a3, int a4)
{
int v4; // eax
int result; // eax

v4 = *a3 & ~*a1;
if ( a4 == 1 )
v4 = *a1 | *a3;
*a3 = v4;
result = tcsetattr(0, 0, a2);
if ( result == -1 )
{
perror("tcsetattr");
exit(1);
}
return result;
}

canonical_decompiled_code:
int __fastcall func18(_DWORD *a1, const struct termios *a2, int *a3, int a4)
{
int v4; // eax
int result; // eax

v4 = *a3 & ~*a1;
if ( a4 == 1 )
v4 = *a1 | *a3;
*a3 = v4;
result = tcsetattr(0, 0, a2);
if ( result == -1 )
{
perror("tcsetattr");
exit(1);
}
return result;
}

original_code:
void s_opt( struct option *row,
   struct termios *ttyopts,
   tcflag_t *flag_p,
   int on )
{
 if ( on == 1 )
  *flag_p |= row->constant;
 else
  *flag_p &= ~(row->constant);
 if (tcsetattr(0, 0, ttyopts) == -1) {
  perror("tcsetattr");
  exit(1);
 }
}

canonical_original_code:
void s_opt(struct option *row, struct termios *ttyopts, unsigned int *flag_p, int on)
{
 if ( on == 1 )
  *flag_p |= row->constant;
 else
  *flag_p &= ~(row->constant);
 if (tcsetattr(0, 0, ttyopts) == -1) {
  perror("tcsetattr");
  exit(1);
 }
}

variable_types: struct option { unsigned int constant; char *name; void (*printer)(struct option *, struct termios { unsigned int c_iflag; unsigned int c_oflag; unsigned int c_cflag; unsigned int c_lflag; unsigned char c_line; unsigned char c_cc[32]; unsigned int c_ispeed; unsigned int c_ospeed; } *); void (*setter)(struct option *, struct termios *, int); } *

variable_types:
ttyopts
struct termios *

user_defined_types: struct option { unsigned int constant; char *name; void (*printer)(struct option *, struct termios *); void (*setter)(struct option *, struct termios *, int); }


decompiled_code:
int __fastcall s_in(_DWORD *a1, struct termios *a2, int a3)
{
return s_opt(a1, a2, (int *)a2, a3);
}

canonical_decompiled_code:
int __fastcall func19(_DWORD *a1, struct termios *a2, int a3)
{
return func18(a1, a2, (int *)a2, a3);
}

original_code:
void s_in( struct option *row, struct termios *ttyopts, int on )
{
 s_opt(row, ttyopts, &ttyopts->c_iflag, on);
}

canonical_original_code:
void s_in(struct option *row, struct termios *ttyopts, int on)
{
 s_opt(row, ttyopts, &ttyopts->c_iflag, on);
}


decompiled_code:
int __fastcall s_out(_DWORD *a1, const struct termios *a2, int a3)
{
return s_opt(a1, a2, (int *)&a2->c_oflag, a3);
}

canonical_decompiled_code:
int __fastcall func20(_DWORD *a1, const struct termios *a2, int a3)
{
return func18(a1, a2, (int *)&a2->c_oflag, a3);
}

original_code:
void s_out( struct option *row, struct termios *ttyopts, int on )
{
 s_opt(row, ttyopts, &ttyopts->c_oflag, on);
}

canonical_original_code:
void s_out(struct option *row, struct termios *ttyopts, int on)
{
 s_opt(row, ttyopts, &ttyopts->c_oflag, on);
}


decompiled_code:
int __fastcall s_local(_DWORD *a1, const struct termios *a2, int a3)
{
return s_opt(a1, a2, (int *)&a2->c_lflag, a3);
}

canonical_decompiled_code:
int __fastcall func21(_DWORD *a1, const struct termios *a2, int a3)
{
return func18(a1, a2, (int *)&a2->c_lflag, a3);
}

original_code:
void s_local( struct option *row, struct termios *ttyopts, int on )
{
 s_opt(row, ttyopts, &ttyopts->c_lflag, on);
}

canonical_original_code:
void s_local(struct option *row, struct termios *ttyopts, int on)
{
 s_opt(row, ttyopts, &ttyopts->c_lflag, on);
}


decompiled_code:
int __fastcall print_setting(__int64 a1)
{
void (__fastcall **v1)(void *, _QWORD); // rbx

if ( off_4040E8 )
{
v1 = (void (__fastcall **)(void *, _QWORD))&setting_table;
do
{
v1[2](v1, a1);
v1 += 4;
putchar(32);
}
while ( v1[1] );
}
return putchar(10);
}

canonical_decompiled_code:
int __fastcall func22(__int64 a1)
{
void (__fastcall **v1)(void *, _QWORD); // rbx

if ( off_4040E8 )
{
v1 = (void (__fastcall **)(void *, _QWORD))&setting_table;
do
{
v1[2](v1, a1);
v1 += 4;
putchar(32);
}
while ( v1[1] );
}
return putchar(10);
}

original_code:
void print_setting( struct termios *ttyopts )
{
 int i;
 for ( i = 0; setting_table[i].name; i++ ) {
  setting_table[i].printer(&setting_table[i], ttyopts);
  printf(" ");
 }
 printf("\n");
}

canonical_original_code:
void print_setting(struct termios *ttyopts)
{
 int i;
 for ( i = 0; setting_table[i].name; i++ ) {
  setting_table[i].printer(&setting_table[i], ttyopts);
  printf(" ");
 }
 printf("\n");
}


decompiled_code:
int __fastcall p_opt(__int64 a1, int a2)
{
int result; // eax

if ( (*(_DWORD *)a1 & a2) != 0 )
result = printf(*(const char **)(a1 + 8));
else
result = printf("-%s", *(const char **)(a1 + 8));
return result;
}

canonical_decompiled_code:
int __fastcall func23(__int64 a1, int a2)
{
int result; // eax

if ( (*(_DWORD *)a1 & a2) != 0 )
result = printf(*(const char **)(a1 + 8));
else
result = printf("-%s", *(const char **)(a1 + 8));
return result;
}

original_code:
void p_opt ( struct option *row, int flag)
{
 if ( flag & row->constant )
  printf(row->name);
 else
  printf("-%s", row->name);
}

canonical_original_code:
void p_opt(struct option *row, int flag)
{
 if ( flag & row->constant )
  printf(row->name);
 else
  printf("-%s", row->name);
}

variable_types: flag int


decompiled_code:
int __fastcall p_in(__int64 a1, int *a2)
{
return p_opt(a1, *a2);
}

canonical_decompiled_code:
int __fastcall func24(__int64 a1, int *a2)
{
return func23(a1, *a2);
}

original_code:
void p_in( struct option *row, struct termios *ttyopts )
{
 p_opt(row, ttyopts->c_iflag);
}

canonical_original_code:
void p_in(struct option *row, struct termios *ttyopts)
{
 p_opt(row, ttyopts->c_iflag);
}


decompiled_code:
int __fastcall p_out(__int64 a1, __int64 a2)
{
return p_opt(a1, *(_DWORD *)(a2 + 4));
}

canonical_decompiled_code:
int __fastcall func25(__int64 a1, __int64 a2)
{
return func23(a1, *(_DWORD *)(a2 + 4));
}

original_code:
void p_out( struct option *row, struct termios *ttyopts )
{
 p_opt(row, ttyopts->c_oflag);
}

canonical_original_code:
void p_out(struct option *row, struct termios *ttyopts)
{
 p_opt(row, ttyopts->c_oflag);
}


decompiled_code:
int __fastcall p_local(__int64 a1, __int64 a2)
{
return p_opt(a1, *(_DWORD *)(a2 + 12));
}

canonical_decompiled_code:
int __fastcall func26(__int64 a1, __int64 a2)
{
return func23(a1, *(_DWORD *)(a2 + 12));
}

original_code:
void p_local( struct option *row, struct termios *ttyopts )
{
 p_opt(row, ttyopts->c_lflag);
}

canonical_original_code:
void p_local(struct option *row, struct termios *ttyopts)
{
 p_opt(row, ttyopts->c_lflag);
}


decompiled_code:
__int64 __fastcall is_speed(char *s2)
{
const char *v2; // rdi
__int64 v3; // rbx

v2 = (const char *)off_4041E8;
if ( !off_4041E8 )
return 0xFFFFFFFFLL;
v3 = 0LL;
while ( strcmp(v2, s2) )
{
++v3;
v2 = (const char *)*(&off_4041E8 + 2 * v3);
if ( !v2 )
return 0xFFFFFFFFLL;
}
return (unsigned int)v3;
}

canonical_decompiled_code:
__int64 __fastcall func27(char *s2)
{
const char *v2; // rdi
__int64 v3; // rbx

v2 = (const char *)off_4041E8;
if ( !off_4041E8 )
return 0xFFFFFFFFLL;
v3 = 0LL;
while ( strcmp(v2, s2) )
{
++v3;
v2 = (const char *)*(&off_4041E8 + 2 * v3);
if ( !v2 )
return 0xFFFFFFFFLL;
}
return (unsigned int)v3;
}

original_code:
int is_speed( char *av )
{
 int i;
 for ( i = 0; baud[i].name; i++ ) {
  if ( strcmp(baud[i].name, av) == 0 ) {
   return i;
  }
 }
 return -1;
}

canonical_original_code:
int is_speed(char *av)
{
 int i;
 for ( i = 0; baud[i].name; i++ ) {
  if ( strcmp(baud[i].name, av) == 0 ) {
   return i;
  }
 }
 return -1;
}


decompiled_code:
int __fastcall set_speed(struct termios *termios_p, int a2)
{
int result; // eax

if ( cfsetospeed(termios_p, baud[4 * a2]) == -1 )
{
perror("cfsetospeed");
exit(1);
}
result = tcsetattr(0, 0, termios_p);
if ( result == -1 )
{
perror("tcsetattr");
exit(1);
}
return result;
}

canonical_decompiled_code:
int __fastcall func28(struct termios *termios_p, int a2)
{
int result; // eax

if ( cfsetospeed(termios_p, baud[4 * a2]) == -1 )
{
perror("cfsetospeed");
exit(1);
}
result = tcsetattr(0, 0, termios_p);
if ( result == -1 )
{
perror("tcsetattr");
exit(1);
}
return result;
}

original_code:
void set_speed( struct termios *ttyopts, int i )
{
 if ( cfsetospeed(ttyopts, baud[i].constant) == -1 ) {
  perror("cfsetospeed");
  exit(1);
 }
 if (tcsetattr(0, 0, ttyopts) == -1) {
  perror("tcsetattr");
  exit(1);
 }
}

canonical_original_code:
void set_speed(struct termios *ttyopts, int i)
{
 if ( cfsetospeed(ttyopts, baud[i].constant) == -1 ) {
  perror("cfsetospeed");
  exit(1);
 }
 if (tcsetattr(0, 0, ttyopts) == -1) {
  perror("tcsetattr");
  exit(1);
 }
}


decompiled_code:
speed_t __fastcall print_speed(const struct termios *a1)
{
speed_t result; // eax
const char *v2; // rsi
speed_t v3; // ebp
int *v4; // rbx

result = cfgetospeed(a1);
v2 = (const char *)off_4041E8;
if ( off_4041E8 )
{
v3 = result;
v4 = baud;
do
{
while ( v3 != *v4 )
{
v2 = (const char *)*((_QWORD *)v4 + 3);
v4 += 4;
if ( !v2 )
return result;
}
v4 += 4;
result = printf("speed %s baud;\n", v2);
v2 = (const char *)*((_QWORD *)v4 + 1);
}
while ( v2 );
}
return result;
}

canonical_decompiled_code:
speed_t __fastcall func29(const struct termios *a1)
{
speed_t result; // eax
const char *v2; // rsi
speed_t v3; // ebp
int *v4; // rbx

result = cfgetospeed(a1);
v2 = (const char *)off_4041E8;
if ( off_4041E8 )
{
v3 = result;
v4 = baud;
do
{
while ( v3 != *v4 )
{
v2 = (const char *)*((_QWORD *)v4 + 3);
v4 += 4;
if ( !v2 )
return result;
}
v4 += 4;
result = printf("speed %s baud;\n", v2);
v2 = (const char *)*((_QWORD *)v4 + 1);
}
while ( v2 );
}
return result;
}

original_code:
void print_speed( struct termios *ttyopts )
{
 int cfospeed = cfgetospeed(ttyopts);
 int i;
 for ( i = 0; baud[i].name; i++ ) {
  if ( cfospeed == baud[i].constant ) {
   printf("speed %s baud;\n", baud[i].name);
  }
 }
}

canonical_original_code:
void print_speed(struct termios *ttyopts)
{
 int cfospeed = cfgetospeed(ttyopts);
 int i;
 for ( i = 0; baud[i].name; i++ ) {
  if ( cfospeed == baud[i].constant ) {
   printf("speed %s baud;\n", baud[i].name);
  }
 }
}

variable_types: cfospeed int


contar

decompiled_code:
__int64 __fastcall contar(__int64 a1)
{
unsigned int v1; // er12
__int64 v2; // rbx
int v3; // eax

v1 = 0;
if ( a1 )
{
v2 = a1;
do
{
v3 = contar(*(_QWORD *)(v2 + 8));
v2 = *(_QWORD *)(v2 + 16);
v1 += v3 + 1;
}
while ( v2 );
}
return v1;
}

original_code:
int contar(Nodo* raiz)
{
    if(raiz==((void *)0))
    {
        return 0;
    }
    return 1+contar(raiz->der)+contar(raiz->izq);
}

canonical_original_code:
int contar(struct NodoArbol *raiz)
{
    if(raiz==((void *)0))
    {
        return 0;
    }
    return 1+contar(raiz->der)+contar(raiz->izq);
}

variable_types: struct NodoArbol { int dato; struct NodoArbol *der; struct NodoArbol *izq; } *


decompiled_code:
__int64 __fastcall insertar_ordenado(unsigned int a1, int a2, __int64 a3, __int64 a4)
{
unsigned int v6; // ebx
__int64 v8; // rax
__int64 v9; // rdi
__int64 v10; // rax
int v11; // edx

v6 = a1 + (int)(a2 - a1) / 2;
if ( (int)(a2 - a1) > 2 )
{
do
{
v8 = insertar_elemento(a4, *(unsigned int *)(a3 + 4LL * (int)v6));
v9 = a1;
a1 = v6;
v10 = insertar_ordenado(v9, v6, a3, v8);
v11 = a2 - v6;
a4 = v10;
v6 += (int)(a2 - v6) / 2;
}
while ( v11 > 2 );
}
return a4;
}

canonical_decompiled_code:
__int64 __fastcall func1(unsigned int a1, int a2, __int64 a3, __int64 a4)
{
unsigned int v6; // ebx
__int64 v8; // rax
__int64 v9; // rdi
__int64 v10; // rax
int v11; // edx

v6 = a1 + (int)(a2 - a1) / 2;
if ( (int)(a2 - a1) > 2 )
{
do
{
v8 = insertar_elemento(a4, *(unsigned int *)(a3 + 4LL * (int)v6));
v9 = a1;
a1 = v6;
v10 = func1(v9, v6, a3, v8);
v11 = a2 - v6;
a4 = v10;
v6 += (int)(a2 - v6) / 2;
}
while ( v11 > 2 );
}
return a4;
}

original_code:
Nodo* insertar_ordenado(int inicio,int final,int *datos,Nodo* raiz)
{
    int mitad;
    mitad=(final-inicio)/2+inicio;
    if(final-inicio>2)
    {
        raiz=insertar_elemento(raiz,datos[mitad]);
        raiz=insertar_ordenado(inicio,mitad,datos,raiz);
        raiz=insertar_ordenado(mitad,final,datos,raiz);
    }
    return raiz;
}

canonical_original_code:
struct NodoArbol *insertar_ordenado(int inicio, int final, int *datos, struct NodoArbol *raiz)
{
    int mitad;
    mitad=(final-inicio)/2+inicio;
    if(final-inicio>2)
    {
        raiz=insertar_elemento(raiz,datos[mitad]);
        raiz=insertar_ordenado(inicio,mitad,datos,raiz);
        raiz=insertar_ordenado(mitad,final,datos,raiz);
    }
    return raiz;
}

variable_types: inicio int

variable_types: final int

variable_types:
datos
int *

variable_types:
raiz
struct NodoArbol *

variable_types: mitad int

return_type: struct NodoArbol { int dato; struct NodoArbol *der; struct NodoArbol *izq; } *


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

v2 = ftok(a1, a2);
if ( v2 < 0 )
{
fwrite("\nError creando token de cola.\n\n", 1uLL, 0x1FuLL, stderr);
result = -1;
}
else
{
result = msgget(v2, 896);
if ( result < 0 )
{
fwrite(&unk_A18, 1uLL, 0x29uLL, stderr);
result = -1;
}
}
return result;
}

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

v2 = ftok(a1, a2);
if ( v2 < 0 )
{
fwrite("\nError creando token de cola.\n\n", 1uLL, 0x1FuLL, stderr);
result = -1;
}
else
{
result = msgget(v2, 896);
if ( result < 0 )
{
fwrite(&unk_A18, 1uLL, 0x29uLL, stderr);
result = -1;
}
}
return result;
}

original_code:
int inicializar_cola(char nombre[], char id)
{
    int cola;
    key_t llave = ftok(nombre, id);
    if(llave < 0)
    {
        fprintf(stderr, "\nError creando token de cola.\n\n");
        return -1;
    }
    cola = msgget(llave, 0600 | 01000);
    if(cola < 0)
    {
        fprintf(stderr, "\nError durante la creación de la cola.\n\n");
        return -1;
    }
    return cola;
}

canonical_original_code:
int inicializar_cola(char nombre[], char id)
{
    int cola;
    int llave = ftok(nombre, id);
    if(llave < 0)
    {
        fprintf(stderr, "\nError creando token de cola.\n\n");
        return -1;
    }
    cola = msgget(llave, 0600 | 01000);
    if(cola < 0)
    {
        fprintf(stderr, "\nError durante la creación de la cola.\n\n");
        return -1;
    }
    return cola;
}

variable_types:
nombre
char []

variable_types: id char

variable_types: cola int

variable_types: llave int


decompiled_code:
_BOOL8 __fastcall es_cola_correcta(int a1)
{
return a1 >= 0;
}

canonical_decompiled_code:
_BOOL8 __fastcall func1(int a1)
{
return a1 >= 0;
}

original_code:
int es_cola_correcta(int cola)
{
    return cola >= 0;
}


decompiled_code:
int __fastcall inicializar_memoria_compartida(const char *a1, char a2)
{
int v2; // eax
int result; // eax
int *v4; // rax
int *v5; // rax

v2 = ftok(a1, a2);
if ( v2 < 0 )
{
v4 = _errno_location();
printf(&format, (unsigned int)*v4);
result = -1;
}
else
{
result = shmget(v2, 4uLL, 896);
if ( result < 0 )
{
v5 = _errno_location();
printf(&byte_A90, (unsigned int)*v5);
result = -1;
}
}
return result;
}

canonical_decompiled_code:
int __fastcall func2(const char *a1, char a2)
{
int v2; // eax
int result; // eax
int *v4; // rax
int *v5; // rax

v2 = ftok(a1, a2);
if ( v2 < 0 )
{
v4 = _errno_location();
printf(&format, (unsigned int)*v4);
result = -1;
}
else
{
result = shmget(v2, 4uLL, 896);
if ( result < 0 )
{
v5 = _errno_location();
printf(&byte_A90, (unsigned int)*v5);
result = -1;
}
}
return result;
}

original_code:
int inicializar_memoria_compartida(char nombre[], char id)
{
    int memoria;
    key_t keymemo=ftok(nombre,id);
    if(keymemo < 0)
    {
        printf("¡Error! Fallo recuperando token de mem. compartida. [ERROR %d]\n", (*__errno_location ()));
        return -1;
    }
    memoria = shmget(keymemo, sizeof(int), 01000 | 0600);
    if(memoria < 0)
    {
        printf("¡Error! No se pudo acceder a la memoria compartida, [ERROR %d]\n", (*__errno_location ()));
        return -1;
    }
    return memoria;
}

canonical_original_code:
int inicializar_memoria_compartida(char nombre[], char id)
{
    int memoria;
    int keymemo = ftok(nombre,id);
    if(keymemo < 0)
    {
        printf("¡Error! Fallo recuperando token de mem. compartida. [ERROR %d]\n", (*__errno_location ()));
        return -1;
    }
    memoria = shmget(keymemo, sizeof(int), 01000 | 0600);
    if(memoria < 0)
    {
        printf("¡Error! No se pudo acceder a la memoria compartida, [ERROR %d]\n", (*__errno_location ()));
        return -1;
    }
    return memoria;
}

variable_types: memoria int

variable_types: keymemo int


decompiled_code:
// attributes: thunk
_BOOL8 __fastcall es_memoria_correcta(int a1)
{
return es_cola_correcta(a1);
}

canonical_decompiled_code:
_BOOL8 __fastcall func3(int a1)
{
return func1(a1);
}

original_code:
int es_memoria_correcta(int memoria_compartida)
{
    return memoria_compartida >= 0;
}


decompiled_code:
_BOOL8 __fastcall es_semaforo_correcto(__int64 a1)
{
return a1 != 0;
}

canonical_decompiled_code:
_BOOL8 __fastcall func4(__int64 a1)
{
return a1 != 0;
}

original_code:
int es_semaforo_correcto(sem_t *semaforo)
{
    return semaforo != ((void *)0);
}

canonical_original_code:
int es_semaforo_correcto(union sem_t *semaforo)
{
    return semaforo != ((void *)0);
}

variable_types: union sem_t { char __size[32]; long __align; } *


decompiled_code:
void *__fastcall inicializar_clientes(int a1)
{
return malloc(40LL * a1);
}

canonical_decompiled_code:
void *__fastcall func5(int a1)
{
return malloc(40LL * a1);
}

original_code:
int *inicializar_clientes(int numero_clientes)
{
    size_t tamanyo_memoria = 10 * sizeof(pid_t) * (size_t)numero_clientes;
    return (int *)malloc(tamanyo_memoria);
}

canonical_original_code:
int *inicializar_clientes(int numero_clientes)
{
    unsigned long tamanyo_memoria = 10 * sizeof(pid_t) * (size_t)numero_clientes;
    return (int *)malloc(tamanyo_memoria);
}

return_type: int *


decompiled_code:
// attributes: thunk
_BOOL8 __fastcall son_clientes_correctos(__int64 a1)
{
return es_semaforo_correcto(a1);
}

canonical_decompiled_code:
_BOOL8 __fastcall func6(__int64 a1)
{
return func4(a1);
}

original_code:
int son_clientes_correctos(int *clientes)
{
    return clientes != ((void *)0);
}

variable_types:
clientes
int *


decompiled_code:
void *__fastcall get_inicio_memoria_compartida(int a1)
{
return shmat(a1, 0LL, 0);
}

canonical_decompiled_code:
void *__fastcall func7(int a1)
{
return shmat(a1, 0LL, 0);
}

original_code:
int *get_inicio_memoria_compartida(int memoria_compartida)
{
    return (int *)shmat(memoria_compartida, 0, 0);
}


decompiled_code:
// attributes: thunk
_BOOL8 __fastcall es_arbol_correcto(__int64 a1)
{
return es_semaforo_correcto(a1);
}

canonical_decompiled_code:
_BOOL8 __fastcall func8(__int64 a1)
{
return func4(a1);
}

original_code:
int es_arbol_correcto(Nodo *arbol)
{
    return arbol != ((void *)0);
}

canonical_original_code:
int es_arbol_correcto(struct NodoArbol *arbol)
{
    return arbol != ((void *)0);
}

user_defined_types: struct NodoArbol { int dato; struct NodoArbol *der; struct NodoArbol *izq; }


decompiled_code:
int __fastcall borrar_cola(int a1)
{
return msgctl(a1, 0, 0LL);
}

canonical_decompiled_code:
int __fastcall func9(int a1)
{
return msgctl(a1, 0, 0LL);
}

original_code:
void borrar_cola(int cola)
{
    msgctl(cola, 0, 0);
}


decompiled_code:
void __fastcall cerrar_clientes(__int64 a1, int a2)
{
__pid_t *v2; // rbx
__int64 v3; // rbp
__pid_t v4; // edi

if ( es_semaforo_correcto(a1) )
{
if ( a2 > 0 )
{
v2 = (__pid_t *)a1;
v3 = a1 + 4LL * (unsigned int)(a2 - 1) + 4;
do
{
v4 = *v2++;
kill(v4, 2);
}
while ( v2 != (__pid_t *)v3 );
}
free(vector_clientes);
}
}

canonical_decompiled_code:
void __fastcall func10(__int64 a1, int a2)
{
__pid_t *v2; // rbx
__int64 v3; // rbp
__pid_t v4; // edi

if ( func4(a1) )
{
if ( a2 > 0 )
{
v2 = (__pid_t *)a1;
v3 = a1 + 4LL * (unsigned int)(a2 - 1) + 4;
do
{
v4 = *v2++;
kill(v4, 2);
}
while ( v2 != (__pid_t *)v3 );
}
free(vector_clientes);
}
}

original_code:
void cerrar_clientes(int *clientes, int numero_clientes)
{
    if (!son_clientes_correctos(clientes))
        return;
    int i;
    for(i = 0; i < numero_clientes; i++)
    {
        kill(clientes[i], 2);
    }
    free(vector_clientes);
}

variable_types: i int


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

result = es_semaforo_correcto((__int64)a1);
if ( result )
{
sem_close(a1);
result = sem_unlink(a2);
}
return result;
}

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

result = func4((__int64)a1);
if ( result )
{
sem_close(a1);
result = sem_unlink(a2);
}
return result;
}

original_code:
void cerrar_semaforo(sem_t *semaforo, char nombre[])
{
    if (!es_semaforo_correcto(semaforo))
        return;
    sem_close(semaforo);
    sem_unlink(nombre);
}

canonical_original_code:
void cerrar_semaforo(union sem_t *semaforo, char nombre[])
{
    if (!es_semaforo_correcto(semaforo))
        return;
    sem_close(semaforo);
    sem_unlink(nombre);
}

user_defined_types: union sem_t { char __size[32]; long __align; }


decompiled_code:
int __fastcall liberar_memoria_compartida(int a1)
{
int result; // eax

result = es_cola_correcta(a1);
if ( result )
result = shmctl(a1, 0, 0LL);
return result;
}

canonical_decompiled_code:
int __fastcall func12(int a1)
{
int result; // eax

result = func1(a1);
if ( result )
result = shmctl(a1, 0, 0LL);
return result;
}

original_code:
void liberar_memoria_compartida(int memoria_compartida)
{
    if (!es_memoria_correcta(memoria_compartida))
        return;
    shmctl(memoria_compartida, 0, 0);
}


decompiled_code:
int __fastcall registrando_en_logfile(int a1)
{
struct tm *v1; // rax
int result; // eax
int v3; // [rsp-10h] [rbp-48h]
time_t timer; // [rsp+8h] [rbp-30h] BYREF
char s[40]; // [rsp+10h] [rbp-28h] BYREF

timer = time(0LL);
v1 = gmtime(&timer);
result = strftime(s, 0x14uLL, "%Y-%m-%d %H:%M:%S", v1);
switch ( a1 )
{
case 2:
fprintf(
logfile,
aSClienteLdOper,
s,
peticion,
*((unsigned int *)&peticion + 2),
*(unsigned int *)dato,
respuesta[2]);
result = v3;
break;
case 3:
result = fprintf(logfile, "\n******************%s SERVIDOR CERRADO******************\n\n", s);
break;
case 1:
result = fprintf(
logfile,
"\n\n*****%s SERVIDOR INICIADO CON %d CLIENTES MAXIMOS*****\n",
s,
(unsigned int)max_clientes);
break;
}
return result;
}

canonical_decompiled_code:
int __fastcall func13(int a1)
{
struct tm *v1; // rax
int result; // eax
int v3; // [rsp-10h] [rbp-48h]
time_t timer; // [rsp+8h] [rbp-30h] BYREF
char s[40]; // [rsp+10h] [rbp-28h] BYREF

timer = time(0LL);
v1 = gmtime(&timer);
result = strftime(s, 0x14uLL, "%Y-%m-%d %H:%M:%S", v1);
switch ( a1 )
{
case 2:
fprintf(
logfile,
aSClienteLdOper,
s,
peticion,
*((unsigned int *)&peticion + 2),
*(unsigned int *)dato,
respuesta[2]);
result = v3;
break;
case 3:
result = fprintf(logfile, "\n******************%s SERVIDOR CERRADO******************\n\n", s);
break;
case 1:
result = fprintf(
logfile,
"\n\n*****%s SERVIDOR INICIADO CON %d CLIENTES MAXIMOS*****\n",
s,
(unsigned int)max_clientes);
break;
}
return result;
}

original_code:
void registrando_en_logfile(int tipo_operacion)
{
    char buff[20];
    struct tm *sTm;
    time_t now = time (0);
    sTm = gmtime (&now);
    strftime (buff, sizeof(buff), "%Y-%m-%d %H:%M:%S", sTm);
    switch(tipo_operacion)
    {
        case 1:
        fprintf(logfile,"\n\n*****%s SERVIDOR INICIADO CON %d CLIENTES MAXIMOS*****\n",buff,max_clientes);
        break;
        case 2:
        fprintf(logfile,"%s: Cliente: %ld -> Operación: %d -> Dato: %d -> Respuesta del servidor: %d   \n", buff, peticion.tipo,peticion.codigo_operacion, *dato, respuesta.codigo_error);
        break;
        case 3:
                fprintf(logfile,"\n******************%s SERVIDOR CERRADO******************\n\n",buff);
        break;
    }
    return;
}

canonical_original_code:
void registrando_en_logfile(int tipo_operacion)
{
    char buff[20];
    struct tm *sTm;
    long now = time (0);
    sTm = gmtime (&now);
    strftime (buff, sizeof(buff), "%Y-%m-%d %H:%M:%S", sTm);
    switch(tipo_operacion)
    {
        case 1:
        fprintf(logfile,"\n\n*****%s SERVIDOR INICIADO CON %d CLIENTES MAXIMOS*****\n",buff,max_clientes);
        break;
        case 2:
        fprintf(logfile,"%s: Cliente: %ld -> Operación: %d -> Dato: %d -> Respuesta del servidor: %d   \n", buff, peticion.tipo,peticion.codigo_operacion, *dato, respuesta.codigo_error);
        break;
        case 3:
                fprintf(logfile,"\n******************%s SERVIDOR CERRADO******************\n\n",buff);
        break;
    }
    return;
}

variable_types:
buff
char [20]

variable_types: struct tm { int tm_sec; int tm_min; int tm_hour; int tm_mday; int tm_mon; int tm_year; int tm_wday; int tm_yday; int tm_isdst; long tm_gmtoff; char *tm_zone; } *

variable_types: now long


decompiled_code:
_BOOL8 preparar_entorno()
{
_BOOL4 v0; // er12
_BOOL8 result; // rax

puts("Creando colas...");
Q1 = inicializar_cola("/bin", 51);
if ( es_cola_correcta(Q1) )
{
Q2 = inicializar_cola("/bin", 52);
v0 = es_cola_correcta(Q2);
if ( !v0 )
{
puts("\nNo se pudo crear la cola 2.\n");
return v0;
}
Q_clientes_activos = inicializar_cola("/bin", 55);
if ( es_cola_correcta(Q_clientes_activos) )
{
puts("Creando memoria compartida...");
memo = inicializar_memoria_compartida("/bin", 53);
v0 = es_cola_correcta(memo);
if ( v0 )
{
puts("Creando semaforos...");
mutex = inicializar_semaforo("/semMUTEX", 1u);
v0 = es_semaforo_correcto((__int64)mutex);
if ( v0 )
{
s1 = inicializar_semaforo("/semS1", max_clientes);
v0 = es_semaforo_correcto((__int64)s1);
if ( v0 )
{
sclientes = inicializar_semaforo("/semSCLIENTES", 1u);
v0 = es_semaforo_correcto((__int64)sclientes);
if ( v0 )
{
vector_clientes = inicializar_clientes(max_clientes);
v0 = es_semaforo_correcto((__int64)vector_clientes);
if ( v0 )
{
puts("Cargando datos del arbol desde el fichero...");
raizarbol = cargar_ordenado(raizarbol);
v0 = es_semaforo_correcto(raizarbol);
if ( v0 )
{
signal(2, cerrar_programa);
dato = (__int64)get_inicio_memoria_compartida(memo);
puts("Creando fichero para guardar el log del sistema...");
logfile = fopen("servidor.log", "a");
if ( logfile )
{
v0 = 1;
registrando_en_logfile(1);
}
else
{
v0 = 0;
puts(asc_D90);
}
}
else
{
puts(&byte_D30);
}
}
else
{
puts("\nError inicializando espacio de clientes.\n");
}
}
else
{
puts("\nError inicializando semaforo SCLIENTES.\n");
}
}
else
{
puts("\nError inicializando semaforo S1.\n");
}
}
else
{
puts("\nError inicializando semaforo MutEx.\n");
}
}
else
{
puts("\nNo se pudo inicializar la memoria compartida.\n");
}
return v0;
}
puts("\nNo se pudo crear la cola clientes-activos.\n");
result = 0LL;
}
else
{
puts("\nNo se pudo crear la cola 1.\n");
result = 0LL;
}
return result;
}

canonical_decompiled_code:
_BOOL8 func14()
{
_BOOL4 v0; // er12
_BOOL8 result; // rax

puts("Creando colas...");
Q1 = func0("/bin", 51);
if ( func1(Q1) )
{
Q2 = func0("/bin", 52);
v0 = func1(Q2);
if ( !v0 )
{
puts("\nNo se pudo crear la cola 2.\n");
return v0;
}
Q_clientes_activos = func0("/bin", 55);
if ( func1(Q_clientes_activos) )
{
puts("Creando memoria compartida...");
memo = func2("/bin", 53);
v0 = func1(memo);
if ( v0 )
{
puts("Creando semaforos...");
mutex = inicializar_semaforo("/semMUTEX", 1u);
v0 = func4((__int64)mutex);
if ( v0 )
{
s1 = inicializar_semaforo("/semS1", max_clientes);
v0 = func4((__int64)s1);
if ( v0 )
{
sclientes = inicializar_semaforo("/semSCLIENTES", 1u);
v0 = func4((__int64)sclientes);
if ( v0 )
{
vector_clientes = func5(max_clientes);
v0 = func4((__int64)vector_clientes);
if ( v0 )
{
puts("Cargando datos del arbol desde el fichero...");
raizarbol = cargar_ordenado(raizarbol);
v0 = func4(raizarbol);
if ( v0 )
{
signal(2, cerrar_programa);
dato = (__int64)func7(memo);
puts("Creando fichero para guardar el log del sistema...");
logfile = fopen("servidor.log", "a");
if ( logfile )
{
v0 = 1;
func13(1);
}
else
{
v0 = 0;
puts(asc_D90);
}
}
else
{
puts(&byte_D30);
}
}
else
{
puts("\nError inicializando espacio de clientes.\n");
}
}
else
{
puts("\nError inicializando semaforo SCLIENTES.\n");
}
}
else
{
puts("\nError inicializando semaforo S1.\n");
}
}
else
{
puts("\nError inicializando semaforo MutEx.\n");
}
}
else
{
puts("\nNo se pudo inicializar la memoria compartida.\n");
}
return v0;
}
puts("\nNo se pudo crear la cola clientes-activos.\n");
result = 0LL;
}
else
{
puts("\nNo se pudo crear la cola 1.\n");
result = 0LL;
}
return result;
}

original_code:
int preparar_entorno()
{
    printf("Creando colas...\n");
    Q1 = inicializar_cola("/bin", '3');
    if(!es_cola_correcta(Q1))
    {
        printf("\nNo se pudo crear la cola 1.\n\n");
        return 0;
    }
    Q2 = inicializar_cola("/bin", '4');
    if (!es_cola_correcta(Q2))
    {
        printf("\nNo se pudo crear la cola 2.\n\n");
        return 0;
    }
    Q_clientes_activos = inicializar_cola("/bin", '7');
    if (!es_cola_correcta(Q_clientes_activos))
    {
        printf("\nNo se pudo crear la cola clientes-activos.\n\n");
        return 0;
    }
    printf("Creando memoria compartida...\n");
    memo = inicializar_memoria_compartida("/bin", '5');
    if(!es_memoria_correcta(memo))
    {
        printf("\nNo se pudo inicializar la memoria compartida.\n\n");
        return 0;
    }
    printf("Creando semaforos...\n");
    mutex = inicializar_semaforo("/semMUTEX", 1);
    if (!es_semaforo_correcto(mutex))
    {
        printf("\nError inicializando semaforo MutEx.\n\n");
        return 0;
    }
    s1 = inicializar_semaforo("/semS1", max_clientes);
    if(!es_semaforo_correcto(s1))
    {
        printf("\nError inicializando semaforo S1.\n\n");
        return 0;
    }
    sclientes = inicializar_semaforo("/semSCLIENTES", 1);
    if(!es_semaforo_correcto(sclientes))
    {
        printf("\nError inicializando semaforo SCLIENTES.\n\n");
        return 0;
    }
    vector_clientes = inicializar_clientes(max_clientes);
    if (!son_clientes_correctos(vector_clientes))
    {
        printf("\nError inicializando espacio de clientes.\n\n");
        return 0;
    }
    printf("Cargando datos del arbol desde el fichero...\n");
    raizarbol=cargar_ordenado(raizarbol);
    if(!es_arbol_correcto(raizarbol))
    {
        printf("¡Error! No se pudo cargar el arbol.\n");
        return 0;
    }
    signal (2,cerrar_programa);
    dato = get_inicio_memoria_compartida(memo);
    printf("Creando fichero para guardar el log del sistema...\n");
    logfile=fopen("servidor.log","a");
    if(logfile==((void *)0))
    {
        printf("\nError en la apertura/creación del log.\n\n");
        return 0;
    }
    registrando_en_logfile(1);
    return 1;
}


decompiled_code:
void __noreturn cerrar_programa()
{
puts("Cerrando el control de clientes inactivos...");
puts("Guardando datos del arbol en el fichero...");
guardar_fichero(raizarbol);
puts("Cerrando log del servidor...");
registrando_en_logfile(3);
fclose(logfile);
puts("Cerrando clientes...");
cerrar_clientes((__int64)vector_clientes, num_clientes);
puts("Cerrando colas...");
borrar_cola(Q1);
borrar_cola(Q2);
borrar_cola(Q_clientes_activos);
puts("Cerrando semaforos...");
cerrar_semaforo(mutex, "/semMUTEX");
cerrar_semaforo(s1, "/semS1");
cerrar_semaforo(sclientes, "/semSCLIENTES");
puts("Cerrando memoria compartida...");
liberar_memoria_compartida(memo);
exit(0);
}

canonical_decompiled_code:
void __noreturn func15()
{
puts("Cerrando el control de clientes inactivos...");
puts("Guardando datos del arbol en el fichero...");
guardar_fichero(raizarbol);
puts("Cerrando log del servidor...");
func13(3);
fclose(logfile);
puts("Cerrando clientes...");
func10((__int64)vector_clientes, num_clientes);
puts("Cerrando colas...");
func9(Q1);
func9(Q2);
func9(Q_clientes_activos);
puts("Cerrando semaforos...");
func11(mutex, "/semMUTEX");
func11(s1, "/semS1");
func11(sclientes, "/semSCLIENTES");
puts("Cerrando memoria compartida...");
func12(memo);
exit(0);
}

original_code:
void cerrar_programa(int sig)
{
    printf("Cerrando el control de clientes inactivos...\n");
    printf("Guardando datos del arbol en el fichero...\n");
    guardar_fichero(raizarbol);
    printf("Cerrando log del servidor...\n");
    registrando_en_logfile(3);
    fclose(logfile);
    printf("Cerrando clientes...\n");
    cerrar_clientes(vector_clientes, num_clientes);
    printf("Cerrando colas...\n");
    borrar_cola(Q1);
    borrar_cola(Q2);
    borrar_cola(Q_clientes_activos);
    printf("Cerrando semaforos...\n");
    cerrar_semaforo(mutex, "/semMUTEX");
    cerrar_semaforo(s1, "/semS1");
    cerrar_semaforo(sclientes,"/semSCLIENTES");
    printf("Cerrando memoria compartida...\n");
    liberar_memoria_compartida(memo);
    exit(0);
}

variable_types: sig int


decompiled_code:
int operacion_arbol()
{
unsigned int v0; // ebx
__int64 v1; // rax
sem_t *v2; // rdi
int result; // eax
sem_t *v4; // rdi
__int64 v5; // rax
sem_t *v6; // rdi
unsigned int *v7; // rax
sem_t *v8; // rdi

v0 = *((_DWORD *)&peticion + 2);
switch ( v0 )
{
case 0u:
printf(
"Peticion de alta del cliente %d/%d, con pid %ld\n",
(unsigned int)(num_clientes + 1),
(unsigned int)max_clientes,
peticion);
v4 = sclientes;
*((_DWORD *)vector_clientes + num_clientes) = peticion;
sem_wait(v4);
++num_clientes;
sem_post(sclientes);
respuesta[2] = 0;
return registrando_en_logfile(2);
case 1u:
sem_wait(mutex);
v5 = insertar_elemento(raizarbol, *(unsigned int *)dato);
v6 = mutex;
respuesta[2] = 0;
raizarbol = v5;
sem_post(v6);
return registrando_en_logfile(2);
case 2u:
sem_wait(mutex);
v7 = (unsigned int *)dato;
respuesta[2] = 0;
raizarbol = borrar(raizarbol, *v7);
sem_post(mutex);
return registrando_en_logfile(2);
case 3u:
sem_wait(mutex);
v1 = buscar(raizarbol, *(unsigned int *)dato);
v2 = mutex;
if ( v1 )
v0 = 2;
respuesta[2] = v0;
sem_post(v2);
goto LABEL_5;
case 4u:
if ( (unsigned int)baja((unsigned int)peticion) == 1 )
{
sem_wait(sclientes);
--num_clientes;
sem_post(sclientes);
printf(
"Peticion de baja del cliente %ld, clientes conectados %d/%d\n",
peticion,
(unsigned int)num_clientes,
(unsigned int)max_clientes);
v8 = s1;
respuesta[2] = 0;
sem_post(v8);
LABEL_5:
result = registrando_en_logfile(2);
}
else
{
respuesta[2] = 1;
result = registrando_en_logfile(2);
}
return result;
default:
goto LABEL_5;
}
}

canonical_decompiled_code:
int func16()
{
unsigned int v0; // ebx
__int64 v1; // rax
sem_t *v2; // rdi
int result; // eax
sem_t *v4; // rdi
__int64 v5; // rax
sem_t *v6; // rdi
unsigned int *v7; // rax
sem_t *v8; // rdi

v0 = *((_DWORD *)&peticion + 2);
switch ( v0 )
{
case 0u:
printf(
"Peticion de alta del cliente %d/%d, con pid %ld\n",
(unsigned int)(num_clientes + 1),
(unsigned int)max_clientes,
peticion);
v4 = sclientes;
*((_DWORD *)vector_clientes + num_clientes) = peticion;
sem_wait(v4);
++num_clientes;
sem_post(sclientes);
respuesta[2] = 0;
return func13(2);
case 1u:
sem_wait(mutex);
v5 = insertar_elemento(raizarbol, *(unsigned int *)dato);
v6 = mutex;
respuesta[2] = 0;
raizarbol = v5;
sem_post(v6);
return func13(2);
case 2u:
sem_wait(mutex);
v7 = (unsigned int *)dato;
respuesta[2] = 0;
raizarbol = borrar(raizarbol, *v7);
sem_post(mutex);
return func13(2);
case 3u:
sem_wait(mutex);
v1 = buscar(raizarbol, *(unsigned int *)dato);
v2 = mutex;
if ( v1 )
v0 = 2;
respuesta[2] = v0;
sem_post(v2);
goto LABEL_5;
case 4u:
if ( (unsigned int)baja((unsigned int)peticion) == 1 )
{
sem_wait(sclientes);
--num_clientes;
sem_post(sclientes);
printf(
"Peticion de baja del cliente %ld, clientes conectados %d/%d\n",
peticion,
(unsigned int)num_clientes,
(unsigned int)max_clientes);
v8 = s1;
respuesta[2] = 0;
sem_post(v8);
LABEL_5:
result = func13(2);
}
else
{
respuesta[2] = 1;
result = func13(2);
}
return result;
default:
goto LABEL_5;
}
}

original_code:
void operacion_arbol(void)
{
    switch(peticion.codigo_operacion)
    {
    case 0:
        printf("Peticion de alta del cliente %d/%d, con pid %ld\n",num_clientes+1,max_clientes,peticion.tipo);
        vector_clientes[num_clientes]=peticion.tipo;
        sem_wait(sclientes);
        num_clientes++;
        sem_post(sclientes);
        respuesta.codigo_error=0;
        break;
    case 1:
        sem_wait(mutex);
        raizarbol=insertar_elemento(raizarbol,*dato);
        respuesta.codigo_error=0;
        sem_post(mutex);
        break;
    case 2:
        sem_wait(mutex);
        respuesta.codigo_error=0;
        raizarbol=borrar(raizarbol,*dato);
        sem_post(mutex);
        break;
    case 3:
        sem_wait(mutex);
        if(buscar(raizarbol,*dato)!=((void *)0))
        {
            respuesta.codigo_error=2;
        }
        else
        {
            respuesta.codigo_error=3;
        }
        sem_post(mutex);
        break;
    case 4:
        if(baja(peticion.tipo)==1)
        {
            sem_wait(sclientes);
            num_clientes--;
            sem_post(sclientes);
            printf("Peticion de baja del cliente %ld, clientes conectados %d/%d\n",peticion.tipo,num_clientes,max_clientes);
            respuesta.codigo_error=0;
            sem_post(s1);
        }
        else
        {
            respuesta.codigo_error=1;
        }
        break;
    }
    registrando_en_logfile(2);
   return;
}

canonical_original_code:
void operacion_arbol()
{
    switch(peticion.codigo_operacion)
    {
    case 0:
        printf("Peticion de alta del cliente %d/%d, con pid %ld\n",num_clientes+1,max_clientes,peticion.tipo);
        vector_clientes[num_clientes]=peticion.tipo;
        sem_wait(sclientes);
        num_clientes++;
        sem_post(sclientes);
        respuesta.codigo_error=0;
        break;
    case 1:
        sem_wait(mutex);
        raizarbol=insertar_elemento(raizarbol,*dato);
        respuesta.codigo_error=0;
        sem_post(mutex);
        break;
    case 2:
        sem_wait(mutex);
        respuesta.codigo_error=0;
        raizarbol=borrar(raizarbol,*dato);
        sem_post(mutex);
        break;
    case 3:
        sem_wait(mutex);
        if(buscar(raizarbol,*dato)!=((void *)0))
        {
            respuesta.codigo_error=2;
        }
        else
        {
            respuesta.codigo_error=3;
        }
        sem_post(mutex);
        break;
    case 4:
        if(baja(peticion.tipo)==1)
        {
            sem_wait(sclientes);
            num_clientes--;
            sem_post(sclientes);
            printf("Peticion de baja del cliente %ld, clientes conectados %d/%d\n",peticion.tipo,num_clientes,max_clientes);
            respuesta.codigo_error=0;
            sem_post(s1);
        }
        else
        {
            respuesta.codigo_error=1;
        }
        break;
    }
    registrando_en_logfile(2);
   return;
}


visualizar

decompiled_code:
unsigned int *__fastcall visualizar(unsigned int *a1)
{
if ( a1 )
{
visualizar(*((_QWORD *)a1 + 2));
printf(" %d ", *a1);
visualizar(*((_QWORD *)a1 + 1));
}
return a1;
}

canonical_decompiled_code:
unsigned int *__fastcall func0(unsigned int *a1)
{
if ( a1 )
{
func0(*((_QWORD *)a1 + 2));
printf(" %d ", *a1);
func0(*((_QWORD *)a1 + 1));
}
return a1;
}

original_code:
Nodo* visualizar(Nodo* raiz)
{
    if (raiz != ((void *)0))
    {
        visualizar(raiz->izq);
        printf(" %d ",raiz->dato);
        visualizar(raiz->der);
    }
    return raiz;
}

canonical_original_code:
struct NodoArbol *visualizar(struct NodoArbol *raiz)
{
    if (raiz != ((void *)0))
    {
        visualizar(raiz->izq);
        printf(" %d ",raiz->dato);
        visualizar(raiz->der);
    }
    return raiz;
}


borrar

decompiled_code:
unsigned int *__fastcall borrar(unsigned int *a1, signed int a2)
{
_QWORD *v3; // rbp
__int64 v4; // rax
unsigned int *v5; // r15
unsigned int *v6; // r12
__int64 v7; // r14
unsigned int *k; // rax
__int64 v9; // rsi
__int64 v10; // rax
unsigned int *j; // rax
__int64 v13; // rax
unsigned int *v14; // rax
__int64 v15; // rax
unsigned int *i; // rax
__int64 v17; // rsi
__int64 v18; // rax

v3 = (_QWORD *)buscar();
v4 = buscar_padre(a1, (unsigned int)a2);
if ( !v3 )
{
respuesta[2] = 3;
return a1;
}
v5 = (unsigned int *)v3[1];
v6 = (unsigned int *)v3[2];
v7 = v4;
if ( v5 )
{
if ( v4 )
{
if ( v6 )
goto LABEL_5;
for ( i = (unsigned int *)*((_QWORD *)v5 + 2); i; i = (unsigned int *)*((_QWORD *)i + 2) )
v5 = i;
v17 = *v5;
if ( *(_DWORD *)v7 <= a2 )
{
v18 = buscar_padre(a1, v17);
*(_QWORD *)(v7 + 8) = v5;
if ( *(_DWORD *)v18 == *(_DWORD *)v3 )
goto LABEL_38;
}
else
{
v18 = buscar_padre(a1, v17);
*(_QWORD *)(v7 + 16) = v5;
if ( *(_DWORD *)v18 == *(_DWORD *)v3 )
{
LABEL_38:
*((_QWORD *)v5 + 2) = v3[2];
goto LABEL_11;
}
}
*(_QWORD *)(v18 + 8) = *((_QWORD *)v5 + 2);
*((_QWORD *)v5 + 1) = v3[1];
goto LABEL_38;
}
if ( !v6 )
{
v14 = (unsigned int *)*((_QWORD *)v5 + 2);
if ( v14 )
{
do
{
v6 = v14;
v14 = (unsigned int *)*((_QWORD *)v14 + 2);
}
while ( v14 );
}
else
{
v6 = (unsigned int *)v3[1];
}
v15 = buscar_padre(a1, *v6);
if ( *(_DWORD *)v15 != *(_DWORD *)v3 )
{
*(_QWORD *)(v15 + 16) = *((_QWORD *)v6 + 1);
*((_QWORD *)v6 + 1) = v3[1];
}
*((_QWORD *)v6 + 2) = v3[2];
goto LABEL_20;
}
goto LABEL_15;
}
if ( !v6 )
{
if ( v4 )
{
if ( *(_DWORD *)v4 <= a2 )
*(_QWORD *)(v4 + 8) = 0LL;
else
*(_QWORD *)(v4 + 16) = 0LL;
goto LABEL_11;
}
LABEL_20:
free(v3);
return v6;
}
if ( !v4 )
{
LABEL_15:
for ( j = (unsigned int *)*((_QWORD *)v6 + 1); j; j = (unsigned int *)*((_QWORD *)j + 1) )
v6 = j;
v13 = buscar_padre(a1, *v6);
if ( *(_DWORD *)v13 != *(_DWORD *)v3 )
{
*(_QWORD *)(v13 + 8) = *((_QWORD *)v6 + 2);
*((_QWORD *)v6 + 2) = v3[2];
}
*((_QWORD *)v6 + 1) = v3[1];
goto LABEL_20;
}
LABEL_5:
for ( k = (unsigned int *)*((_QWORD *)v6 + 1); k; k = (unsigned int *)*((_QWORD *)k + 1) )
v6 = k;
v9 = *v6;
if ( *(_DWORD *)v7 > a2 )
{
v10 = buscar_padre(a1, v9);
*(_QWORD *)(v7 + 16) = v6;
if ( *(_DWORD *)v10 == *(_DWORD *)v3 )
goto LABEL_10;
goto LABEL_9;
}
v10 = buscar_padre(a1, v9);
*(_QWORD *)(v7 + 8) = v6;
if ( *(_DWORD *)v10 != *(_DWORD *)v3 )
{
LABEL_9:
*(_QWORD *)(v10 + 8) = *((_QWORD *)v6 + 2);
*((_QWORD *)v6 + 2) = v3[2];
}
LABEL_10:
*((_QWORD *)v6 + 1) = v3[1];
LABEL_11:
v6 = a1;
free(v3);
return v6;
}

canonical_decompiled_code:
unsigned int *__fastcall func0(unsigned int *a1, signed int a2)
{
_QWORD *v3; // rbp
__int64 v4; // rax
unsigned int *v5; // r15
unsigned int *v6; // r12
__int64 v7; // r14
unsigned int *k; // rax
__int64 v9; // rsi
__int64 v10; // rax
unsigned int *j; // rax
__int64 v13; // rax
unsigned int *v14; // rax
__int64 v15; // rax
unsigned int *i; // rax
__int64 v17; // rsi
__int64 v18; // rax

v3 = (_QWORD *)buscar();
v4 = buscar_padre(a1, (unsigned int)a2);
if ( !v3 )
{
respuesta[2] = 3;
return a1;
}
v5 = (unsigned int *)v3[1];
v6 = (unsigned int *)v3[2];
v7 = v4;
if ( v5 )
{
if ( v4 )
{
if ( v6 )
goto LABEL_5;
for ( i = (unsigned int *)*((_QWORD *)v5 + 2); i; i = (unsigned int *)*((_QWORD *)i + 2) )
v5 = i;
v17 = *v5;
if ( *(_DWORD *)v7 <= a2 )
{
v18 = buscar_padre(a1, v17);
*(_QWORD *)(v7 + 8) = v5;
if ( *(_DWORD *)v18 == *(_DWORD *)v3 )
goto LABEL_38;
}
else
{
v18 = buscar_padre(a1, v17);
*(_QWORD *)(v7 + 16) = v5;
if ( *(_DWORD *)v18 == *(_DWORD *)v3 )
{
LABEL_38:
*((_QWORD *)v5 + 2) = v3[2];
goto LABEL_11;
}
}
*(_QWORD *)(v18 + 8) = *((_QWORD *)v5 + 2);
*((_QWORD *)v5 + 1) = v3[1];
goto LABEL_38;
}
if ( !v6 )
{
v14 = (unsigned int *)*((_QWORD *)v5 + 2);
if ( v14 )
{
do
{
v6 = v14;
v14 = (unsigned int *)*((_QWORD *)v14 + 2);
}
while ( v14 );
}
else
{
v6 = (unsigned int *)v3[1];
}
v15 = buscar_padre(a1, *v6);
if ( *(_DWORD *)v15 != *(_DWORD *)v3 )
{
*(_QWORD *)(v15 + 16) = *((_QWORD *)v6 + 1);
*((_QWORD *)v6 + 1) = v3[1];
}
*((_QWORD *)v6 + 2) = v3[2];
goto LABEL_20;
}
goto LABEL_15;
}
if ( !v6 )
{
if ( v4 )
{
if ( *(_DWORD *)v4 <= a2 )
*(_QWORD *)(v4 + 8) = 0LL;
else
*(_QWORD *)(v4 + 16) = 0LL;
goto LABEL_11;
}
LABEL_20:
free(v3);
return v6;
}
if ( !v4 )
{
LABEL_15:
for ( j = (unsigned int *)*((_QWORD *)v6 + 1); j; j = (unsigned int *)*((_QWORD *)j + 1) )
v6 = j;
v13 = buscar_padre(a1, *v6);
if ( *(_DWORD *)v13 != *(_DWORD *)v3 )
{
*(_QWORD *)(v13 + 8) = *((_QWORD *)v6 + 2);
*((_QWORD *)v6 + 2) = v3[2];
}
*((_QWORD *)v6 + 1) = v3[1];
goto LABEL_20;
}
LABEL_5:
for ( k = (unsigned int *)*((_QWORD *)v6 + 1); k; k = (unsigned int *)*((_QWORD *)k + 1) )
v6 = k;
v9 = *v6;
if ( *(_DWORD *)v7 > a2 )
{
v10 = buscar_padre(a1, v9);
*(_QWORD *)(v7 + 16) = v6;
if ( *(_DWORD *)v10 == *(_DWORD *)v3 )
goto LABEL_10;
goto LABEL_9;
}
v10 = buscar_padre(a1, v9);
*(_QWORD *)(v7 + 8) = v6;
if ( *(_DWORD *)v10 != *(_DWORD *)v3 )
{
LABEL_9:
*(_QWORD *)(v10 + 8) = *((_QWORD *)v6 + 2);
*((_QWORD *)v6 + 2) = v3[2];
}
LABEL_10:
*((_QWORD *)v6 + 1) = v3[1];
LABEL_11:
v6 = a1;
free(v3);
return v6;
}

original_code:
Nodo* borrar(Nodo* raiz,int d)
{
    Nodo *paux1,*paux2,*borr,*padre;
    borr=buscar(raiz,d);
    padre=buscar_padre(raiz,d);
    if(borr!=((void *)0))
    {
        if(borr->der==((void *)0) && borr->izq==((void *)0))
        {
            if(padre==((void *)0))
            {
                free(borr);
                return ((void *)0);
            }
            else
            {
                if(padre->dato>d)
                {
                    padre->izq=((void *)0);
                }
                else
                {
                    padre->der=((void *)0);
                }
            }
        }
        else
        {
            if(padre!=((void *)0))
            {
                if(borr->izq!=((void *)0))
                {
                    paux1=borr->izq;
                    paux2=paux1->der;
                    while(paux2!=((void *)0))
                    {
                        paux1=paux2;
                        paux2=paux1->der;
                    }
                    if(padre->dato>d)
                    {
                        paux2=buscar_padre(raiz,paux1->dato);
                        padre->izq=paux1;
                        if(paux2->dato!=borr->dato)
                        {
                            paux2->der=paux1->izq;
                            paux1->izq=borr->izq;
                        }
                        paux1->der=borr->der;
                    }
                    else
                    {
                        paux2=buscar_padre(raiz,paux1->dato);
                        padre->der=paux1;
                        if(paux2->dato!=borr->dato)
                        {
                            paux2->der=paux1->izq;
                            paux1->izq=borr->izq;
                        }
                        paux1->der=borr->der;
                    }
                }
                else
                {
                    paux1=borr->der;
                    paux2=paux1->izq;
                    while(paux2!=((void *)0))
                    {
                        paux1=paux2;
                        paux2=paux1->izq;
                    }
                    if(padre->dato>d)
                    {
                        paux2=buscar_padre(raiz,paux1->dato);
                        padre->izq=paux1;
                        if(paux2->dato!=borr->dato)
                        {
                            paux2->der=paux1->izq;
                            paux1->der=borr->der;
                        }
                        paux1->izq=borr->izq;
                    }
                    else
                    {
                        paux2=buscar_padre(raiz,paux1->dato);
                        padre->der=paux1;
                        if(paux2->dato!=borr->dato)
                        {
                            paux2->der=paux1->izq;
                            paux1->der=borr->der;
                        }
                        paux1->izq=borr->izq;
                    }
                }
            }
            else
            {
                if(borr->izq!=((void *)0))
                {
                    paux1=borr->izq;
                    paux2=paux1->der;
                    while(paux2!=((void *)0))
                    {
                        paux1=paux2;
                        paux2=paux1->der;
                    }
                    paux2=buscar_padre(raiz,paux1->dato);
                    if(paux2->dato!=borr->dato)
                    {
                        paux2->der=paux1->izq;
                        paux1->izq=borr->izq;
                    }
                    paux1->der=borr->der;
                }
                else
                {
                    paux1=borr->der;
                    paux2=paux1->izq;
                    while(paux2!=((void *)0))
                    {
                        paux1=paux2;
                        paux2=paux1->izq;
                    }
                    paux2=buscar_padre(raiz,paux1->dato);
                    if(paux2->dato!=borr->dato)
                    {
                        paux2->izq=paux1->der;
                        paux1->der=borr->der;
                    }
                    paux1->izq=borr->izq;
                }
                free(borr);
                return (paux1);
            }
        }
        free(borr);
        return raiz;
    }
    else
    {
        respuesta.codigo_error=3;
        return raiz;
    }
}

canonical_original_code:
struct NodoArbol *borrar(struct NodoArbol *raiz, int d)
{
    struct NodoArbol *paux1; struct NodoArbol *paux2; struct NodoArbol *borr; struct NodoArbol *padre;
    borr=buscar(raiz,d);
    padre=buscar_padre(raiz,d);
    if(borr!=((void *)0))
    {
        if(borr->der==((void *)0) && borr->izq==((void *)0))
        {
            if(padre==((void *)0))
            {
                free(borr);
                return ((void *)0);
            }
            else
            {
                if(padre->dato>d)
                {
                    padre->izq=((void *)0);
                }
                else
                {
                    padre->der=((void *)0);
                }
            }
        }
        else
        {
            if(padre!=((void *)0))
            {
                if(borr->izq!=((void *)0))
                {
                    paux1=borr->izq;
                    paux2=paux1->der;
                    while(paux2!=((void *)0))
                    {
                        paux1=paux2;
                        paux2=paux1->der;
                    }
                    if(padre->dato>d)
                    {
                        paux2=buscar_padre(raiz,paux1->dato);
                        padre->izq=paux1;
                        if(paux2->dato!=borr->dato)
                        {
                            paux2->der=paux1->izq;
                            paux1->izq=borr->izq;
                        }
                        paux1->der=borr->der;
                    }
                    else
                    {
                        paux2=buscar_padre(raiz,paux1->dato);
                        padre->der=paux1;
                        if(paux2->dato!=borr->dato)
                        {
                            paux2->der=paux1->izq;
                            paux1->izq=borr->izq;
                        }
                        paux1->der=borr->der;
                    }
                }
                else
                {
                    paux1=borr->der;
                    paux2=paux1->izq;
                    while(paux2!=((void *)0))
                    {
                        paux1=paux2;
                        paux2=paux1->izq;
                    }
                    if(padre->dato>d)
                    {
                        paux2=buscar_padre(raiz,paux1->dato);
                        padre->izq=paux1;
                        if(paux2->dato!=borr->dato)
                        {
                            paux2->der=paux1->izq;
                            paux1->der=borr->der;
                        }
                        paux1->izq=borr->izq;
                    }
                    else
                    {
                        paux2=buscar_padre(raiz,paux1->dato);
                        padre->der=paux1;
                        if(paux2->dato!=borr->dato)
                        {
                            paux2->der=paux1->izq;
                            paux1->der=borr->der;
                        }
                        paux1->izq=borr->izq;
                    }
                }
            }
            else
            {
                if(borr->izq!=((void *)0))
                {
                    paux1=borr->izq;
                    paux2=paux1->der;
                    while(paux2!=((void *)0))
                    {
                        paux1=paux2;
                        paux2=paux1->der;
                    }
                    paux2=buscar_padre(raiz,paux1->dato);
                    if(paux2->dato!=borr->dato)
                    {
                        paux2->der=paux1->izq;
                        paux1->izq=borr->izq;
                    }
                    paux1->der=borr->der;
                }
                else
                {
                    paux1=borr->der;
                    paux2=paux1->izq;
                    while(paux2!=((void *)0))
                    {
                        paux1=paux2;
                        paux2=paux1->izq;
                    }
                    paux2=buscar_padre(raiz,paux1->dato);
                    if(paux2->dato!=borr->dato)
                    {
                        paux2->izq=paux1->der;
                        paux1->der=borr->der;
                    }
                    paux1->izq=borr->izq;
                }
                free(borr);
                return (paux1);
            }
        }
        free(borr);
        return raiz;
    }
    else
    {
        respuesta.codigo_error=3;
        return raiz;
    }
}

variable_types: d int

variable_types: struct NodoArbol { int dato; struct NodoArbol *der; struct NodoArbol *izq; } *


decompiled_code:
int atender_peticion()
{
__pid_t v0; // eax
int v1; // edi

v0 = getpid();
v1 = Q_clientes_activos;
*((_DWORD *)&cliente_activo + 2) = 1;
cliente_activo = v0;
return msgsnd(v1, &cliente_activo, 4uLL, 0);
}

canonical_decompiled_code:
int func0()
{
__pid_t v0; // eax
int v1; // edi

v0 = getpid();
v1 = Q_clientes_activos;
*((_DWORD *)&cliente_activo + 2) = 1;
cliente_activo = v0;
return msgsnd(v1, &cliente_activo, 4uLL, 0);
}

original_code:
void atender_peticion(int sig)
{
    cliente_activo.tipo = getpid();
    cliente_activo.codigo_operacion = 1;
    msgsnd(Q_clientes_activos, &cliente_activo,sizeof(int),0);
}


decompiled_code:
int __fastcall abrir_cola(const char *a1, char a2)
{
int v2; // eax
int result; // eax
int *v4; // rax

v2 = ftok(a1, a2);
if ( v2 < 0 )
{
v4 = _errno_location();
printf(&format, (unsigned int)*v4);
exit(-1);
}
result = msgget(v2, 0);
if ( result < 0 )
{
puts(&s);
exit(-1);
}
return result;
}

canonical_decompiled_code:
int __fastcall func1(const char *a1, char a2)
{
int v2; // eax
int result; // eax
int *v4; // rax

v2 = ftok(a1, a2);
if ( v2 < 0 )
{
v4 = _errno_location();
printf(&format, (unsigned int)*v4);
exit(-1);
}
result = msgget(v2, 0);
if ( result < 0 )
{
puts(&s);
exit(-1);
}
return result;
}

original_code:
int abrir_cola(char nombre[], char id)
{
    int cola;
    key_t llave = ftok(nombre, id);
    if(llave < 0)
    {
        printf("¡Error! ftok fallo con errno = %d\n",(*__errno_location ()));
        exit(-1);
    }
    cola = msgget(llave, 0);
    if(cola < 0)
    {
        printf("¡Error! No esta ejecutado el servidor.\n");
        exit(-1);
    }
    return cola;
}

canonical_original_code:
int abrir_cola(char nombre[], char id)
{
    int cola;
    int llave = ftok(nombre, id);
    if(llave < 0)
    {
        printf("¡Error! ftok fallo con errno = %d\n",(*__errno_location ()));
        exit(-1);
    }
    cola = msgget(llave, 0);
    if(cola < 0)
    {
        printf("¡Error! No esta ejecutado el servidor.\n");
        exit(-1);
    }
    return cola;
}


decompiled_code:
int __fastcall abrir_memoria_compartida(const char *a1, char a2)
{
int v2; // eax
int result; // eax
int *v4; // rax
int *v5; // rax

v2 = ftok(a1, a2);
if ( v2 < 0 )
{
v4 = _errno_location();
printf(&byte_268, (unsigned int)*v4);
exit(-1);
}
result = shmget(v2, 4uLL, 384);
if ( result < 0 )
{
v5 = _errno_location();
printf(&byte_2B0, (unsigned int)*v5);
exit(-1);
}
return result;
}

canonical_decompiled_code:
int __fastcall func2(const char *a1, char a2)
{
int v2; // eax
int result; // eax
int *v4; // rax
int *v5; // rax

v2 = ftok(a1, a2);
if ( v2 < 0 )
{
v4 = _errno_location();
printf(&byte_268, (unsigned int)*v4);
exit(-1);
}
result = shmget(v2, 4uLL, 384);
if ( result < 0 )
{
v5 = _errno_location();
printf(&byte_2B0, (unsigned int)*v5);
exit(-1);
}
return result;
}

original_code:
int abrir_memoria_compartida(char nombre[], char id)
{
    int memoria;
    key_t keymemo=ftok(nombre,id);
    if(keymemo < 0)
    {
        printf("¡Error! Fallo recuperando token de mem. compartida. [ERROR %d]\n", (*__errno_location ()));
        exit(-1);
    }
    memoria = shmget(keymemo,sizeof(int),0600);
    if(memoria < 0)
    {
        printf("¡Error! No se pudo acceder a la memoria compartida, [ERROR %d]\n", (*__errno_location ()));
        exit(-1);
    }
    return memoria;
}

canonical_original_code:
int abrir_memoria_compartida(char nombre[], char id)
{
    int memoria;
    int keymemo = ftok(nombre,id);
    if(keymemo < 0)
    {
        printf("¡Error! Fallo recuperando token de mem. compartida. [ERROR %d]\n", (*__errno_location ()));
        exit(-1);
    }
    memoria = shmget(keymemo,sizeof(int),0600);
    if(memoria < 0)
    {
        printf("¡Error! No se pudo acceder a la memoria compartida, [ERROR %d]\n", (*__errno_location ()));
        exit(-1);
    }
    return memoria;
}


buscar

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

for ( result = a1; result; result = *(_QWORD *)(result + 8) )
{
while ( *(_DWORD *)result > a2 )
{
result = *(_QWORD *)(result + 16);
if ( !result )
return result;
}
if ( *(_DWORD *)result >= a2 )
break;
}
return result;
}

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

for ( result = a1; result; result = *(_QWORD *)(result + 8) )
{
while ( *(_DWORD *)result > a2 )
{
result = *(_QWORD *)(result + 16);
if ( !result )
return result;
}
if ( *(_DWORD *)result >= a2 )
break;
}
return result;
}

original_code:
Nodo* buscar(Nodo* raiz,int d)
{
    if (raiz==((void *)0))
    {
        return ((void *)0);
    }
    else if (d<raiz->dato)
    {
        buscar(raiz->izq,d);
    }
    else if (d>raiz->dato)
    {
        buscar(raiz->der,d);
    }
    else
    {
        return raiz;
    }
}

canonical_original_code:
struct NodoArbol *buscar(struct NodoArbol *raiz, int d)
{
    if (raiz==((void *)0))
    {
        return ((void *)0);
    }
    else if (d<raiz->dato)
    {
        buscar(raiz->izq,d);
    }
    else if (d>raiz->dato)
    {
        buscar(raiz->der,d);
    }
    else
    {
        return raiz;
    }
}

variable_types:
raiz
struct NodoArbol *


original_code:
Nodo* buscar_padre(Nodo* raiz,int d)
{
    Nodo *paux2,*paux1;
    paux1=raiz;
    paux2=((void *)0);
    if(raiz==((void *)0))
        return paux2;
    while (paux1->dato!=d)
    {
        if(paux1->dato<d)
        {
            paux2=paux1;
            paux1=paux1->der;
        }
        else
        {
            paux2=paux1;
            paux1=paux1->izq;
        }
        if (paux1==((void *)0))
        {
            return ((void *)0);
        }
    }
    return paux2;
}

canonical_original_code:
struct NodoArbol *buscar_padre(struct NodoArbol *raiz, int d)
{
    struct NodoArbol *paux2; struct NodoArbol *paux1;
    paux1=raiz;
    paux2=((void *)0);
    if(raiz==((void *)0))
        return paux2;
    while (paux1->dato!=d)
    {
        if(paux1->dato<d)
        {
            paux2=paux1;
            paux1=paux1->der;
        }
        else
        {
            paux2=paux1;
            paux1=paux1->izq;
        }
        if (paux1==((void *)0))
        {
            return ((void *)0);
        }
    }
    return paux2;
}


decompiled_code:
void matar_cliente_inactivo()
{
if ( (unsigned int)baja((unsigned int)matar_pid) == 1 )
{
sem_wait(sclientes);
--num_clientes;
sem_post(sclientes);
printf(
"Eliminado el cliente %d por inactividad, clientes conectados %d/%d\n",
(unsigned int)matar_pid,
(unsigned int)num_clientes,
(unsigned int)max_clientes);
sem_post(s1);
}
}

canonical_decompiled_code:
void func0()
{
if ( (unsigned int)baja((unsigned int)matar_pid) == 1 )
{
sem_wait(sclientes);
--num_clientes;
sem_post(sclientes);
printf(
"Eliminado el cliente %d por inactividad, clientes conectados %d/%d\n",
(unsigned int)matar_pid,
(unsigned int)num_clientes,
(unsigned int)max_clientes);
sem_post(s1);
}
}

original_code:
void matar_cliente_inactivo(int sig)
{
    if(baja(matar_pid)==1)
    {
        sem_wait(sclientes);
        num_clientes--;
        sem_post(sclientes);
        printf("Eliminado el cliente %d por inactividad, clientes conectados %d/%d\n",matar_pid,num_clientes,max_clientes);
        sem_post(s1);
    }
}


decompiled_code:
void __noreturn control_clientes()
{
int v0; // eax
__pid_t *v1; // rdx
__int64 v2; // rbx
__pid_t v3; // edi

puts("Iniciando el control de clientes activos...");
signal(14, (__sighandler_t)matar_cliente_inactivo);
v0 = num_clientes;
v1 = (__pid_t *)vector_clientes;
while ( 1 )
{
while ( v0 <= 0 )
;
v2 = 0LL;
v3 = *v1;
if ( *v1 )
{
LABEL_6:
matar_pid = v3;
kill(v3, 10);
alarm(5u);
printf("Comprobando actividad del cliente %d\n", (unsigned int)matar_pid);
msgrcv(Q_clientes_activos, &cliente_activo, 4uLL, *(int *)(vector_clientes + 4 * v2), 0);
alarm(0);
sleep(0x14u);
v0 = num_clientes;
v1 = (__pid_t *)vector_clientes;
}
while ( v0 > (int)++v2 )
{
v3 = v1[v2];
if ( v3 )
goto LABEL_6;
}
}
}

canonical_decompiled_code:
void __noreturn func1()
{
int v0; // eax
__pid_t *v1; // rdx
__int64 v2; // rbx
__pid_t v3; // edi

puts("Iniciando el control de clientes activos...");
signal(14, (__sighandler_t)matar_cliente_inactivo);
v0 = num_clientes;
v1 = (__pid_t *)vector_clientes;
while ( 1 )
{
while ( v0 <= 0 )
;
v2 = 0LL;
v3 = *v1;
if ( *v1 )
{
LABEL_6:
matar_pid = v3;
kill(v3, 10);
alarm(5u);
printf("Comprobando actividad del cliente %d\n", (unsigned int)matar_pid);
msgrcv(Q_clientes_activos, &cliente_activo, 4uLL, *(int *)(vector_clientes + 4 * v2), 0);
alarm(0);
sleep(0x14u);
v0 = num_clientes;
v1 = (__pid_t *)vector_clientes;
}
while ( v0 > (int)++v2 )
{
v3 = v1[v2];
if ( v3 )
goto LABEL_6;
}
}
}

original_code:
void *control_clientes(void *parametro)
{
    int i;
    printf("Iniciando el control de clientes activos...\n");
    signal (14,matar_cliente_inactivo);
    while(1)
    {
        for(i=0; i<num_clientes; i++)
        {
            if(vector_clientes[i]!=0)
            {
                matar_pid = vector_clientes[i];
                kill(vector_clientes[i],10);
                alarm(5);
                printf("Comprobando actividad del cliente %d\n",matar_pid);
                msgrcv(Q_clientes_activos,&cliente_activo,sizeof(int),vector_clientes[i],0);
                alarm(0);
                sleep(20);
            }
        }
    }
}

variable_types:
parametro
void *

return_type: void *


baja

decompiled_code:
__int64 __fastcall baja(__pid_t pid)
{
__int64 v1; // rcx
__int64 i; // rax
__int64 result; // rax

sem_wait(sclientes);
if ( max_clientes <= 0 )
{
LABEL_8:
sem_post(sclientes);
result = 0LL;
}
else
{
v1 = vector_clientes;
i = 0LL;
while ( *(_DWORD *)(vector_clientes + 4 * i) != pid )
{
if ( max_clientes == ++i )
goto LABEL_8;
}
for ( i = (int)i; max_clientes - 1 > (int)i; ++i )
*(_DWORD *)(v1 + 4 * i) = *(_DWORD *)(v1 + 4 * i + 4);
sem_post(sclientes);
kill(pid, 2);
result = 1LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(__pid_t pid)
{
__int64 v1; // rcx
__int64 i; // rax
__int64 result; // rax

sem_wait(sclientes);
if ( max_clientes <= 0 )
{
LABEL_8:
sem_post(sclientes);
result = 0LL;
}
else
{
v1 = vector_clientes;
i = 0LL;
while ( *(_DWORD *)(vector_clientes + 4 * i) != pid )
{
if ( max_clientes == ++i )
goto LABEL_8;
}
for ( i = (int)i; max_clientes - 1 > (int)i; ++i )
*(_DWORD *)(v1 + 4 * i) = *(_DWORD *)(v1 + 4 * i + 4);
sem_post(sclientes);
kill(pid, 2);
result = 1LL;
}
return result;
}

original_code:
int baja(int pid)
{
    int i,encontrado=0;
    sem_wait(sclientes);
    for(i=0; i<max_clientes; i++)
    {
        if(vector_clientes[i]==pid)
        {
            encontrado=1;
            break;
        }
    }
    if(encontrado!=1)
    {
        sem_post(sclientes);
        return 0;
    }
    for(i=i; i<max_clientes-1; i++)
    {
        vector_clientes[i]=vector_clientes[i+1];
    }
    sem_post(sclientes);
    kill(pid,2);
    return 1;
}

canonical_original_code:
int baja(int pid)
{
    int i; int encontrado = 0;
    sem_wait(sclientes);
    for(i=0; i<max_clientes; i++)
    {
        if(vector_clientes[i]==pid)
        {
            encontrado=1;
            break;
        }
    }
    if(encontrado!=1)
    {
        sem_post(sclientes);
        return 0;
    }
    for(i=i; i<max_clientes-1; i++)
    {
        vector_clientes[i]=vector_clientes[i+1];
    }
    sem_post(sclientes);
    kill(pid,2);
    return 1;
}

variable_types: pid int

variable_types: encontrado int


reader

decompiled_code:
__int64 __fastcall reader(unsigned int a1)
{
unsigned int v1; // er12
__int64 result; // rax

while ( 1 )
{
result = (unsigned int)stop;
if ( stop )
break;
ta_sem_wait();
ta_lock();
v1 = readerloc;
readerloc = (readerloc + 1) % datalen;
ta_unlock();
ta_sem_signal();
fprintf(_bss_start, "reader %d read location %d\n", a1, v1);
if ( (random() & 1) == 0 )
ta_yield();
}
return result;
}

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

while ( 1 )
{
result = (unsigned int)stop;
if ( stop )
break;
ta_sem_wait();
ta_lock();
v1 = readerloc;
readerloc = (readerloc + 1) % datalen;
ta_unlock();
ta_sem_signal();
fprintf(_bss_start, "reader %d read location %d\n", a1, v1);
if ( (random() & 1) == 0 )
ta_yield();
}
return result;
}

original_code:
void reader(void *arg)
{
    int tid = (int)arg;
    int val = 0;
    while (!stop)
    {
        ta_sem_wait(&readersem);
        ta_lock(&rmutex);
        int loc = readerloc;
        readerloc = (readerloc+1) % datalen;
        ta_unlock(&rmutex);
        val = data[loc];
        ta_sem_signal(&writersem);
        fprintf(stderr, "reader %d read location %d\n", tid, loc);
        if (random() % 2 == 0)
            ta_yield();
    }
}

variable_types:
arg
void *

variable_types: tid int

variable_types: val int

variable_types: loc int


writer

decompiled_code:
void __fastcall writer(unsigned int a1)
{
int v1; // ebx
int v2; // ebp
int v3; // er12
int v4; // ecx

v1 = stop;
if ( !stop )
{
v2 = 1000000;
do
{
while ( 1 )
{
v3 = v1;
ta_sem_wait();
ta_lock();
v1 = (v1 + 1) % datalen;
ta_unlock();
v4 = v2++;
*((_DWORD *)data + v3) = v4;
ta_sem_signal();
fprintf(_bss_start, "writer %d wrote location %d\n", a1, (unsigned int)v3);
if ( (random() & 1) == 0 )
break;
if ( stop )
return;
}
ta_yield();
}
while ( !stop );
}
}

canonical_decompiled_code:
void __fastcall func9(unsigned int a1)
{
int v1; // ebx
int v2; // ebp
int v3; // er12
int v4; // ecx

v1 = stop;
if ( !stop )
{
v2 = 1000000;
do
{
while ( 1 )
{
v3 = v1;
ta_sem_wait();
ta_lock();
v1 = (v1 + 1) % datalen;
ta_unlock();
v4 = v2++;
*((_DWORD *)data + v3) = v4;
ta_sem_signal();
fprintf(_bss_start, "writer %d wrote location %d\n", a1, (unsigned int)v3);
if ( (random() & 1) == 0 )
break;
if ( stop )
return;
}
ta_yield();
}
while ( !stop );
}
}

original_code:
void writer(void *arg)
{
    int tid = (int)arg;
    int val = 1000000;
    int writerloc = 0;
    while (!stop)
    {
        ta_sem_wait(&writersem);
        ta_lock(&wmutex);
        int loc = writerloc;
        writerloc = (writerloc+1) % datalen;
        ta_unlock(&wmutex);
        data[loc] = val++;
        ta_sem_signal(&readersem);
        fprintf(stderr, "writer %d wrote location %d\n", tid, loc);
        if (random() % 2 == 0)
            ta_yield();
    }
}

variable_types: writerloc int


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int v3; // eax
__int64 v4; // rbx

v3 = time(0LL);
srandom(v3);
ta_libinit();
data = calloc(0x190uLL, 1uLL);
if ( !data )
__assert_fail("data", "test07.c", 0x57u, "main");
v4 = 0LL;
datalen = 100;
ta_sem_init();
ta_sem_init();
ta_lock_init();
ta_lock_init();
ta_create();
do
{
ta_create();
++v4;
ta_create();
}
while ( v4 != 5 );
if ( (unsigned int)ta_waitall() )
__assert_fail("rv == 0", "test07.c", 0x69u, "main");
ta_sem_destroy();
ta_sem_destroy();
ta_lock_destroy();
ta_lock_destroy();
free(data);
return 0;
}

original_code:
int main(int argc, char **argv)
{
    srandom(time(((void *)0)));
    ta_libinit();
    int i = 0;
    int nrw = 5;
    data = (int *)malloc(sizeof(int) * 100);
    ((void) sizeof ((data) ? 1 : 0), __extension__ ({ if (data) ; else __assert_fail ("data", "test07.c", 87, __extension__ __PRETTY_FUNCTION__); }));
    memset(data, 0, sizeof(int)*100);
    datalen = 100;
    ta_sem_init(&readersem, 0);
    ta_sem_init(&writersem, 100);
    ta_lock_init(&rmutex);
    ta_lock_init(&wmutex);
    ta_create(killerthr, (void *)i);
    for (i = 0; i < nrw; i++)
    {
        ta_create(reader, (void *)i);
        ta_create(writer, (void *)i);
    }
    int rv = ta_waitall();
    ((void) sizeof ((rv == 0) ? 1 : 0), __extension__ ({ if (rv == 0) ; else __assert_fail ("rv == 0", "test07.c", 105, __extension__ __PRETTY_FUNCTION__); }));
    ta_sem_destroy(&readersem);
    ta_sem_destroy(&writersem);
    ta_lock_destroy(&rmutex);
    ta_lock_destroy(&wmutex);
    free(data);
    return 0;
}

variable_types: argc int

variable_types:
argv
char **

variable_types: nrw int

variable_types: rv int


killerthr

decompiled_code:
time_t killerthr()
{
time_t v0; // rbx
time_t result; // rax

v0 = time(0LL) + 3;
do
{
ta_yield();
result = time(0LL);
}
while ( v0 > result );
stop = 1;
return result;
}

canonical_decompiled_code:
time_t func7()
{
time_t v0; // rbx
time_t result; // rax

v0 = time(0LL) + 3;
do
{
ta_yield();
result = time(0LL);
}
while ( v0 > result );
stop = 1;
return result;
}

original_code:
void killerthr(void *arg)
{
    time_t now = time(((void *)0));
    time_t finish = now + 3;
    while (now < finish)
    {
        ta_yield();
        now = time(((void *)0));
    }
    stop = 1;
}

canonical_original_code:
void killerthr(void *arg)
{
    long now = time(((void *)0));
    long finish = now + 3;
    while (now < finish)
    {
        ta_yield();
        now = time(((void *)0));
    }
    stop = 1;
}

variable_types: now long

variable_types: finish long


decompiled_code:
_QWORD *create_queue()
{
_QWORD *result; // rax

result = malloc(0x18uLL);
*result = 0LL;
result[1] = 0LL;
*((_DWORD *)result + 4) = 0;
return result;
}

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

result = malloc(0x18uLL);
*result = 0LL;
result[1] = 0LL;
*((_DWORD *)result + 4) = 0;
return result;
}

original_code:
queue* create_queue(){
    queue* q = (queue*)malloc(sizeof(queue));
    q->head = ((void *)0);
    q->tail = ((void *)0);
    q->length = 0;
    return q;
}

canonical_original_code:
struct queue *create_queue(){
    struct queue *q = (queue*)malloc(sizeof(queue));
    q->head = ((void *)0);
    q->tail = ((void *)0);
    q->length = 0;
    return q;
}

variable_types: struct queue { struct queue_node { struct control_block { struct ucontext_t { unsigned long __uc_flags; struct ucontext_t *uc_link; struct stack_t { void *ss_sp; int ss_flags; unsigned long ss_size; } uc_stack; struct mcontext_t { long long __gregs[23]; struct _libc_fpstate { unsigned short __cwd; unsigned short __swd; unsigned short __ftw; unsigned short __fop; unsigned long __rip; unsigned long __rdp; unsigned int __mxcsr; unsigned int __mxcr_mask; struct _libc_fpxreg { unsigned short __significand[4]; unsigned short __exponent; unsigned short __glibc_reserved1[3]; } _st[8]; struct _libc_xmmreg { unsigned int __element[4]; } _xmm[16]; unsigned int __glibc_reserved1[24]; } *__fpregs; unsigned long long __reserved1[8]; } uc_mcontext; struct __sigset_t { unsigned long __val[-1]; } uc_sigmask; struct _libc_fpstate __fpregs_mem; unsigned long long __ssp[4]; } *ctx; int status; } *thread; struct queue_node *next; struct queue_node *prev; } *head; struct queue_node *tail; int length; } *

user_defined_types: struct queue { struct queue_node *head; struct queue_node *tail; int length; }

user_defined_types: struct queue_node { struct control_block *thread; struct queue_node *next; struct queue_node *prev; }

user_defined_types: struct control_block { struct ucontext_t *ctx; int status; }

user_defined_types: struct ucontext_t { unsigned long __uc_flags; struct ucontext_t *uc_link; struct stack_t uc_stack; struct mcontext_t uc_mcontext; struct __sigset_t uc_sigmask; struct _libc_fpstate __fpregs_mem; unsigned long long __ssp[4]; }

user_defined_types: struct mcontext_t { long long __gregs[23]; struct _libc_fpstate *__fpregs; unsigned long long __reserved1[8]; }

user_defined_types: struct _libc_fpstate { unsigned short __cwd; unsigned short __swd; unsigned short __ftw; unsigned short __fop; unsigned long __rip; unsigned long __rdp; unsigned int __mxcsr; unsigned int __mxcr_mask; struct _libc_fpxreg _st[8]; struct _libc_xmmreg _xmm[16]; unsigned int __glibc_reserved1[24]; }


len

decompiled_code:
__int64 __fastcall len(__int64 a1)
{
return *(unsigned int *)(a1 + 16);
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1)
{
return *(unsigned int *)(a1 + 16);
}

original_code:
int len(queue* q){
    return q->length;
}

canonical_original_code:
int len(struct queue *q){
    return q->length;
}

user_defined_types: struct stack_t { void *ss_sp; int ss_flags; unsigned long ss_size; }

user_defined_types: struct __sigset_t { unsigned long __val[-1]; }

user_defined_types: struct _libc_fpxreg { unsigned short __significand[4]; unsigned short __exponent; unsigned short __glibc_reserved1[3]; }

user_defined_types: struct _libc_xmmreg { unsigned int __element[4]; }


push

decompiled_code:
__int64 __fastcall push(__int64 a1, __int64 a2)
{
_QWORD *v2; // rbp
__int64 result; // rax

v2 = create_queue_node(a2);
result = len(a1);
if ( (_DWORD)result )
{
result = *(_QWORD *)(a1 + 8);
*(_QWORD *)(result + 16) = v2;
v2[1] = result;
*(_QWORD *)(a1 + 8) = v2;
}
else
{
*(_QWORD *)a1 = v2;
*(_QWORD *)(a1 + 8) = v2;
v2[1] = 0LL;
}
v2[2] = 0LL;
++*(_DWORD *)(a1 + 16);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, __int64 a2)
{
_QWORD *v2; // rbp
__int64 result; // rax

v2 = create_queue_node(a2);
result = func1(a1);
if ( (_DWORD)result )
{
result = *(_QWORD *)(a1 + 8);
*(_QWORD *)(result + 16) = v2;
v2[1] = result;
*(_QWORD *)(a1 + 8) = v2;
}
else
{
*(_QWORD *)a1 = v2;
*(_QWORD *)(a1 + 8) = v2;
v2[1] = 0LL;
}
v2[2] = 0LL;
++*(_DWORD *)(a1 + 16);
return result;
}

original_code:
void push(queue* q, tcb* thread){
    queue_node* n = create_queue_node(thread);
    if (len(q) == 0){
 q->head = n;
 q->tail = n;
 n->next = ((void *)0);
 n->prev = ((void *)0);
 q->length++;
    }
    else{
 q->tail->prev = n;
 n->next = q->tail;
 q->tail = n;
 q->tail->prev = ((void *)0);
 q->length++;
    }
}

canonical_original_code:
void push(struct queue *q, struct control_block *thread){
    struct queue_node *n = create_queue_node(thread);
    if (len(q) == 0){
 q->head = n;
 q->tail = n;
 n->next = ((void *)0);
 n->prev = ((void *)0);
 q->length++;
    }
    else{
 q->tail->prev = n;
 n->next = q->tail;
 q->tail = n;
 q->tail->prev = ((void *)0);
 q->length++;
    }
}

variable_types:
thread
struct control_block *

variable_types: struct queue_node { struct control_block { struct ucontext_t { unsigned long __uc_flags; struct ucontext_t *uc_link; struct stack_t { void *ss_sp; int ss_flags; unsigned long ss_size; } uc_stack; struct mcontext_t { long long __gregs[23]; struct _libc_fpstate { unsigned short __cwd; unsigned short __swd; unsigned short __ftw; unsigned short __fop; unsigned long __rip; unsigned long __rdp; unsigned int __mxcsr; unsigned int __mxcr_mask; struct _libc_fpxreg { unsigned short __significand[4]; unsigned short __exponent; unsigned short __glibc_reserved1[3]; } _st[8]; struct _libc_xmmreg { unsigned int __element[4]; } _xmm[16]; unsigned int __glibc_reserved1[24]; } *__fpregs; unsigned long long __reserved1[8]; } uc_mcontext; struct __sigset_t { unsigned long __val[-1]; } uc_sigmask; struct _libc_fpstate __fpregs_mem; unsigned long long __ssp[4]; } *ctx; int status; } *thread; struct queue_node *next; struct queue_node *prev; } *


pop

original_code:
tcb* pop(queue* q) {
    if (q->length > 1){
        tcb* thread = q->head->thread;
 queue_node* head = q->head;
        q->head = q->head->prev;
 free(head);
 q->head->next = ((void *)0);
 q->length--;
 return thread;
    }
    else if (q->length == 1){
 tcb* thread = q->head->thread;
 q->head = ((void *)0);
 q->tail = ((void *)0);
 free(q->head);
 q->length--;
 return thread;
    }
    else {
 printf("Error: Queue length 0\n");
 exit(1);
    }
}

canonical_original_code:
struct control_block *pop(struct queue *q) {
    if (q->length > 1){
        struct control_block *thread = q->head->thread;
 struct queue_node *head = q->head;
        q->head = q->head->prev;
 free(head);
 q->head->next = ((void *)0);
 q->length--;
 return thread;
    }
    else if (q->length == 1){
 struct control_block *thread = q->head->thread;
 q->head = ((void *)0);
 q->tail = ((void *)0);
 free(q->head);
 q->length--;
 return thread;
    }
    else {
 printf("Error: Queue length 0\n");
 exit(1);
    }
}

variable_types: struct queue { struct queue_node { struct control_block *thread; struct queue_node *next; struct queue_node *prev; } *head; struct queue_node *tail; int length; } *

variable_types: struct control_block { struct ucontext_t { unsigned long __uc_flags; struct ucontext_t *uc_link; struct stack_t { void *ss_sp; int ss_flags; unsigned long ss_size; } uc_stack; struct mcontext_t { long long __gregs[23]; struct _libc_fpstate { unsigned short __cwd; unsigned short __swd; unsigned short __ftw; unsigned short __fop; unsigned long __rip; unsigned long __rdp; unsigned int __mxcsr; unsigned int __mxcr_mask; struct _libc_fpxreg { unsigned short __significand[4]; unsigned short __exponent; unsigned short __glibc_reserved1[3]; } _st[8]; struct _libc_xmmreg { unsigned int __element[4]; } _xmm[16]; unsigned int __glibc_reserved1[24]; } *__fpregs; unsigned long long __reserved1[8]; } uc_mcontext; struct __sigset_t { unsigned long __val[-1]; } uc_sigmask; struct _libc_fpstate __fpregs_mem; unsigned long long __ssp[4]; } *ctx; int status; } *


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

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

original_code:
tcb* get_head(queue* q){
    return q->head->thread;
}

canonical_original_code:
struct control_block *get_head(struct queue *q){
    return q->head->thread;
}

return_type: struct control_block { struct ucontext_t { unsigned long __uc_flags; struct ucontext_t *uc_link; struct stack_t { void *ss_sp; int ss_flags; unsigned long ss_size; } uc_stack; struct mcontext_t { long long __gregs[23]; struct _libc_fpstate { unsigned short __cwd; unsigned short __swd; unsigned short __ftw; unsigned short __fop; unsigned long __rip; unsigned long __rdp; unsigned int __mxcsr; unsigned int __mxcr_mask; struct _libc_fpxreg { unsigned short __significand[4]; unsigned short __exponent; unsigned short __glibc_reserved1[3]; } _st[8]; struct _libc_xmmreg { unsigned int __element[4]; } _xmm[16]; unsigned int __glibc_reserved1[24]; } *__fpregs; unsigned long long __reserved1[8]; } uc_mcontext; struct __sigset_t { unsigned long __val[-1]; } uc_sigmask; struct _libc_fpstate __fpregs_mem; unsigned long long __ssp[4]; } *ctx; int status; } *


decompiled_code:
void __fastcall destroy_queue(void *ptr)
{
int v2; // ebx
__int64 v3; // rbp
__int64 v4; // r12
void *v5; // rdi

v2 = 0;
v3 = *(_QWORD *)ptr;
while ( (int)len((__int64)ptr) > v2 )
{
v4 = *(_QWORD *)(v3 + 16);
++v2;
free(**(void ***)v3);
free(*(void **)v3);
v5 = (void *)v3;
v3 = v4;
free(v5);
}
free(ptr);
}

canonical_decompiled_code:
void __fastcall func5(void *ptr)
{
int v2; // ebx
__int64 v3; // rbp
__int64 v4; // r12
void *v5; // rdi

v2 = 0;
v3 = *(_QWORD *)ptr;
while ( (int)func1((__int64)ptr) > v2 )
{
v4 = *(_QWORD *)(v3 + 16);
++v2;
free(**(void ***)v3);
free(*(void **)v3);
v5 = (void *)v3;
v3 = v4;
free(v5);
}
free(ptr);
}

original_code:
void destroy_queue(queue* q){
    queue_node* cur = q->head;
    int i = 0;
    for (;i<len(q);i++){
 queue_node* prev = cur->prev;
 free(cur->thread->ctx);
 free(cur->thread);
 free(cur);
 cur = prev;
    }
    free(q);
}

canonical_original_code:
void destroy_queue(struct queue *q){
    struct queue_node *cur = q->head;
    int i = 0;
    for (;i<len(q);i++){
 struct queue_node *prev = cur->prev;
 free(cur->thread->ctx);
 free(cur->thread);
 free(cur);
 cur = prev;
    }
    free(q);
}

variable_types: i int


think

decompiled_code:
__int64 __fastcall think(unsigned int a1)
{
fprintf(_bss_start, "Philosopher %d is thinking\n", a1);
return ta_yield();
}

canonical_decompiled_code:
__int64 __fastcall func8(unsigned int a1)
{
fprintf(_bss_start, "Philosopher %d is thinking\n", a1);
return ta_yield();
}

original_code:
void think(int i)
{
    fprintf(stderr, "Philosopher %d is thinking\n", i);
    ta_yield();
}


eat

decompiled_code:
__int64 __fastcall eat(unsigned int a1)
{
fprintf(_bss_start, "Philosopher %d is eating\n", a1);
return ta_yield();
}

canonical_decompiled_code:
__int64 __fastcall func9(unsigned int a1)
{
fprintf(_bss_start, "Philosopher %d is eating\n", a1);
return ta_yield();
}

original_code:
void eat(int i)
{
    fprintf(stderr, "Philosopher %d is eating\n", i);
    ta_yield();
}


testSafetyAndLiveness

original_code:
void testSafetyAndLiveness(int i, shared_data_t *data)
{
    if (data->state[i] == 1 &&
 (data->state[(i+1)%5] != 2 &&
  data->state[(i-1)%5] != 2))
    {
 data->state[i] = 2;
 ta_sem_signal(&data->mayEat[i]);
    }
}

canonical_original_code:
void testSafetyAndLiveness(int i, struct shared_data_t *data)
{
    if (data->state[i] == 1 &&
 (data->state[(i+1)%5] != 2 &&
  data->state[(i-1)%5] != 2))
    {
 data->state[i] = 2;
 ta_sem_signal(&data->mayEat[i]);
    }
}

variable_types: struct shared_data_t { int stop; int atTable; struct tasem_t { int value; struct queue { struct queue_node { struct control_block { struct ucontext_t { unsigned long uc_flags; struct ucontext_t *uc_link; struct stack_t { void *ss_sp; int ss_flags; unsigned long ss_size; } uc_stack; struct mcontext_t { long long gregs[23]; struct _libc_fpstate { unsigned short cwd; unsigned short swd; unsigned short ftw; unsigned short fop; unsigned long rip; unsigned long rdp; unsigned int mxcsr; unsigned int mxcr_mask; struct _libc_fpxreg { unsigned short significand[4]; unsigned short exponent; unsigned short __glibc_reserved1[3]; } _st[8]; struct _libc_xmmreg { unsigned int element[4]; } _xmm[16]; unsigned int __glibc_reserved1[24]; } *fpregs; unsigned long long __reserved1[8]; } uc_mcontext; struct __sigset_t { unsigned long __val[-1]; } uc_sigmask; struct _libc_fpstate __fpregs_mem; unsigned long long __ssp[4]; } *ctx; int status; } *thread; struct queue_node *next; struct queue_node *prev; } *head; struct queue_node *tail; int length; } *w_queue; } atTableSem; struct tasem_t mutex; int state[5]; struct tasem_t mayEat[5]; } *

user_defined_types: struct shared_data_t { int stop; int atTable; struct tasem_t atTableSem; struct tasem_t mutex; int state[5]; struct tasem_t mayEat[5]; }

user_defined_types: struct tasem_t { int value; struct queue *w_queue; }

user_defined_types: struct ucontext_t { unsigned long uc_flags; struct ucontext_t *uc_link; struct stack_t uc_stack; struct mcontext_t uc_mcontext; struct __sigset_t uc_sigmask; struct _libc_fpstate __fpregs_mem; unsigned long long __ssp[4]; }

user_defined_types: struct mcontext_t { long long gregs[23]; struct _libc_fpstate *fpregs; unsigned long long __reserved1[8]; }

user_defined_types: struct _libc_fpstate { unsigned short cwd; unsigned short swd; unsigned short ftw; unsigned short fop; unsigned long rip; unsigned long rdp; unsigned int mxcsr; unsigned int mxcr_mask; struct _libc_fpxreg _st[8]; struct _libc_xmmreg _xmm[16]; unsigned int __glibc_reserved1[24]; }


philosophize

decompiled_code:
int __fastcall philosophize(int *a1)
{
unsigned int v1; // ebx
int result; // eax

ta_sem_wait();
v1 = a1[1];
a1[1] = v1 + 1;
ta_sem_signal();
for ( result = fprintf(_bss_start, "Philosopher %d has been seated\n", v1); !*a1; result = *a1 )
{
think(v1);
take_chopsticks(v1, (__int64)a1);
eat(v1);
release_chopsticks(v1, (__int64)a1);
}
return result;
}

canonical_decompiled_code:
int __fastcall func13(int *a1)
{
unsigned int v1; // ebx
int result; // eax

ta_sem_wait();
v1 = a1[1];
a1[1] = v1 + 1;
ta_sem_signal();
for ( result = fprintf(_bss_start, "Philosopher %d has been seated\n", v1); !*a1; result = *a1 )
{
func8(v1);
func11(v1, (__int64)a1);
func9(v1);
func12(v1, (__int64)a1);
}
return result;
}

original_code:
void philosophize(void *vptr)
{
    shared_data_t *data = (shared_data_t*)vptr;
    int philosopher_index = 0;
    ta_sem_wait(&data->atTableSem);
    philosopher_index = data->atTable++;
    ta_sem_signal(&data->atTableSem);
    fprintf(stderr, "Philosopher %d has been seated\n", philosopher_index);
    while (!data->stop)
    {
        think(philosopher_index);
        take_chopsticks(philosopher_index, data);
        eat(philosopher_index);
        release_chopsticks(philosopher_index, data);
    }
}

canonical_original_code:
void philosophize(void *vptr)
{
    struct shared_data_t *data = (shared_data_t*)vptr;
    int philosopher_index = 0;
    ta_sem_wait(&data->atTableSem);
    philosopher_index = data->atTable++;
    ta_sem_signal(&data->atTableSem);
    fprintf(stderr, "Philosopher %d has been seated\n", philosopher_index);
    while (!data->stop)
    {
        think(philosopher_index);
        take_chopsticks(philosopher_index, data);
        eat(philosopher_index);
        release_chopsticks(philosopher_index, data);
    }
}

variable_types:
vptr
void *

variable_types: struct shared_data_t { int stop; int atTable; struct tasem_t { int value; struct queue { struct queue_node { struct control_block { struct ucontext_t { unsigned long uc_flags; struct ucontext_t *uc_link; struct stack_t { void *ss_sp; int ss_flags; unsigned long ss_size; } uc_stack; struct mcontext_t { long long gregs[23]; struct _libc_fpstate { unsigned short cwd; unsigned short swd; unsigned short ftw; unsigned short fop; unsigned long rip; unsigned long rdp; unsigned int mxcsr; unsigned int mxcr_mask; struct _libc_fpxreg { unsigned short significand[4]; unsigned short exponent; unsigned short __glibc_reserved1[3]; } _st[8]; struct _libc_xmmreg { unsigned int element[4]; } _xmm[16]; unsigned int __glibc_reserved1[24]; } *fpregs; unsigned long long __reserved1[8]; } uc_mcontext; struct __sigset_t { unsigned long __val[-1]; } uc_sigmask; struct _libc_fpstate __fpregs_mem; unsigned long long __ssp[4]; } *ctx; int status; } *thread; struct queue_node *next; struct queue_node *prev; } *head; struct queue_node *tail; int length; } *w_queue; } atTableSem; struct tasem_t chopstickSem[5]; } *

user_defined_types: struct shared_data_t { int stop; int atTable; struct tasem_t atTableSem; struct tasem_t chopstickSem[5]; }


SuperFastHash

original_code:
uint32_t SuperFastHash (const char *data, int len) {
 uint32_t hash = 0, tmp;
 int rem;
 if (len <= 0 || data == ((void *)0)) return 0;
 rem = len & 3;
 len >>= 2;
 for (;len > 0; len--) {
  hash += ((((uint32_t)(((const uint8_t *)(data))[1])) << 8) +(uint32_t)(((const uint8_t *)(data))[0]) );
  tmp = (((((uint32_t)(((const uint8_t *)(data+2))[1])) << 8) +(uint32_t)(((const uint8_t *)(data+2))[0]) ) << 11) ^ hash;
  hash = (hash << 16) ^ tmp;
  data += 2*sizeof (uint16_t);
  hash += hash >> 11;
 }
 switch (rem) {
  case 3: hash += ((((uint32_t)(((const uint8_t *)(data))[1])) << 8) +(uint32_t)(((const uint8_t *)(data))[0]) );
    hash ^= hash << 16;
    hash ^= data[sizeof (uint16_t)] << 18;
    hash += hash >> 11;
    break;
  case 2: hash += ((((uint32_t)(((const uint8_t *)(data))[1])) << 8) +(uint32_t)(((const uint8_t *)(data))[0]) );
    hash ^= hash << 11;
    hash += hash >> 17;
    break;
  case 1: hash += *data;
    hash ^= hash << 10;
    hash += hash >> 1;
 }
 hash ^= hash << 3;
 hash += hash >> 5;
 hash ^= hash << 4;
 hash += hash >> 17;
 hash ^= hash << 25;
 hash += hash >> 6;
 return hash;
}

canonical_original_code:
unsigned int SuperFastHash(char *data, int len) {
 unsigned int hash = 0; unsigned int tmp;
 int rem;
 if (len <= 0 || data == ((void *)0)) return 0;
 rem = len & 3;
 len >>= 2;
 for (;len > 0; len--) {
  hash += ((((unsigned int)(((unsigned char *)(data))[1])) << 8) +(unsigned int)(((unsigned char *)(data))[0]) );
  tmp = (((((unsigned int)(((unsigned char *)(data+2))[1])) << 8) +(unsigned int)(((unsigned char *)(data+2))[0]) ) << 11) ^ hash;
  hash = (hash << 16) ^ tmp;
  data += 2*sizeof (unsigned short);
  hash += hash >> 11;
 }
 switch (rem) {
  case 3: hash += ((((unsigned int)(((unsigned char *)(data))[1])) << 8) +(unsigned int)(((unsigned char *)(data))[0]) );
    hash ^= hash << 16;
    hash ^= data[sizeof (unsigned short)] << 18;
    hash += hash >> 11;
    break;
  case 2: hash += ((((unsigned int)(((unsigned char *)(data))[1])) << 8) +(unsigned int)(((unsigned char *)(data))[0]) );
    hash ^= hash << 11;
    hash += hash >> 17;
    break;
  case 1: hash += *data;
    hash ^= hash << 10;
    hash += hash >> 1;
 }
 hash ^= hash << 3;
 hash += hash >> 5;
 hash ^= hash << 4;
 hash += hash >> 17;
 hash ^= hash << 25;
 hash += hash >> 6;
 return hash;
}

variable_types:
data
char *

variable_types: len int

variable_types:
hash
unsigned int

variable_types:
tmp
unsigned int

variable_types: rem int

return_type: unsigned int