main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int v3; // eax
unsigned int v4; // eax
__int64 v5; // rax
unsigned int v6; // eax
unsigned int v7; // eax
__int64 v8; // rax
unsigned int v10; // [rsp+4h] [rbp-14h]
__int64 v11; // [rsp+8h] [rbp-10h]
__int64 v12; // [rsp+8h] [rbp-10h]

puts(" ................");
printf("Enter 16 hexadeximal digits: ");
__isoc99_scanf();
printf("Enter hexadeximal digits for new exponent: ");
__isoc99_scanf();
putchar(10);
printf("entered number (hex) %016llx\n", v11);
v3 = exp_bits(v11);
printf("number of exp bits are (dec) %16u\n", v3);
v4 = get_exponent(v11);
printf("value of exponent is (hex) %16x\n", v4);
v5 = get_mantissa(v11);
printf("value of mantissa is (hex) %16llx\n", v5);
v12 = set_exponent(v11, v10);
putchar(10);
printf("modified number (hex) %016llx\n", v12);
v6 = exp_bits(v12);
printf("number of exp bits are (dec) %16u\n", v6);
v7 = get_exponent(v12);
printf("value of exponent is (hex) %16x\n", v7);
v8 = get_mantissa(v12);
printf("value of mantissa is (hex) %16llx\n", v8);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int v3; // eax
unsigned int v4; // eax
__int64 v5; // rax
unsigned int v6; // eax
unsigned int v7; // eax
__int64 v8; // rax
unsigned int v10; // [rsp+4h] [rbp-14h]
__int64 v11; // [rsp+8h] [rbp-10h]
__int64 v12; // [rsp+8h] [rbp-10h]

puts(" ................");
printf("Enter 16 hexadeximal digits: ");
__isoc99_scanf();
printf("Enter hexadeximal digits for new exponent: ");
__isoc99_scanf();
putchar(10);
printf("entered number (hex) %016llx\n", v11);
v3 = func7(v11);
printf("number of exp bits are (dec) %16u\n", v3);
v4 = func8(v11);
printf("value of exponent is (hex) %16x\n", v4);
v5 = func10(v11);
printf("value of mantissa is (hex) %16llx\n", v5);
v12 = func9(v11, v10);
putchar(10);
printf("modified number (hex) %016llx\n", v12);
v6 = func7(v12);
printf("number of exp bits are (dec) %16u\n", v6);
v7 = func8(v12);
printf("value of exponent is (hex) %16x\n", v7);
v8 = func10(v12);
printf("value of mantissa is (hex) %16llx\n", v8);
return 0;
}

original_code:
int main()
{
  ulli number;
  uint new_exponent;
  printf("                             ................\n");
  printf("Enter 16 hexadeximal digits: ");
  scanf("%llx", &number);
  printf("Enter hexadeximal digits for new exponent: ");
  scanf("%x", &new_exponent);
  printf("\n");
  printf("entered number         (hex) %016llx\n", number);
  printf("number of exp bits are (dec) %16u\n", exp_bits(number));
  printf("value of exponent is   (hex) %16x\n", get_exponent(number));
  printf("value of mantissa is   (hex) %16llx\n", get_mantissa(number));
  number = set_exponent(number, new_exponent);
  printf("\n");
  printf("modified number        (hex) %016llx\n", number);
  printf("number of exp bits are (dec) %16u\n", exp_bits(number));
  printf("value of exponent is   (hex) %16x\n", get_exponent(number));
  printf("value of mantissa is   (hex) %16llx\n", get_mantissa(number));
  return 0;
}

canonical_original_code:
int main()
{
  unsigned long long number;
  unsigned int new_exponent;
  printf("                             ................\n");
  printf("Enter 16 hexadeximal digits: ");
  scanf("%llx", &number);
  printf("Enter hexadeximal digits for new exponent: ");
  scanf("%x", &new_exponent);
  printf("\n");
  printf("entered number         (hex) %016llx\n", number);
  printf("number of exp bits are (dec) %16u\n", exp_bits(number));
  printf("value of exponent is   (hex) %16x\n", get_exponent(number));
  printf("value of mantissa is   (hex) %16llx\n", get_mantissa(number));
  number = set_exponent(number, new_exponent);
  printf("\n");
  printf("modified number        (hex) %016llx\n", number);
  printf("number of exp bits are (dec) %16u\n", exp_bits(number));
  printf("value of exponent is   (hex) %16x\n", get_exponent(number));
  printf("value of mantissa is   (hex) %16llx\n", get_mantissa(number));
  return 0;
}

variable_types:
number
unsigned long long


decompiled_code:
void set_display()
{
;
}

canonical_decompiled_code:
void func1()
{
;
}

original_code:
void set_display(int value)
{
}

canonical_original_code:
void set_display(int value)
{
}

variable_types: value int

return_type: void


decompiled_code:
void seconds_to_display()
{
;
}

canonical_decompiled_code:
void func2()
{
;
}

original_code:
void seconds_to_display(int seconds)
{
  set_display( 0 );
}

variable_types: seconds int


Heat

decompiled_code:
void Heat()
{
;
}

canonical_decompiled_code:
void func4()
{
;
}

original_code:
void Heat()
{
}

canonical_original_code:
void Heat()
{
}


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

result = (unsigned int)state_1;
if ( state_1 == 2 )
{
result = A;
if ( (A & 1) != 0 )
{
clock += 20;
++press_count_0;
}
else
{
result = A;
if ( (A & 2) != 0 )
{
result = (unsigned int)(clock / 2);
clock /= 2;
press_count_0 = 0;
state_1 = 1;
goto LABEL_8;
}
}
if ( press_count_0 > 5 )
{
press_count_0 = 0;
state_1 = 3;
}
goto LABEL_8;
}
if ( (unsigned int)state_1 > 2 )
{
if ( state_1 == 3 )
{
result = A;
if ( (A & 1) != 0 )
{
clock += 60;
state_1 = 3;
}
else
{
result = A;
if ( (A & 2) != 0 )
{
result = (unsigned int)(clock / 2);
clock /= 2;
press_count_0 = 0;
state_1 = 1;
}
}
}
goto LABEL_8;
}
if ( !state_1 )
{
press_count_0 = 0;
state_1 = 1;
clock = 0;
return result;
}
result = A;
if ( (A & 1) != 0 )
{
clock += 10;
++press_count_0;
goto LABEL_6;
}
result = A;
if ( (A & 2) == 0 )
{
LABEL_6:
if ( press_count_0 > 5 )
{
press_count_0 = 0;
state_1 = 2;
}
goto LABEL_8;
}
result = (unsigned int)(clock / 2);
clock /= 2;
press_count_0 = 0;
LABEL_8:
if ( clock > 5999 )
clock = 5999;
return result;
}

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

result = (unsigned int)state_1;
if ( state_1 == 2 )
{
result = A;
if ( (A & 1) != 0 )
{
clock += 20;
++press_count_0;
}
else
{
result = A;
if ( (A & 2) != 0 )
{
result = (unsigned int)(clock / 2);
clock /= 2;
press_count_0 = 0;
state_1 = 1;
goto LABEL_8;
}
}
if ( press_count_0 > 5 )
{
press_count_0 = 0;
state_1 = 3;
}
goto LABEL_8;
}
if ( (unsigned int)state_1 > 2 )
{
if ( state_1 == 3 )
{
result = A;
if ( (A & 1) != 0 )
{
clock += 60;
state_1 = 3;
}
else
{
result = A;
if ( (A & 2) != 0 )
{
result = (unsigned int)(clock / 2);
clock /= 2;
press_count_0 = 0;
state_1 = 1;
}
}
}
goto LABEL_8;
}
if ( !state_1 )
{
press_count_0 = 0;
state_1 = 1;
clock = 0;
return result;
}
result = A;
if ( (A & 1) != 0 )
{
clock += 10;
++press_count_0;
goto LABEL_6;
}
result = A;
if ( (A & 2) == 0 )
{
LABEL_6:
if ( press_count_0 > 5 )
{
press_count_0 = 0;
state_1 = 2;
}
goto LABEL_8;
}
result = (unsigned int)(clock / 2);
clock /= 2;
press_count_0 = 0;
LABEL_8:
if ( clock > 5999 )
clock = 5999;
return result;
}

original_code:
void Set_Time()
{
  static enum {INIT,INC_10S, INC_20S, INC_1M} state = INIT;
  static int press_count;
  switch (state)
  {
    case INIT:
      press_count = 0;
      state = INC_10S;
      clock = 0;
      break;
    case INC_10S:
      if ( (A & 0x01) )
      {
        clock += 10;
        ++press_count;
      }
      else if ( (A & 0x02) )
      {
        clock /= 2;
        press_count = 0;
      }
      if (press_count >= 6)
      {
        press_count = 0;
        state = INC_20S;
      }
      break;
    case INC_20S:
      if ( (A & 0x01) )
      {
        clock += 20;
        ++press_count;
      }
      else if ( (A & 0x02) )
      {
        clock /= 2;
        press_count = 0;
        state = INC_10S;
      }
      if (press_count >= 6)
      {
        press_count = 0;
        state = INC_1M;
      }
      break;
    case INC_1M:
      if ( (A & 0x01) )
      {
        clock += 60;
        state = INC_1M;
      }
      else if ( (A & 0x02) )
      {
        clock /= 2;
        press_count = 0;
        state = INC_10S;
      }
      break;
  }
  switch (state)
  {
    case INIT:
      break;
    case INC_10S:
      time_set = (clock != 0);
      break;
    case INC_20S:
      time_set = (clock != 0);
      break;
    case INC_1M:
      time_set = (clock != 0);
      break;
  }
  if (clock > 99*60+59)
    clock = 99*60+59;
}

canonical_original_code:
void Set_Time()
{
  static enum { INIT=0, INC_10S=1, INC_20S=2, INC_1M=3 } state = INIT;
  static int press_count;
  switch (state)
  {
    case INIT:
      press_count = 0;
      state = INC_10S;
      clock = 0;
      break;
    case INC_10S:
      if ( (A & 0x01) )
      {
        clock += 10;
        ++press_count;
      }
      else if ( (A & 0x02) )
      {
        clock /= 2;
        press_count = 0;
      }
      if (press_count >= 6)
      {
        press_count = 0;
        state = INC_20S;
      }
      break;
    case INC_20S:
      if ( (A & 0x01) )
      {
        clock += 20;
        ++press_count;
      }
      else if ( (A & 0x02) )
      {
        clock /= 2;
        press_count = 0;
        state = INC_10S;
      }
      if (press_count >= 6)
      {
        press_count = 0;
        state = INC_1M;
      }
      break;
    case INC_1M:
      if ( (A & 0x01) )
      {
        clock += 60;
        state = INC_1M;
      }
      else if ( (A & 0x02) )
      {
        clock /= 2;
        press_count = 0;
        state = INC_10S;
      }
      break;
  }
  switch (state)
  {
    case INIT:
      break;
    case INC_10S:
      time_set = (clock != 0);
      break;
    case INC_20S:
      time_set = (clock != 0);
      break;
    case INC_1M:
      time_set = (clock != 0);
      break;
  }
  if (clock > 99*60+59)
    clock = 99*60+59;
}


TimerISR

decompiled_code:
void TimerISR()
{
timer_period_elapsed = 1;
}

canonical_decompiled_code:
void func0()
{
timer_period_elapsed = 1;
}


decompiled_code:
__int64 app_main()
{
int i; // ebx
__int64 result; // rax

TimerSet(200LL);
TimerOn();
B = 0;
for ( i = 0; ; ++i )
{
result = true_test(1LL, "1");
if ( !(_DWORD)result )
break;
while ( (unsigned int)true_test(timer_period_elapsed == 0, "! timer_period_elapsed") )
;
timer_period_elapsed = 0;
B = i;
}
return result;
}

canonical_decompiled_code:
__int64 func3()
{
int i; // ebx
__int64 result; // rax

TimerSet(200LL);
TimerOn();
B = 0;
for ( i = 0; ; ++i )
{
result = true_test(1LL, "1");
if ( !(_DWORD)result )
break;
while ( (unsigned int)true_test(timer_period_elapsed == 0, "! timer_period_elapsed") )
;
timer_period_elapsed = 0;
B = i;
}
return result;
}

original_code:
int app_main(void)
{
   TimerSet(200);
   TimerOn();
   B = 0;
   byte count = 0;
   while ( true_test(1, "1") )
   {
     while ( true_test(! timer_period_elapsed, "! timer_period_elapsed") )
       ;
     timer_period_elapsed = 0;
     B = count;
     count = (count + 1);
   }
   return 0;
}

canonical_original_code:
int app_main()
{
   TimerSet(200);
   TimerOn();
   B = 0;
   unsigned char count = 0;
   while ( true_test(1, "1") )
   {
     while ( true_test(! timer_period_elapsed, "! timer_period_elapsed") )
       ;
     timer_period_elapsed = 0;
     B = count;
     count = (count + 1);
   }
   return 0;
}

variable_types:
count
unsigned char

return_type: int


HotelSafe

decompiled_code:
void HotelSafe()
{
;
}

original_code:
void HotelSafe()
{
}

canonical_original_code:
void HotelSafe()
{
}


Safe

decompiled_code:
int Safe()
{
int v0; // eax
__int64 v2[9]; // [rsp+0h] [rbp-48h]

v2[0] = (__int64)"LOCK";
v2[1] = (__int64)"PIN1";
v2[2] = (__int64)"PIN2";
v2[3] = (__int64)"PIN3";
v2[4] = (__int64)"PINX";
v2[5] = (__int64)"OPEN";
v2[6] = 0LL;
printf("Entry State = %s, A = %d\n", (const char *)v2[state_5], A);
v0 = state_5;
switch ( state_5 )
{
case 0:
if ( A != pin1_4 )
goto LABEL_3;
state_5 = 1;
goto LABEL_8;
case 1:
if ( A == pin2_3 )
{
state_5 = 2;
LABEL_12:
v0 = state_5;
LABEL_13:
B = 0;
pin3_2 += 2;
}
else
{
LABEL_8:
v0 = state_5;
LABEL_9:
B = 0;
++pin2_3;
}
break;
case 2:
if ( A != pin3_2 )
goto LABEL_12;
state_5 = 3;
LABEL_16:
v0 = state_5;
LABEL_17:
B = 0;
pin4_1 += 3;
count_0 = 0;
break;
case 3:
if ( A != pin4_1 )
goto LABEL_16;
state_5 = 4;
LABEL_20:
v0 = state_5;
LABEL_21:
B = 0;
++count_0;
break;
case 4:
if ( count_0 != 4 )
goto LABEL_20;
state_5 = 5;
LABEL_24:
v0 = state_5;
LABEL_25:
B = 2;
break;
case 5:
if ( A != 11 )
goto LABEL_24;
state_5 = 0;
LABEL_3:
v0 = state_5;
LABEL_4:
B = 1;
pin1_4 = 1;
pin2_3 = 1;
pin3_2 = 1;
pin4_1 = 1;
break;
default:
switch ( state_5 )
{
case 0:
goto LABEL_4;
case 1:
goto LABEL_9;
case 2:
goto LABEL_13;
case 3:
goto LABEL_17;
case 4:
goto LABEL_21;
case 5:
goto LABEL_25;
default:
return printf("Exit State = %s\n", (const char *)v2[v0]);
}
return printf("Exit State = %s\n", (const char *)v2[v0]);
}
return printf("Exit State = %s\n", (const char *)v2[v0]);
}

canonical_decompiled_code:
int func3()
{
int v0; // eax
__int64 v2[9]; // [rsp+0h] [rbp-48h]

v2[0] = (__int64)"LOCK";
v2[1] = (__int64)"PIN1";
v2[2] = (__int64)"PIN2";
v2[3] = (__int64)"PIN3";
v2[4] = (__int64)"PINX";
v2[5] = (__int64)"OPEN";
v2[6] = 0LL;
printf("Entry State = %s, A = %d\n", (const char *)v2[state_5], A);
v0 = state_5;
switch ( state_5 )
{
case 0:
if ( A != pin1_4 )
goto LABEL_3;
state_5 = 1;
goto LABEL_8;
case 1:
if ( A == pin2_3 )
{
state_5 = 2;
LABEL_12:
v0 = state_5;
LABEL_13:
B = 0;
pin3_2 += 2;
}
else
{
LABEL_8:
v0 = state_5;
LABEL_9:
B = 0;
++pin2_3;
}
break;
case 2:
if ( A != pin3_2 )
goto LABEL_12;
state_5 = 3;
LABEL_16:
v0 = state_5;
LABEL_17:
B = 0;
pin4_1 += 3;
count_0 = 0;
break;
case 3:
if ( A != pin4_1 )
goto LABEL_16;
state_5 = 4;
LABEL_20:
v0 = state_5;
LABEL_21:
B = 0;
++count_0;
break;
case 4:
if ( count_0 != 4 )
goto LABEL_20;
state_5 = 5;
LABEL_24:
v0 = state_5;
LABEL_25:
B = 2;
break;
case 5:
if ( A != 11 )
goto LABEL_24;
state_5 = 0;
LABEL_3:
v0 = state_5;
LABEL_4:
B = 1;
pin1_4 = 1;
pin2_3 = 1;
pin3_2 = 1;
pin4_1 = 1;
break;
default:
switch ( state_5 )
{
case 0:
goto LABEL_4;
case 1:
goto LABEL_9;
case 2:
goto LABEL_13;
case 3:
goto LABEL_17;
case 4:
goto LABEL_21;
case 5:
goto LABEL_25;
default:
return printf("Exit State = %s\n", (const char *)v2[v0]);
}
return printf("Exit State = %s\n", (const char *)v2[v0]);
}
return printf("Exit State = %s\n", (const char *)v2[v0]);
}

original_code:
void Safe()
{
  static enum { LOCK, PIN1, PIN2, PIN3, PINX, OPEN } state = LOCK;
  const char* debug[] = {
    "LOCK", "PIN1", "PIN2", "PIN3", "PINX", "OPEN", 0
  };
  static byte pin1 = 1, pin2 = 1, pin3 = 1, pin4 = 1;
  static byte count = 0;
  printf("Entry State = %s, A = %d\n", debug[state], A);
  switch( state )
  {
    case LOCK: if ( A == pin1 ) state = PIN1; break;
    case PIN1: if ( A == pin2 ) state = PIN2; break;
    case PIN2: if ( A == pin3 ) state = PIN3; break;
    case PIN3: if ( A == pin4 ) state = PINX; break;
    case PINX: if ( count == 4 ) state = OPEN; break;
    case OPEN: if ( A == 11 ) state = LOCK; break;
  }
  switch( state )
  {
    case LOCK: B = 1; pin1 = 1, pin2 = 1, pin3 = 1, pin4 = 1; break;
    case PIN1: B = 0; pin2 += 1; break;
    case PIN2: B = 0; pin3 += 2; break;
    case PIN3: B = 0; pin4 += 3; count = 0; break;
    case PINX: B = 0; ++count; break;
    case OPEN: B = 2; break;
  }
  printf("Exit State = %s\n", debug[state]);
}

canonical_original_code:
void Safe()
{
  static enum { LOCK=0, PIN1=1, PIN2=2, PIN3=3, PINX=4, OPEN=5 } state = LOCK;
  char *debug[] = {
    "LOCK", "PIN1", "PIN2", "PIN3", "PINX", "OPEN", 0
  };
  static unsigned char pin1 = 1; static unsigned char pin2 = 1; static unsigned char pin3 = 1; static unsigned char pin4 = 1;
  static unsigned char count = 0;
  printf("Entry State = %s, A = %d\n", debug[state], A);
  switch( state )
  {
    case LOCK: if ( A == pin1 ) state = PIN1; break;
    case PIN1: if ( A == pin2 ) state = PIN2; break;
    case PIN2: if ( A == pin3 ) state = PIN3; break;
    case PIN3: if ( A == pin4 ) state = PINX; break;
    case PINX: if ( count == 4 ) state = OPEN; break;
    case OPEN: if ( A == 11 ) state = LOCK; break;
  }
  switch( state )
  {
    case LOCK: B = 1; pin1 = 1, pin2 = 1, pin3 = 1, pin4 = 1; break;
    case PIN1: B = 0; pin2 += 1; break;
    case PIN2: B = 0; pin3 += 2; break;
    case PIN3: B = 0; pin4 += 3; count = 0; break;
    case PINX: B = 0; ++count; break;
    case OPEN: B = 2; break;
  }
  printf("Exit State = %s\n", debug[state]);
}

variable_types:
debug
char *[]


KeyboardISR

decompiled_code:
int KeyboardISR()
{
return Safe();
}

canonical_decompiled_code:
int func4()
{
return func3();
}

original_code:
void KeyboardISR()
{
  Safe();
}

canonical_original_code:
void KeyboardISR()
{
  Safe();
}


TimerISR

decompiled_code:
void TimerISR()
{
;
}

canonical_decompiled_code:
void func0()
{
;
}

original_code:
void TimerISR()
{
}

canonical_original_code:
void TimerISR()
{
}


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

B = 1;
do
result = true_test(1LL, &unk_234);
while ( (_DWORD)result );
return result;
}

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

B = 1;
do
result = true_test(1LL, &unk_234);
while ( (_DWORD)result );
return result;
}

original_code:
int app_main(void)
{
   B = 1;
   while ( true_test(1, "1") )
   {
   }
   return 0;
}

canonical_original_code:
int app_main()
{
   B = 1;
   while ( true_test(1, "1") )
   {
   }
   return 0;
}


decompiled_code:
char BLINK_Tick()
{
char result; // al

result = BLINK_State;
if ( BLINK_State )
{
if ( BLINK_State != 1 )
{
BLINK_State = 0;
LABEL_4:
B = 0;
return result;
}
result = A;
if ( A <= 5u )
{
BLINK_State = 0;
goto LABEL_4;
}
}
else
{
result = A;
if ( A <= 5u )
goto LABEL_4;
BLINK_State = 1;
}
result = B == 0;
B = B == 0;
return result;
}

canonical_decompiled_code:
char func1()
{
char result; // al

result = BLINK_State;
if ( BLINK_State )
{
if ( BLINK_State != 1 )
{
BLINK_State = 0;
LABEL_4:
B = 0;
return result;
}
result = A;
if ( A <= 5u )
{
BLINK_State = 0;
goto LABEL_4;
}
}
else
{
result = A;
if ( A <= 5u )
goto LABEL_4;
BLINK_State = 1;
}
result = B == 0;
B = B == 0;
return result;
}

original_code:
void BLINK_Tick() {
   switch(BLINK_State) {
         case BLINK_OFF:
         if (A > 5) {
            BLINK_State = BLINK_BLINK;
         }
         break;
      case BLINK_BLINK:
         if (A <= 5) {
            BLINK_State = BLINK_OFF;
         }
         break;
      default:
         BLINK_State = BLINK_OFF;
   }
   switch(BLINK_State) {
      case BLINK_OFF:
         B = 0;
         break;
      case BLINK_BLINK:
         B = !B;
         break;
      default:
      break;
   }
}


decompiled_code:
void TimerISR()
{
BLINK_Clk = 1;
}

canonical_decompiled_code:
void func0()
{
BLINK_Clk = 1;
}

original_code:
void TimerISR() {
   BLINK_Clk = 1;
}

canonical_original_code:
void TimerISR() {
   BLINK_Clk = 1;
}


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

TimerSet(300LL);
TimerOn();
BLINK_State = -1;
B = 0;
while ( 1 )
{
result = true_test(1LL, "1");
if ( !(_DWORD)result )
break;
BLINK_Tick();
while ( (unsigned int)true_test(BLINK_Clk == 0, "!BLINK_Clk") )
;
BLINK_Clk = 0;
}
return result;
}

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

TimerSet(300LL);
TimerOn();
BLINK_State = -1;
B = 0;
while ( 1 )
{
result = true_test(1LL, "1");
if ( !(_DWORD)result )
break;
func1();
while ( (unsigned int)true_test(BLINK_Clk == 0, "!BLINK_Clk") )
;
BLINK_Clk = 0;
}
return result;
}

original_code:
int app_main(void)
{
  const unsigned int BLINK_Period = 300;
  TimerSet(BLINK_Period);
  TimerOn();
  BLINK_State = -1;
  B = 0;
  while ( true_test(1, "1") )
  {
    BLINK_Tick();
    while ( true_test(!BLINK_Clk, "!BLINK_Clk") )
      ;
    BLINK_Clk = 0;
  }
  return 0;
}

canonical_original_code:
int app_main()
{
  unsigned int BLINK_Period = 300;
  TimerSet(BLINK_Period);
  TimerOn();
  BLINK_State = -1;
  B = 0;
  while ( true_test(1, "1") )
  {
    BLINK_Tick();
    while ( true_test(!BLINK_Clk, "!BLINK_Clk") )
      ;
    BLINK_Clk = 0;
  }
  return 0;
}


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

result = A;
if ( A < 0 )
{
result = 0LL;
if ( blink_state != 2 )
result = (unsigned int)(blink_state + 1);
blink_state = result;
}
return result;
}

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

result = A;
if ( A < 0 )
{
result = 0LL;
if ( blink_state != 2 )
result = (unsigned int)(blink_state + 1);
blink_state = result;
}
return result;
}

original_code:
void button_press()
{
  byte A_READ = A & 128;
  if (A_READ)
    blink_state == ON ? blink_state = OFF : blink_state++;
}

canonical_original_code:
void button_press()
{
  unsigned char A_READ = A & 128;
  if (A_READ)
    blink_state == ON ? blink_state = OFF : blink_state++;
}


enable

decompiled_code:
__int64 enable()
{
__int64 result; // rax
bool v1; // zf

result = (unsigned int)motion_state;
if ( motion_state == 2 )
{
LOBYTE(result) = lamp_state != 0;
result = (unsigned int)-(int)result;
B = result;
if ( (A & 0x7C) != 0 )
{
counter = 100;
return result;
}
}
else
{
if ( (unsigned int)motion_state <= 2 )
{
if ( motion_state )
{
result = 2 * (unsigned int)((A & 0x7C) != 0);
motion_state = 2 * ((A & 0x7C) != 0);
}
else
{
B = 0;
if ( (A & 0x7C) != 0 )
motion_state = 1;
}
return result;
}
if ( motion_state != 3 )
return result;
}
v1 = counter == 1;
result = (unsigned int)--counter;
if ( v1 )
motion_state = 0;
return result;
}

canonical_decompiled_code:
__int64 func2()
{
__int64 result; // rax
bool v1; // zf

result = (unsigned int)motion_state;
if ( motion_state == 2 )
{
LOBYTE(result) = lamp_state != 0;
result = (unsigned int)-(int)result;
B = result;
if ( (A & 0x7C) != 0 )
{
counter = 100;
return result;
}
}
else
{
if ( (unsigned int)motion_state <= 2 )
{
if ( motion_state )
{
result = 2 * (unsigned int)((A & 0x7C) != 0);
motion_state = 2 * ((A & 0x7C) != 0);
}
else
{
B = 0;
if ( (A & 0x7C) != 0 )
motion_state = 1;
}
return result;
}
if ( motion_state != 3 )
return result;
}
v1 = counter == 1;
result = (unsigned int)--counter;
if ( v1 )
motion_state = 0;
return result;
}

original_code:
void enable()
{
  byte A_READ = A & 127;
  switch(motion_state)
    {
    case SLEEP:
      B = 0;
      if (A_READ > 3)
 ++motion_state;
      break;
    case DATA:
      if (A_READ > 3)
 ++motion_state;
      else
 motion_state = SLEEP;
      break;
    case ROAD:
      B = (lamp_state) ? 255 : 0;
      if (A_READ > 3) {
 counter = 100;
 break;
      }
    case COUNTER:
      if (--counter == 0) {
 motion_state = SLEEP;
      }
      break;
    }
}

canonical_original_code:
void enable()
{
  unsigned char A_READ = A & 127;
  switch(motion_state)
    {
    case SLEEP:
      B = 0;
      if (A_READ > 3)
 ++motion_state;
      break;
    case DATA:
      if (A_READ > 3)
 ++motion_state;
      else
 motion_state = SLEEP;
      break;
    case ROAD:
      B = (lamp_state) ? 255 : 0;
      if (A_READ > 3) {
 counter = 100;
 break;
      }
    case COUNTER:
      if (--counter == 0) {
 motion_state = SLEEP;
      }
      break;
    }
}


toggle

decompiled_code:
__int64 toggle()
{
if ( blink_state == 1 )
{
button_press();
lamp_state = lamp_state == 0;
}
else if ( blink_state == 2 )
{
button_press();
lamp_state = 1;
}
else
{
if ( blink_state )
{
blink_state = 0;
}
else
{
button_press();
lamp_state = 0;
}
counter = 0;
}
return enable();
}

canonical_decompiled_code:
__int64 func3()
{
if ( blink_state == 1 )
{
func1();
lamp_state = lamp_state == 0;
}
else if ( blink_state == 2 )
{
func1();
lamp_state = 1;
}
else
{
if ( blink_state )
{
blink_state = 0;
}
else
{
func1();
lamp_state = 0;
}
counter = 0;
}
return func2();
}

original_code:
void toggle()
{
  switch (blink_state) {
    case OFF:
      button_press();
      lamp_state = false;
      counter = 0;
      break;
    case BLINK:
      button_press();
      lamp_state = !lamp_state;
      break;
    case ON:
      button_press();
      lamp_state = true;
      break;
    default:
      blink_state = OFF;
      counter = 0;
      break;
  }
  enable();
}


TimerISR

decompiled_code:
void TimerISR()
{
T_FLAG = 1;
}

canonical_decompiled_code:
void func0()
{
T_FLAG = 1;
}

original_code:
void TimerISR() {
  T_FLAG = 1;
}

canonical_original_code:
void TimerISR() {
  T_FLAG = 1;
}


decompiled_code:
void __noreturn app_main()
{
TimerSet(100LL);
TimerOn();
B = 0;
blink_state = 0;
motion_state = 0;
counter = 0;
for ( T_FLAG = 0; ; T_FLAG = 0 )
{
toggle();
while ( (unsigned int)true_test(T_FLAG == 0, "!T_FLAG") )
;
}
}

canonical_decompiled_code:
void __noreturn func4()
{
TimerSet(100LL);
TimerOn();
B = 0;
blink_state = 0;
motion_state = 0;
counter = 0;
for ( T_FLAG = 0; ; T_FLAG = 0 )
{
func3();
while ( (unsigned int)true_test(T_FLAG == 0, "!T_FLAG") )
;
}
}

original_code:
int app_main(void)
{
  TimerSet(100);
  TimerOn();
  B = 0;
  blink_state = OFF;
  motion_state = SLEEP;
  counter = 0;
  T_FLAG = 0;
  for (;;)
  {
    toggle();
    while ( true_test(!T_FLAG, "!T_FLAG") )
      ;
    T_FLAG = 0;
  }
  return 0;
}

canonical_original_code:
int app_main()
{
  TimerSet(100);
  TimerOn();
  B = 0;
  blink_state = OFF;
  motion_state = SLEEP;
  counter = 0;
  T_FLAG = 0;
  for (;;)
  {
    toggle();
    while ( true_test(!T_FLAG, "!T_FLAG") )
      ;
    T_FLAG = 0;
  }
  return 0;
}


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

for ( result = *(_QWORD *)routers; result; result = *(_QWORD *)(result + 32) )
{
if ( *(_DWORD *)result == *a1
&& *(_DWORD *)(result + 4) == a1[1]
&& *(_DWORD *)(result + 8) == a1[2]
&& *(_DWORD *)(result + 12) == a1[3]
&& *(_DWORD *)(result + 24) == a2 )
{
break;
}
}
return result;
}

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

for ( result = *(_QWORD *)routers; result; result = *(_QWORD *)(result + 32) )
{
if ( *(_DWORD *)result == *a1
&& *(_DWORD *)(result + 4) == a1[1]
&& *(_DWORD *)(result + 8) == a1[2]
&& *(_DWORD *)(result + 12) == a1[3]
&& *(_DWORD *)(result + 24) == a2 )
{
break;
}
}
return result;
}

original_code:
static struct Router *
find_router(const struct in6_addr *addr, int if_index) {
    struct Router *iter;
    for((iter) = (routers)->slh_first; (iter); (iter) = (iter)->entries.sle_next) {
        if ((__extension__ ({ const struct in6_addr *__a = (const struct in6_addr *) (&iter->addr); const struct in6_addr *__b = (const struct in6_addr *) (addr); __a->__in6_u.__u6_addr32[0] == __b->__in6_u.__u6_addr32[0] && __a->__in6_u.__u6_addr32[1] == __b->__in6_u.__u6_addr32[1] && __a->__in6_u.__u6_addr32[2] == __b->__in6_u.__u6_addr32[2] && __a->__in6_u.__u6_addr32[3] == __b->__in6_u.__u6_addr32[3]; })) && iter->if_index == if_index)
            return iter;
    }
    return ((void *)0);
}

canonical_original_code:
static struct Router *find_router(struct in6_addr *addr, int if_index) {
    struct Router *iter;
    for((iter) = (routers)->slh_first; (iter); (iter) = (iter)->entries.sle_next) {
        if ((__extension__ ({ struct in6_addr *__a = (const struct in6_addr *) (&iter->addr); struct in6_addr *__b = (const struct in6_addr *) (addr); __a->__in6_u.__u6_addr32[0] == __b->__in6_u.__u6_addr32[0] && __a->__in6_u.__u6_addr32[1] == __b->__in6_u.__u6_addr32[1] && __a->__in6_u.__u6_addr32[2] == __b->__in6_u.__u6_addr32[2] && __a->__in6_u.__u6_addr32[3] == __b->__in6_u.__u6_addr32[3]; })) && iter->if_index == if_index)
            return iter;
    }
    return ((void *)0);
}

variable_types:
addr
struct in6_addr *

variable_types: struct Router { struct in6_addr { union { unsigned char __u6_addr8[16]; unsigned short __u6_addr16[8]; unsigned int __u6_addr32[4]; } __in6_u; } addr; long valid_until; int if_index; struct { struct Router *sle_next; } entries; } *

variable_types: struct in6_addr { union { unsigned char __u6_addr8[16]; unsigned short __u6_addr16[8]; unsigned int __u6_addr32[4]; } __in6_u; } *

user_defined_types: struct Router { struct in6_addr addr; long valid_until; int if_index; struct { struct Router *sle_next; } entries; }


decompiled_code:
void print_routers()
{
__int64 v0; // rbx
int *v1; // rax
char *v2; // rax
int *v3; // rax
char *v4; // rax
char v5[16]; // [rsp+0h] [rbp-48h] BYREF
char buf[56]; // [rsp+10h] [rbp-38h] BYREF

puts("Routers:");
v0 = *(_QWORD *)routers;
if ( *(_QWORD *)routers )
{
while ( 1 )
{
if ( !inet_ntop(10, (const void *)v0, buf, 0x2Eu) )
{
v1 = _errno_location();
v2 = strerror(*v1);
syslog(2, "inet_ntop: %s", v2);
return;
}
if ( !if_indextoname(*(_DWORD *)(v0 + 24), v5) )
break;
printf("\t%s\t%ld\t%s\n", buf, *(_QWORD *)(v0 + 16), v5);
v0 = *(_QWORD *)(v0 + 32);
if ( !v0 )
return;
}
v3 = _errno_location();
v4 = strerror(*v3);
syslog(2, "if_indextoname: %s", v4);
}
}

canonical_decompiled_code:
void func1()
{
__int64 v0; // rbx
int *v1; // rax
char *v2; // rax
int *v3; // rax
char *v4; // rax
char v5[16]; // [rsp+0h] [rbp-48h] BYREF
char buf[56]; // [rsp+10h] [rbp-38h] BYREF

puts("Routers:");
v0 = *(_QWORD *)routers;
if ( *(_QWORD *)routers )
{
while ( 1 )
{
if ( !inet_ntop(10, (const void *)v0, buf, 0x2Eu) )
{
v1 = _errno_location();
v2 = strerror(*v1);
syslog(2, "inet_ntop: %s", v2);
return;
}
if ( !if_indextoname(*(_DWORD *)(v0 + 24), v5) )
break;
printf("\t%s\t%ld\t%s\n", buf, *(_QWORD *)(v0 + 16), v5);
v0 = *(_QWORD *)(v0 + 32);
if ( !v0 )
return;
}
v3 = _errno_location();
v4 = strerror(*v3);
syslog(2, "if_indextoname: %s", v4);
}
}

original_code:
static void print_routers() {
    struct Router *iter;
    char addr_str[46];
    char if_name[16];
    printf("Routers:\n");
    for((iter) = (routers)->slh_first; (iter); (iter) = (iter)->entries.sle_next) {
        if (inet_ntop(10, &iter->addr, addr_str, sizeof(addr_str)) == ((void *)0)) {
            syslog(2, "inet_ntop: %s", strerror((*__errno_location ())));
            return;
        }
        if (if_indextoname(iter->if_index, if_name) == ((void *)0)) {
            syslog(2, "if_indextoname: %s", strerror((*__errno_location ())));
            return;
        }
        printf("\t%s\t%ld\t%s\n", addr_str, iter->valid_until, if_name);
    }
}

user_defined_types: struct in6_addr { union { unsigned char __u6_addr8[16]; unsigned short __u6_addr16[8]; unsigned int __u6_addr32[4]; } __in6_u; }


decompiled_code:
void __fastcall remove_router(void *ptr)
{
_QWORD *v1; // rax
_QWORD *v2; // rdx

v1 = *(_QWORD **)routers;
if ( *(void **)routers == ptr )
{
*(_QWORD *)routers = *((_QWORD *)ptr + 4);
}
else
{
do
{
v2 = v1;
v1 = (_QWORD *)v1[4];
}
while ( v1 != ptr );
v2[4] = *((_QWORD *)ptr + 4);
}
remove_gateway(ptr, *((unsigned int *)ptr + 6));
free(ptr);
}

canonical_decompiled_code:
void __fastcall func2(void *ptr)
{
_QWORD *v1; // rax
_QWORD *v2; // rdx

v1 = *(_QWORD **)routers;
if ( *(void **)routers == ptr )
{
*(_QWORD *)routers = *((_QWORD *)ptr + 4);
}
else
{
do
{
v2 = v1;
v1 = (_QWORD *)v1[4];
}
while ( v1 != ptr );
v2[4] = *((_QWORD *)ptr + 4);
}
remove_gateway(ptr, *((unsigned int *)ptr + 6));
free(ptr);
}

original_code:
static void
remove_router(struct Router *router) {
    do { if ((routers)->slh_first == (router)) { do { ((routers))->slh_first = ((routers))->slh_first->entries.sle_next; } while ( 0); } else { struct Router *curelm = (routers)->slh_first; while(curelm->entries.sle_next != (router)) curelm = curelm->entries.sle_next; curelm->entries.sle_next = curelm->entries.sle_next->entries.sle_next; } } while ( 0);
    remove_gateway(&router->addr, router->if_index);
    free(router);
}


decompiled_code:
_QWORD *init_routers()
{
_QWORD *result; // rax
int *v1; // rax
char *v2; // rax

result = calloc(1uLL, 8uLL);
routers = (__int64)result;
if ( !result )
{
v1 = _errno_location();
v2 = strerror(*v1);
syslog(2, "calloc(): %s", v2);
exit(1);
}
*result = 0LL;
return result;
}

canonical_decompiled_code:
_QWORD *func3()
{
_QWORD *result; // rax
int *v1; // rax
char *v2; // rax

result = calloc(1uLL, 8uLL);
routers = (__int64)result;
if ( !result )
{
v1 = _errno_location();
v2 = strerror(*v1);
syslog(2, "calloc(): %s", v2);
exit(1);
}
*result = 0LL;
return result;
}

original_code:
void
init_routers() {
    routers = calloc(1, sizeof(*routers));
    if (routers == ((void *)0)) {
        syslog(2, "calloc(): %s", strerror((*__errno_location ())));
        exit(1);
    }
    do { (routers)->slh_first = ((void *)0); } while ( 0);
}


decompiled_code:
__int64 __fastcall update_router(__m128i *a1, unsigned __int32 a2, __int64 a3)
{
__int64 result; // rax

result = find_router(a1, a2);
if ( !result )
result = (__int64)add_router(a1, a2);
*(_QWORD *)(result + 16) = a3;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(__m128i *a1, unsigned __int32 a2, __int64 a3)
{
__int64 result; // rax

result = func0(a1, a2);
if ( !result )
result = (__int64)add_router(a1, a2);
*(_QWORD *)(result + 16) = a3;
return result;
}

original_code:
void
update_router(const struct in6_addr *addr, int if_index, time_t valid_until) {
    struct Router *r;
    r = find_router(addr, if_index);
    if (r == ((void *)0))
        r = add_router(addr, if_index);
    r->valid_until = valid_until;
}

canonical_original_code:
void update_router(struct in6_addr *addr, int if_index, long valid_until) {
    struct Router *r;
    r = find_router(addr, if_index);
    if (r == ((void *)0))
        r = add_router(addr, if_index);
    r->valid_until = valid_until;
}


decompiled_code:
void handle_routers()
{
_QWORD *v0; // rbx
_QWORD *v1; // rdi
time_t timer; // [rsp+8h] [rbp-10h] BYREF

print_routers();
time(&timer);
v0 = *(_QWORD **)routers;
if ( *(_QWORD *)routers )
{
do
{
v1 = v0;
v0 = (_QWORD *)v0[4];
if ( v1[2] < timer )
remove_router(v1);
}
while ( v0 );
}
}

canonical_decompiled_code:
void func5()
{
_QWORD *v0; // rbx
_QWORD *v1; // rdi
time_t timer; // [rsp+8h] [rbp-10h] BYREF

func1();
time(&timer);
v0 = *(_QWORD **)routers;
if ( *(_QWORD *)routers )
{
do
{
v1 = v0;
v0 = (_QWORD *)v0[4];
if ( v1[2] < timer )
func2(v1);
}
while ( v0 );
}
}

original_code:
void
handle_routers() {
    struct Router *iter, *temp;
    time_t now;
    print_routers();
    time(&now);
    for ((iter) = (((routers))->slh_first); (iter) && ((temp) = (((iter))->entries.sle_next), 1); (iter) = (temp)) {
        if (iter->valid_until < now)
            remove_router(iter);
    }
}

canonical_original_code:
void handle_routers() {
    struct Router *iter; struct Router *temp;
    long now;
    print_routers();
    time(&now);
    for ((iter) = (((routers))->slh_first); (iter) && ((temp) = (((iter))->entries.sle_next), 1); (iter) = (temp)) {
        if (iter->valid_until < now)
            remove_router(iter);
    }
}

variable_types: now long


decompiled_code:
time_t next_timeout()
{
time_t v0; // rdx
__int64 i; // rax
time_t timer; // [rsp+8h] [rbp-10h] BYREF

v0 = time(&timer) + 3600;
for ( i = *(_QWORD *)routers; i; i = *(_QWORD *)(i + 32) )
{
if ( v0 > *(_QWORD *)(i + 16) )
v0 = *(_QWORD *)(i + 16);
}
return v0 - timer;
}

canonical_decompiled_code:
time_t func6()
{
time_t v0; // rdx
__int64 i; // rax
time_t timer; // [rsp+8h] [rbp-10h] BYREF

v0 = time(&timer) + 3600;
for ( i = *(_QWORD *)routers; i; i = *(_QWORD *)(i + 32) )
{
if ( v0 > *(_QWORD *)(i + 16) )
v0 = *(_QWORD *)(i + 16);
}
return v0 - timer;
}

original_code:
time_t
next_timeout() {
    struct Router *iter;
    time_t now, min_valid_until;
    min_valid_until = time(&now) + 3600;
    for((iter) = (routers)->slh_first; (iter); (iter) = (iter)->entries.sle_next) {
        min_valid_until = ((min_valid_until) > (iter->valid_until) ? (iter->valid_until) : (min_valid_until));
    }
    return min_valid_until - now;
}

canonical_original_code:
long next_timeout() {
    struct Router *iter;
    long now; long min_valid_until;
    min_valid_until = time(&now) + 3600;
    for((iter) = (routers)->slh_first; (iter); (iter) = (iter)->entries.sle_next) {
        min_valid_until = ((min_valid_until) > (iter->valid_until) ? (iter->valid_until) : (min_valid_until));
    }
    return min_valid_until - now;
}

return_type: long


usage

decompiled_code:
size_t usage()
{
return fwrite(
"Usage: routeradv_listend [-f] [-i <interface>]\n"
" -f run in foreground\n"
" -i specify an interface to listen on\n",
1uLL,
0x73uLL,
stderr);
}

canonical_decompiled_code:
size_t func0()
{
return fwrite(
"Usage: routeradv_listend [-f] [-i <interface>]\n"
" -f run in foreground\n"
" -i specify an interface to listen on\n",
1uLL,
0x73uLL,
stderr);
}

original_code:
static void
usage() {
    fprintf(stderr, "Usage: routeradv_listend [-f] [-i <interface>]\n"
                    "    -f  run in foreground\n"
                    "    -i  specify an interface to listen on\n");
}


daemonize

decompiled_code:
__pid_t __fastcall daemonize(int a1)
{
__pid_t v1; // eax
int v2; // ebx
int v3; // ebx
int v4; // ebp
int v5; // eax
__pid_t result; // eax

umask(0);
v1 = fork();
if ( v1 < 0 )
{
perror("fork()");
exit(1);
}
if ( v1 )
exit(0);
if ( chdir("/") < 0 )
{
perror("chdir()");
exit(1);
}
if ( setsid() < 0 )
{
perror("setsid()");
exit(1);
}
v2 = sysconf(4);
if ( v2 >= 0 )
{
do
{
if ( a1 != v2 )
close(v2);
--v2;
}
while ( v2 != -1 );
}
v3 = open("/dev/null", 2);
v4 = dup(v3);
v5 = dup(v3);
if ( v4 != 1 || v3 != 0 || v5 != 2 )
{
syslog(4, "Unexpected file descriptors\n");
exit(2);
}
result = fork();
if ( result < 0 )
{
perror("fork()");
exit(1);
}
if ( result > 0 )
exit(0);
return result;
}

canonical_decompiled_code:
__pid_t __fastcall func1(int a1)
{
__pid_t v1; // eax
int v2; // ebx
int v3; // ebx
int v4; // ebp
int v5; // eax
__pid_t result; // eax

umask(0);
v1 = fork();
if ( v1 < 0 )
{
perror("fork()");
exit(1);
}
if ( v1 )
exit(0);
if ( chdir("/") < 0 )
{
perror("chdir()");
exit(1);
}
if ( setsid() < 0 )
{
perror("setsid()");
exit(1);
}
v2 = sysconf(4);
if ( v2 >= 0 )
{
do
{
if ( a1 != v2 )
close(v2);
--v2;
}
while ( v2 != -1 );
}
v3 = open("/dev/null", 2);
v4 = dup(v3);
v5 = dup(v3);
if ( v4 != 1 || v3 != 0 || v5 != 2 )
{
syslog(4, "Unexpected file descriptors\n");
exit(2);
}
result = fork();
if ( result < 0 )
{
perror("fork()");
exit(1);
}
if ( result > 0 )
exit(0);
return result;
}

original_code:
static void
daemonize(int sockfd) {
    int i, fd0, fd1, fd2;
    pid_t pid;
    umask(0);
    if ((pid = fork()) < 0) {
        perror("fork()");
        exit(1);
    } else if (pid != 0) {
        exit(0);
    }
    if (chdir("/") < 0) {
        perror("chdir()");
        exit(1);
    }
    if (setsid() < 0) {
        perror("setsid()");
        exit(1);
    }
    for (i = sysconf(_SC_OPEN_MAX); i >= 0; i--)
        if (i != sockfd)
            close(i);
    fd0 = open("/dev/null", 02);
    fd1 = dup(fd0);
    fd2 = dup(fd0);
    if (fd0 != 0 || fd1 != 1 || fd2 != 2) {
        syslog(4, "Unexpected file descriptors\n");
        exit(2);
    }
    pid = fork();
    if (pid < 0) {
        perror("fork()");
        exit(1);
    } else if (pid > 0) {
        exit(0);
    }
}

canonical_original_code:
static void daemonize(int sockfd) {
    int i; int fd0; int fd1; int fd2;
    int pid;
    umask(0);
    if ((pid = fork()) < 0) {
        perror("fork()");
        exit(1);
    } else if (pid != 0) {
        exit(0);
    }
    if (chdir("/") < 0) {
        perror("chdir()");
        exit(1);
    }
    if (setsid() < 0) {
        perror("setsid()");
        exit(1);
    }
    for (i = sysconf(_SC_OPEN_MAX); i >= 0; i--)
        if (i != sockfd)
            close(i);
    fd0 = open("/dev/null", 02);
    fd1 = dup(fd0);
    fd2 = dup(fd0);
    if (fd0 != 0 || fd1 != 1 || fd2 != 2) {
        syslog(4, "Unexpected file descriptors\n");
        exit(2);
    }
    pid = fork();
    if (pid < 0) {
        perror("fork()");
        exit(1);
    } else if (pid > 0) {
        exit(0);
    }
}

variable_types: sockfd int

variable_types: i int

variable_types: pid int


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int v3; // ebx
int v4; // er13
int v5; // eax
int v6; // eax
int v7; // ebx
fd_set *v8; // rsi
int v9; // er14
__int64 v10; // r12
int v11; // edi
char *v12; // rax
struct timeval v14; // [rsp+0h] [rbp-B8h] BYREF
fd_set readfds; // [rsp+10h] [rbp-A8h] BYREF
__int64 v16; // [rsp+90h] [rbp-28h] BYREF

v3 = 0;
v4 = 1;
while ( 1 )
{
v5 = getopt(argc, (char *const *)argv, "fi:");
if ( v5 == -1 )
break;
if ( v5 == 102 )
{
v4 = 0;
}
else
{
if ( v5 != 105 )
{
usage();
exit(1);
}
v3 = if_nametoindex(optarg);
}
}
openlog("routeradv_listend", 34, 24);
v6 = init_icmp_socket(v3);
v7 = v6;
if ( v6 >= 0 )
{
if ( v4 )
daemonize(v6);
init_routers();
v8 = (fd_set *)(&loc_3F + 1);
v9 = v7 / 64;
v10 = 1LL << (v7 % 64);
do
{
while ( 1 )
{
memset(&readfds, 0, sizeof(readfds));
readfds.fds_bits[v9] |= v10;
v14.tv_sec = 0LL;
v14.tv_usec = 0LL;
v14.tv_sec = next_timeout(&v16, v8);
v8 = &readfds;
if ( select(v7 + 1, &readfds, 0LL, 0LL, &v14) < 0 )
break;
if ( (readfds.fds_bits[v9] & v10) != 0 )
recv_icmp_msg((unsigned int)v7);
handle_routers();
}
v11 = *_errno_location();
}
while ( v11 == 4 );
v12 = strerror(v11);
syslog(2, "select: %s", v12);
}
return 1;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int v3; // ebx
int v4; // er13
int v5; // eax
int v6; // eax
int v7; // ebx
fd_set *v8; // rsi
int v9; // er14
__int64 v10; // r12
int v11; // edi
char *v12; // rax
struct timeval v14; // [rsp+0h] [rbp-B8h] BYREF
fd_set readfds; // [rsp+10h] [rbp-A8h] BYREF
__int64 v16; // [rsp+90h] [rbp-28h] BYREF

v3 = 0;
v4 = 1;
while ( 1 )
{
v5 = getopt(argc, (char *const *)argv, "fi:");
if ( v5 == -1 )
break;
if ( v5 == 102 )
{
v4 = 0;
}
else
{
if ( v5 != 105 )
{
func0();
exit(1);
}
v3 = if_nametoindex(optarg);
}
}
openlog("routeradv_listend", 34, 24);
v6 = init_icmp_socket(v3);
v7 = v6;
if ( v6 >= 0 )
{
if ( v4 )
func1(v6);
init_routers();
v8 = (fd_set *)(&loc_3F + 1);
v9 = v7 / 64;
v10 = 1LL << (v7 % 64);
do
{
while ( 1 )
{
memset(&readfds, 0, sizeof(readfds));
readfds.fds_bits[v9] |= v10;
v14.tv_sec = 0LL;
v14.tv_usec = 0LL;
v14.tv_sec = next_timeout(&v16, v8);
v8 = &readfds;
if ( select(v7 + 1, &readfds, 0LL, 0LL, &v14) < 0 )
break;
if ( (readfds.fds_bits[v9] & v10) != 0 )
recv_icmp_msg((unsigned int)v7);
handle_routers();
}
v11 = *_errno_location();
}
while ( v11 == 4 );
v12 = strerror(v11);
syslog(2, "select: %s", v12);
}
return 1;
}

original_code:
int
main(int argc, char **argv) {
    int opt, sockfd;
    int background_flag = 1;
    int if_index = 0;
    fd_set rfds;
    struct timeval timeout;
    while ((opt = getopt(argc, argv, "fi:")) != -1) {
        switch (opt) {
            case 'f':
                background_flag = 0;
                break;
            case 'i':
                if_index = if_nametoindex(optarg);
                break;
            default:
                usage();
                exit(1);
        }
    }
    openlog("routeradv_listend", 0x02|0x20, (3<<3));
    sockfd = init_icmp_socket(if_index);
    if (sockfd < 0)
        return 1;
    if (background_flag)
        daemonize(sockfd);
    init_routers();
    for (;;) {
        do { int __d0, __d1; __asm__ __volatile__ ("cld; rep; " "stosq" : "=c" (__d0), "=D" (__d1) : "a" (0), "0" (sizeof (fd_set) / sizeof (__fd_mask)), "1" (&((&rfds)->fds_bits)[0]) : "memory"); } while (0);
        ((void) (((&rfds)->fds_bits)[((sockfd) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((sockfd) % (8 * (int) sizeof (__fd_mask)))))));
        memset(&timeout, 0, sizeof(timeout));
        timeout.tv_sec = next_timeout();
        if (select(sockfd + 1, &rfds, ((void *)0), ((void *)0), &timeout) < 0) {
            if ((*__errno_location ()) != 4) {
                syslog(2, "select: %s", strerror((*__errno_location ())));
                return 1;
            }
            continue;
        }
        if (((((&rfds)->fds_bits)[((sockfd) / (8 * (int) sizeof (__fd_mask)))] & ((__fd_mask) (1UL << ((sockfd) % (8 * (int) sizeof (__fd_mask)))))) != 0))
            recv_icmp_msg(sockfd);
        handle_routers();
    }
    return 0;
}

canonical_original_code:
int main(int argc, char **argv) {
    int opt; int sockfd;
    int background_flag = 1;
    int if_index = 0;
    struct fd_set rfds;
    struct timeval timeout;
    while ((opt = getopt(argc, argv, "fi:")) != -1) {
        switch (opt) {
            case 'f':
                background_flag = 0;
                break;
            case 'i':
                if_index = if_nametoindex(optarg);
                break;
            default:
                usage();
                exit(1);
        }
    }
    openlog("routeradv_listend", 0x02|0x20, (3<<3));
    sockfd = init_icmp_socket(if_index);
    if (sockfd < 0)
        return 1;
    if (background_flag)
        daemonize(sockfd);
    init_routers();
    for (;;) {
        do { int __d0; int __d1; __asm__ __volatile__ ("cld; rep; " "stosq" : "=c" (__d0), "=D" (__d1) : "a" (0), "0" (sizeof (fd_set) / sizeof (__fd_mask)), "1" (&((&rfds)->fds_bits)[0]) : "memory"); } while (0);
        ((void) (((&rfds)->fds_bits)[((sockfd) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((sockfd) % (8 * (int) sizeof (__fd_mask)))))));
        memset(&timeout, 0, sizeof(timeout));
        timeout.tv_sec = next_timeout();
        if (select(sockfd + 1, &rfds, ((void *)0), ((void *)0), &timeout) < 0) {
            if ((*__errno_location ()) != 4) {
                syslog(2, "select: %s", strerror((*__errno_location ())));
                return 1;
            }
            continue;
        }
        if (((((&rfds)->fds_bits)[((sockfd) / (8 * (int) sizeof (__fd_mask)))] & ((__fd_mask) (1UL << ((sockfd) % (8 * (int) sizeof (__fd_mask)))))) != 0))
            recv_icmp_msg(sockfd);
        handle_routers();
    }
    return 0;
}

variable_types: argc int

variable_types:
argv
char **

variable_types: opt int

variable_types:
rfds
struct fd_set { long fds_bits[-1]; }

variable_types: struct timeval { long tv_sec; long tv_usec; }


decompiled_code:
void __fastcall apply_icmp_filter(int a1)
{
int *v1; // rax
char *v2; // rax
__int64 v3[5]; // [rsp+0h] [rbp-28h] BYREF

v3[0] = -1LL;
v3[1] = -1LL;
v3[2] = -65LL;
v3[3] = -1LL;
if ( setsockopt(a1, 58, 1, v3, 0x20u) )
{
v1 = _errno_location();
v2 = strerror(*v1);
syslog(2, "setsockopt(): %s", v2);
}
}

canonical_decompiled_code:
void __fastcall func0(int a1)
{
int *v1; // rax
char *v2; // rax
__int64 v3[5]; // [rsp+0h] [rbp-28h] BYREF

v3[0] = -1LL;
v3[1] = -1LL;
v3[2] = -65LL;
v3[3] = -1LL;
if ( setsockopt(a1, 58, 1, v3, 0x20u) )
{
v1 = _errno_location();
v2 = strerror(*v1);
syslog(2, "setsockopt(): %s", v2);
}
}

original_code:
static void
apply_icmp_filter(int sockfd) {
    struct icmp6_filter filter;
    memset(&filter, 0, sizeof(filter));
    memset (&filter, 0xFF, sizeof (struct icmp6_filter));;
    ((((&filter)->icmp6_filt[(134) >> 5]) &= ~(1 << ((134) & 31))));
    if (setsockopt(sockfd, IPPROTO_ICMPV6, 1, &filter, sizeof(filter)) != 0) {
        syslog(2, "setsockopt(): %s", strerror((*__errno_location ())));
        return;
    }
}

variable_types: struct icmp6_filter { unsigned int icmp6_filt[8]; }


decompiled_code:
void __fastcall setup_ancillary_data(int fd)
{
int *v1; // rax
char *v2; // rax
int *v3; // rax
char *v4; // rax
int *v5; // rax
char *v6; // rax
int optval[3]; // [rsp+Ch] [rbp-Ch] BYREF

optval[0] = 1;
if ( setsockopt(fd, 1, 29, optval, 4u) )
{
v1 = _errno_location();
v2 = strerror(*v1);
syslog(2, "setsockopt(): %s", v2);
}
if ( setsockopt(fd, 41, 51, optval, 4u) )
{
v3 = _errno_location();
v4 = strerror(*v3);
syslog(2, "setsockopt(): %s", v4);
}
if ( setsockopt(fd, 41, 49, optval, 4u) )
{
v5 = _errno_location();
v6 = strerror(*v5);
syslog(2, "setsockopt(): %s", v6);
}
}

canonical_decompiled_code:
void __fastcall func1(int fd)
{
int *v1; // rax
char *v2; // rax
int *v3; // rax
char *v4; // rax
int *v5; // rax
char *v6; // rax
int optval[3]; // [rsp+Ch] [rbp-Ch] BYREF

optval[0] = 1;
if ( setsockopt(fd, 1, 29, optval, 4u) )
{
v1 = _errno_location();
v2 = strerror(*v1);
syslog(2, "setsockopt(): %s", v2);
}
if ( setsockopt(fd, 41, 51, optval, 4u) )
{
v3 = _errno_location();
v4 = strerror(*v3);
syslog(2, "setsockopt(): %s", v4);
}
if ( setsockopt(fd, 41, 49, optval, 4u) )
{
v5 = _errno_location();
v6 = strerror(*v5);
syslog(2, "setsockopt(): %s", v6);
}
}

original_code:
static void
setup_ancillary_data(int sockfd) {
    int on = 1;
    if (setsockopt(sockfd, 1, 29, &on, sizeof(on)) != 0)
        syslog(2, "setsockopt(): %s", strerror((*__errno_location ())));
    if (setsockopt(sockfd, IPPROTO_IPV6, 51, &on, sizeof(on)) != 0)
        syslog(2, "setsockopt(): %s", strerror((*__errno_location ())));
    if (setsockopt(sockfd, IPPROTO_IPV6, 49, &on, sizeof(on)) != 0)
        syslog(2, "setsockopt(): %s", strerror((*__errno_location ())));
}

variable_types: on int


decompiled_code:
void __fastcall parse_ancillary_data(__int64 a1, struct msghdr *a2)
{
struct cmsghdr *i; // rsi

if ( a2->msg_controllen > 0xF )
{
for ( i = (struct cmsghdr *)a2->msg_control; i; i = _cmsg_nxthdr(a2, i) )
{
if ( *(_QWORD *)&i->cmsg_level == 0x1D00000001LL )
*(__m128i *)(a1 + 56) = _mm_loadu_si128((const __m128i *)i->__cmsg_data);
if ( *(_QWORD *)&i->cmsg_level == 0x3400000029LL )
*(_DWORD *)(a1 + 44) = *(_DWORD *)i->__cmsg_data;
if ( *(_QWORD *)&i->cmsg_level == 0x3200000029LL )
{
*(_DWORD *)(a1 + 48) = *(_DWORD *)&i->__cmsg_data[16];
*(__m128i *)(a1 + 28) = _mm_loadu_si128((const __m128i *)i->__cmsg_data);
}
}
}
}

canonical_decompiled_code:
void __fastcall func3(__int64 a1, struct msghdr *a2)
{
struct cmsghdr *i; // rsi

if ( a2->msg_controllen > 0xF )
{
for ( i = (struct cmsghdr *)a2->msg_control; i; i = _cmsg_nxthdr(a2, i) )
{
if ( *(_QWORD *)&i->cmsg_level == 0x1D00000001LL )
*(__m128i *)(a1 + 56) = _mm_loadu_si128((const __m128i *)i->__cmsg_data);
if ( *(_QWORD *)&i->cmsg_level == 0x3400000029LL )
*(_DWORD *)(a1 + 44) = *(_DWORD *)i->__cmsg_data;
if ( *(_QWORD *)&i->cmsg_level == 0x3200000029LL )
{
*(_DWORD *)(a1 + 48) = *(_DWORD *)&i->__cmsg_data[16];
*(__m128i *)(a1 + 28) = _mm_loadu_si128((const __m128i *)i->__cmsg_data);
}
}
}
}

original_code:
static void
parse_ancillary_data(struct RouterAdvertisment *ra, struct msghdr *m) {
    struct cmsghdr *cmsg;
    const struct in6_pktinfo *pktinfo;
    for (cmsg = ((size_t) (m)->msg_controllen >= sizeof (struct cmsghdr) ? (struct cmsghdr *) (m)->msg_control : (struct cmsghdr *) 0); cmsg != ((void *)0); cmsg = __cmsg_nxthdr (m, cmsg)) {
        if (cmsg->cmsg_level == 1 && cmsg->cmsg_type == 29)
            memcpy(&ra->timestamp, ((cmsg)->__cmsg_data), sizeof(ra->timestamp));
        if (cmsg->cmsg_level == IPPROTO_IPV6 && cmsg->cmsg_type == 52)
            ra->hop_limit = *(int *)((cmsg)->__cmsg_data);
        if (cmsg->cmsg_level == IPPROTO_IPV6 && cmsg->cmsg_type == 50) {
            pktinfo = (const struct in6_pktinfo *)((cmsg)->__cmsg_data);
            ra->if_index = pktinfo->ipi6_ifindex;
            memcpy(&ra->dst_addr, &pktinfo->ipi6_addr, sizeof(ra->dst_addr));
        }
    }
}

canonical_original_code:
static void parse_ancillary_data(struct RouterAdvertisment *ra, struct msghdr *m) {
    struct cmsghdr *cmsg;
    struct in6_pktinfo *pktinfo;
    for (cmsg = ((unsigned long) (m)->msg_controllen >= sizeof (struct cmsghdr) ? (struct cmsghdr *) (m)->msg_control : (struct cmsghdr *) 0); cmsg != ((void *)0); cmsg = __cmsg_nxthdr (m, cmsg)) {
        if (cmsg->cmsg_level == 1 && cmsg->cmsg_type == 29)
            memcpy(&ra->timestamp, ((cmsg)->__cmsg_data), sizeof(ra->timestamp));
        if (cmsg->cmsg_level == IPPROTO_IPV6 && cmsg->cmsg_type == 52)
            ra->hop_limit = *(int *)((cmsg)->__cmsg_data);
        if (cmsg->cmsg_level == IPPROTO_IPV6 && cmsg->cmsg_type == 50) {
            pktinfo = (struct in6_pktinfo *)((cmsg)->__cmsg_data);
            ra->if_index = pktinfo->ipi6_ifindex;
            memcpy(&ra->dst_addr, &pktinfo->ipi6_addr, sizeof(ra->dst_addr));
        }
    }
}

variable_types: struct RouterAdvertisment { struct sockaddr_in6 { unsigned short sin6_family; unsigned short sin6_port; unsigned int sin6_flowinfo; struct in6_addr { union { unsigned char __u6_addr8[16]; unsigned short __u6_addr16[8]; unsigned int __u6_addr32[4]; } __in6_u; } sin6_addr; unsigned int sin6_scope_id; } src_addr; struct in6_addr dst_addr; int hop_limit; int if_index; struct timeval { long tv_sec; long tv_usec; } timestamp; int lifetime; int reachable; int retransmit; } *

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

variable_types: struct cmsghdr { unsigned long cmsg_len; int cmsg_level; int cmsg_type; unsigned char __cmsg_data[]; } *

variable_types: struct in6_pktinfo { struct in6_addr { union { unsigned char __u6_addr8[16]; unsigned short __u6_addr16[8]; unsigned int __u6_addr32[4]; } __in6_u; } ipi6_addr; unsigned int ipi6_ifindex; } *

user_defined_types: struct RouterAdvertisment { struct sockaddr_in6 src_addr; struct in6_addr dst_addr; int hop_limit; int if_index; struct timeval timestamp; int lifetime; int reachable; int retransmit; }

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

user_defined_types: struct in6_pktinfo { struct in6_addr ipi6_addr; unsigned int ipi6_ifindex; }

user_defined_types: struct sockaddr_in6 { unsigned short sin6_family; unsigned short sin6_port; unsigned int sin6_flowinfo; struct in6_addr sin6_addr; unsigned int sin6_scope_id; }


decompiled_code:
__int64 __fastcall parse_icmp_data(_DWORD *a1, __int64 a2, unsigned __int64 a3)
{
unsigned __int64 v4; // rcx
__int64 v5; // rdx
__int16 v6; // ax
unsigned __int64 v7; // rax
__int64 result; // rax

if ( a3 <= 0xF )
{
syslog(5, "Did not receive complete ICMP packet");
result = 0xFFFFFFFFLL;
}
else if ( *(_BYTE *)a2 == 0x86 )
{
if ( *(_BYTE *)(a2 + 1) )
{
syslog(5, "Nonzero ICMP code, ignoring");
result = 0xFFFFFFFFLL;
}
else
{
a1[18] = (unsigned __int16)_bswap_16(*(_WORD *)(a2 + 6));
a1[19] = _bswap_32(*(_DWORD *)(a2 + 8));
a1[20] = _bswap_32(*(_DWORD *)(a2 + 12));
v4 = a3 - 16;
if ( a3 - 16 <= 1 )
{
v5 = 16LL;
LABEL_9:
if ( a3 == v5 )
{
result = 0LL;
}
else
{
syslog(5, "%zd trailing bytes", v4);
result = 0xFFFFFFFFLL;
}
}
else
{
v5 = 16LL;
while ( 1 )
{
v6 = *(unsigned __int8 *)(a2 + v5 + 1);
if ( !(_BYTE)v6 )
{
syslog(5, "Invalid length");
return 0xFFFFFFFFLL;
}
v7 = (8 * v6) & 0x7F8;
if ( v7 > v4 )
break;
v5 += v7;
v4 = a3 - v5;
if ( a3 - v5 <= 1 )
goto LABEL_9;
}
syslog(5, "Did not receive complete ICMP packet option");
result = 0xFFFFFFFFLL;
}
}
}
else
{
result = 0xFFFFFFFFLL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func7(_DWORD *a1, __int64 a2, unsigned __int64 a3)
{
unsigned __int64 v4; // rcx
__int64 v5; // rdx
__int16 v6; // ax
unsigned __int64 v7; // rax
__int64 result; // rax

if ( a3 <= 0xF )
{
syslog(5, "Did not receive complete ICMP packet");
result = 0xFFFFFFFFLL;
}
else if ( *(_BYTE *)a2 == 0x86 )
{
if ( *(_BYTE *)(a2 + 1) )
{
syslog(5, "Nonzero ICMP code, ignoring");
result = 0xFFFFFFFFLL;
}
else
{
a1[18] = (unsigned __int16)func6(*(_WORD *)(a2 + 6));
a1[19] = func4(*(_DWORD *)(a2 + 8));
a1[20] = func4(*(_DWORD *)(a2 + 12));
v4 = a3 - 16;
if ( a3 - 16 <= 1 )
{
v5 = 16LL;
LABEL_9:
if ( a3 == v5 )
{
result = 0LL;
}
else
{
syslog(5, "%zd trailing bytes", v4);
result = 0xFFFFFFFFLL;
}
}
else
{
v5 = 16LL;
while ( 1 )
{
v6 = *(unsigned __int8 *)(a2 + v5 + 1);
if ( !(_BYTE)v6 )
{
syslog(5, "Invalid length");
return 0xFFFFFFFFLL;
}
v7 = (8 * v6) & 0x7F8;
if ( v7 > v4 )
break;
v5 += v7;
v4 = a3 - v5;
if ( a3 - v5 <= 1 )
goto LABEL_9;
}
syslog(5, "Did not receive complete ICMP packet option");
result = 0xFFFFFFFFLL;
}
}
}
else
{
result = 0xFFFFFFFFLL;
}
return result;
}

original_code:
static int
parse_icmp_data(struct RouterAdvertisment *adv, const void *pkt, size_t pkt_len) {
    size_t parsed_len = 0;
    if (pkt_len < sizeof(struct nd_router_advert)) {
        syslog(5, "Did not receive complete ICMP packet");
        return -1;
    }
    const struct nd_router_advert *ra = (const struct nd_router_advert *)pkt;
    if (ra->nd_ra_hdr.icmp6_type != 134) {
        return -1;
    }
    if (ra->nd_ra_hdr.icmp6_code != 0) {
        syslog(5, "Nonzero ICMP code,  ignoring");
        return -1;
    }
    adv->lifetime = ntohs(ra->nd_ra_hdr.icmp6_dataun.icmp6_un_data16[1]);
    adv->reachable = ntohl(ra->nd_ra_reachable);
    adv->retransmit = ntohl(ra->nd_ra_retransmit);
    parsed_len = sizeof(struct nd_router_advert);
    while (pkt_len - parsed_len >= sizeof(struct nd_opt_hdr)) {
        const struct nd_opt_hdr *opt = (const struct nd_opt_hdr *)((const char *)ra + parsed_len);
        if (opt->nd_opt_len == 0) {
            syslog(5, "Invalid length");
            return -1;
        }
        if (pkt_len - parsed_len < opt->nd_opt_len * 8) {
            syslog(5, "Did not receive complete ICMP packet option");
            return -1;
        }
        parsed_len += opt->nd_opt_len * 8;
    }
    if (parsed_len != pkt_len) {
        syslog(5, "%zd trailing bytes", pkt_len - parsed_len);
        return -1;
    }
    return 0;
}

canonical_original_code:
static int parse_icmp_data(struct RouterAdvertisment *adv, void *pkt, unsigned long pkt_len) {
    unsigned long parsed_len = 0;
    if (pkt_len < sizeof(struct nd_router_advert)) {
        syslog(5, "Did not receive complete ICMP packet");
        return -1;
    }
    struct nd_router_advert *ra = (const struct nd_router_advert *)pkt;
    if (ra->nd_ra_hdr.icmp6_type != 134) {
        return -1;
    }
    if (ra->nd_ra_hdr.icmp6_code != 0) {
        syslog(5, "Nonzero ICMP code,  ignoring");
        return -1;
    }
    adv->lifetime = ntohs(ra->nd_ra_hdr.icmp6_dataun.icmp6_un_data16[1]);
    adv->reachable = ntohl(ra->nd_ra_reachable);
    adv->retransmit = ntohl(ra->nd_ra_retransmit);
    parsed_len = sizeof(struct nd_router_advert);
    while (pkt_len - parsed_len >= sizeof(struct nd_opt_hdr)) {
        struct nd_opt_hdr *opt = (const struct nd_opt_hdr *)((const char *)ra + parsed_len);
        if (opt->nd_opt_len == 0) {
            syslog(5, "Invalid length");
            return -1;
        }
        if (pkt_len - parsed_len < opt->nd_opt_len * 8) {
            syslog(5, "Did not receive complete ICMP packet option");
            return -1;
        }
        parsed_len += opt->nd_opt_len * 8;
    }
    if (parsed_len != pkt_len) {
        syslog(5, "%zd trailing bytes", pkt_len - parsed_len);
        return -1;
    }
    return 0;
}

variable_types:
pkt
void *

variable_types: struct nd_router_advert { struct icmp6_hdr { unsigned char icmp6_type; unsigned char icmp6_code; unsigned short icmp6_cksum; union { unsigned int icmp6_un_data32[1]; unsigned short icmp6_un_data16[2]; unsigned char icmp6_un_data8[4]; } icmp6_dataun; } nd_ra_hdr; unsigned int nd_ra_reachable; unsigned int nd_ra_retransmit; } *

variable_types: struct nd_opt_hdr { unsigned char nd_opt_type; unsigned char nd_opt_len; } *

user_defined_types: struct nd_router_advert { struct icmp6_hdr nd_ra_hdr; unsigned int nd_ra_reachable; unsigned int nd_ra_retransmit; }

user_defined_types: struct timeval { long tv_sec; long tv_usec; }


decompiled_code:
__int64 __fastcall init_icmp_socket(int a1)
{
int v1; // eax
unsigned int v2; // ebx
int *v4; // rax
char *v5; // rax

v1 = socket(10, 3, 58);
if ( v1 < 0 )
{
v4 = _errno_location();
v5 = strerror(*v4);
syslog(2, "socket(): %s", v5);
v2 = 1;
}
else
{
v2 = v1;
apply_icmp_filter(v1);
selected_if_index = a1;
multicast_listen(v2, "ff02::1", a1);
setup_ancillary_data(v2);
}
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func8(int a1)
{
int v1; // eax
unsigned int v2; // ebx
int *v4; // rax
char *v5; // rax

v1 = socket(10, 3, 58);
if ( v1 < 0 )
{
v4 = _errno_location();
v5 = strerror(*v4);
syslog(2, "socket(): %s", v5);
v2 = 1;
}
else
{
v2 = v1;
func0(v1);
selected_if_index = a1;
func2(v2, "ff02::1", a1);
func1(v2);
}
return v2;
}

original_code:
int
init_icmp_socket(int if_index) {
    int sockfd;
    sockfd = socket(10, SOCK_RAW, IPPROTO_ICMPV6);
    if (sockfd < 0) {
        syslog(2, "socket(): %s", strerror((*__errno_location ())));
        return 1;
    }
    apply_icmp_filter(sockfd);
    selected_if_index = if_index;
    multicast_listen(sockfd, "ff02::1", if_index);
    setup_ancillary_data(sockfd);
    return sockfd;
}

variable_types: sockfd int


decompiled_code:
void __fastcall recv_icmp_msg(int fd)
{
ssize_t v1; // rax
unsigned __int64 v2; // rbx
int v3; // ebp
int *v4; // rax
char *v5; // rax
__int64 v6[2]; // [rsp+0h] [rbp-2C8h] BYREF
struct msghdr message; // [rsp+10h] [rbp-2B8h] BYREF
__int64 v8[12]; // [rsp+50h] [rbp-278h] BYREF
char v9[256]; // [rsp+B0h] [rbp-218h] BYREF
unsigned __int16 v10[140]; // [rsp+1B0h] [rbp-118h] BYREF

memset(v10, 0, 0x100uLL);
memset(v9, 0, sizeof(v9));
memset(v8, 0, 0x58uLL);
*(_QWORD *)&message.msg_namelen = 28LL;
*(_QWORD *)&message.msg_flags = 0LL;
message.msg_name = v8;
v6[0] = (__int64)v10;
v6[1] = 256LL;
message.msg_iov = (iovec *)v6;
message.msg_iovlen = 1LL;
message.msg_control = v9;
message.msg_controllen = 256LL;
v1 = recvmsg(fd, &message, 0);
if ( v1 < 0 )
{
v4 = _errno_location();
v5 = strerror(*v4);
syslog(2, "recvmsg(): %s", v5);
}
else
{
v2 = v1;
parse_ancillary_data((__int64)v8, &message);
v3 = LODWORD(v8[1]) & _bswap_32(0xFFC00000);
if ( v3 == (unsigned int)_bswap_32(0xFE800000) )
{
if ( HIDWORD(v8[5]) == 255 )
{
if ( selected_if_index <= 0 || selected_if_index == LODWORD(v8[6]) )
{
if ( (unsigned __int16)checksum((unsigned __int16 *)&v8[1], (unsigned __int16 *)&v8[3] + 2, 58, v10, v2) )
{
syslog(5, "Invalid ICMP checksum, ignoring");
}
else if ( (int)parse_icmp_data(v8, (__int64)v10, v2) < 0 )
{
syslog(5, "Unable to parse ICMP packet");
}
else
{
update_router(&v8[1], LODWORD(v8[6]), v8[7] + SLODWORD(v8[9]));
}
}
else
{
syslog(4, "Packeted recevied on different interface");
}
}
else
{
syslog(5, "Hop limit is not 255, ignoring");
}
}
else
{
syslog(5, "Not link local, ignoring");
}
}
}

canonical_decompiled_code:
void __fastcall func9(int fd)
{
ssize_t v1; // rax
unsigned __int64 v2; // rbx
int v3; // ebp
int *v4; // rax
char *v5; // rax
__int64 v6[2]; // [rsp+0h] [rbp-2C8h] BYREF
struct msghdr message; // [rsp+10h] [rbp-2B8h] BYREF
__int64 v8[12]; // [rsp+50h] [rbp-278h] BYREF
char v9[256]; // [rsp+B0h] [rbp-218h] BYREF
unsigned __int16 v10[140]; // [rsp+1B0h] [rbp-118h] BYREF

memset(v10, 0, 0x100uLL);
memset(v9, 0, sizeof(v9));
memset(v8, 0, 0x58uLL);
*(_QWORD *)&message.msg_namelen = 28LL;
*(_QWORD *)&message.msg_flags = 0LL;
message.msg_name = v8;
v6[0] = (__int64)v10;
v6[1] = 256LL;
message.msg_iov = (iovec *)v6;
message.msg_iovlen = 1LL;
message.msg_control = v9;
message.msg_controllen = 256LL;
v1 = recvmsg(fd, &message, 0);
if ( v1 < 0 )
{
v4 = _errno_location();
v5 = strerror(*v4);
syslog(2, "recvmsg(): %s", v5);
}
else
{
v2 = v1;
func3((__int64)v8, &message);
v3 = LODWORD(v8[1]) & func4(0xFFC00000);
if ( v3 == (unsigned int)func4(0xFE800000) )
{
if ( HIDWORD(v8[5]) == 255 )
{
if ( selected_if_index <= 0 || selected_if_index == LODWORD(v8[6]) )
{
if ( (unsigned __int16)func5((unsigned __int16 *)&v8[1], (unsigned __int16 *)&v8[3] + 2, 58, v10, v2) )
{
syslog(5, "Invalid ICMP checksum, ignoring");
}
else if ( (int)func7(v8, (__int64)v10, v2) < 0 )
{
syslog(5, "Unable to parse ICMP packet");
}
else
{
update_router(&v8[1], LODWORD(v8[6]), v8[7] + SLODWORD(v8[9]));
}
}
else
{
syslog(4, "Packeted recevied on different interface");
}
}
else
{
syslog(5, "Hop limit is not 255, ignoring");
}
}
else
{
syslog(5, "Not link local, ignoring");
}
}
}

original_code:
void
recv_icmp_msg(int sockfd) {
    char data_buf[256];
    char control_buf[256];
    struct RouterAdvertisment ra;
    struct msghdr m;
    struct iovec iov;
    ssize_t len;
    memset(data_buf, 0, sizeof(data_buf));
    memset(control_buf, 0, sizeof(control_buf));
    memset(&ra, 0, sizeof(ra));
    memset(&m, 0, sizeof(m));
    memset(&iov, 0, sizeof(iov));
    m.msg_name = &ra.src_addr;
    m.msg_namelen = sizeof(ra.src_addr);
    iov.iov_base = data_buf;
    iov.iov_len = sizeof(data_buf);
    m.msg_iov = &iov;
    m.msg_iovlen = 1;
    m.msg_control = (void *)control_buf;
    m.msg_controllen = sizeof(control_buf);
    m.msg_flags = 0;
    len = recvmsg(sockfd, &m, 0);
    if (len < 0) {
        syslog(2, "recvmsg(): %s", strerror((*__errno_location ())));
        return;
    }
    parse_ancillary_data(&ra, &m);
    if (! (__extension__ ({ const struct in6_addr *__a = (const struct in6_addr *) (&ra.src_addr.sin6_addr); (__a->__in6_u.__u6_addr32[0] & htonl (0xffc00000)) == htonl (0xfe800000); }))) {
        syslog(5, "Not link local, ignoring");
        return;
    }
    if (ra.hop_limit != 255) {
        syslog(5, "Hop limit is not 255, ignoring");
        return;
    }
    if (selected_if_index > 0 && ra.if_index != selected_if_index) {
        syslog(4, "Packeted recevied on different interface");
        return;
    }
    if (checksum(&ra.src_addr.sin6_addr, &ra.dst_addr, IPPROTO_ICMPV6, data_buf, len) != 0) {
        syslog(5, "Invalid ICMP checksum, ignoring");
        return;
    }
    if (parse_icmp_data(&ra, data_buf, len) < 0) {
        syslog(5, "Unable to parse ICMP packet");
        return;
    }
    update_router(&ra.src_addr.sin6_addr, ra.if_index, ra.timestamp.tv_sec + ra.lifetime);
}

canonical_original_code:
void recv_icmp_msg(int sockfd) {
    char data_buf[256];
    char control_buf[256];
    struct RouterAdvertisment ra;
    struct msghdr m;
    struct iovec iov;
    long len;
    memset(data_buf, 0, sizeof(data_buf));
    memset(control_buf, 0, sizeof(control_buf));
    memset(&ra, 0, sizeof(ra));
    memset(&m, 0, sizeof(m));
    memset(&iov, 0, sizeof(iov));
    m.msg_name = &ra.src_addr;
    m.msg_namelen = sizeof(ra.src_addr);
    iov.iov_base = data_buf;
    iov.iov_len = sizeof(data_buf);
    m.msg_iov = &iov;
    m.msg_iovlen = 1;
    m.msg_control = (void *)control_buf;
    m.msg_controllen = sizeof(control_buf);
    m.msg_flags = 0;
    len = recvmsg(sockfd, &m, 0);
    if (len < 0) {
        syslog(2, "recvmsg(): %s", strerror((*__errno_location ())));
        return;
    }
    parse_ancillary_data(&ra, &m);
    if (! (__extension__ ({ struct in6_addr *__a = (const struct in6_addr *) (&ra.src_addr.sin6_addr); (__a->__in6_u.__u6_addr32[0] & htonl (0xffc00000)) == htonl (0xfe800000); }))) {
        syslog(5, "Not link local, ignoring");
        return;
    }
    if (ra.hop_limit != 255) {
        syslog(5, "Hop limit is not 255, ignoring");
        return;
    }
    if (selected_if_index > 0 && ra.if_index != selected_if_index) {
        syslog(4, "Packeted recevied on different interface");
        return;
    }
    if (checksum(&ra.src_addr.sin6_addr, &ra.dst_addr, IPPROTO_ICMPV6, data_buf, len) != 0) {
        syslog(5, "Invalid ICMP checksum, ignoring");
        return;
    }
    if (parse_icmp_data(&ra, data_buf, len) < 0) {
        syslog(5, "Unable to parse ICMP packet");
        return;
    }
    update_router(&ra.src_addr.sin6_addr, ra.if_index, ra.timestamp.tv_sec + ra.lifetime);
}

variable_types: struct RouterAdvertisment { struct sockaddr_in6 { unsigned short sin6_family; unsigned short sin6_port; unsigned int sin6_flowinfo; struct in6_addr { union { unsigned char __u6_addr8[16]; unsigned short __u6_addr16[8]; unsigned int __u6_addr32[4]; } __in6_u; } sin6_addr; unsigned int sin6_scope_id; } src_addr; struct in6_addr dst_addr; int hop_limit; int if_index; struct timeval { long tv_sec; long tv_usec; } timestamp; int lifetime; int reachable; int retransmit; }

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

variable_types: len long

variable_types: struct in6_addr { union { unsigned char __u6_addr8[16]; unsigned short __u6_addr16[8]; unsigned int __u6_addr32[4]; } __in6_u; } *


decompiled_code:
void __fastcall add_gateway(void *cp, unsigned int ifindex)
{
unsigned int v2; // eax
int *v3; // rax
char *v4; // rax
int *v5; // rax
char *v6; // rax
char v7[16]; // [rsp+0h] [rbp-148h] BYREF
char buf[48]; // [rsp+10h] [rbp-138h] BYREF
char s[264]; // [rsp+40h] [rbp-108h] BYREF

if ( inet_ntop(10, cp, buf, 0x2Eu) )
{
if ( if_indextoname(ifindex, v7) )
{
syslog(6, "adding default route via %s", buf);
if ( snprintf(s, 0x100uLL, "/sbin/ip -6 route add ::/0 via %s dev %s", buf, v7) > 255 )
{
syslog(2, "exceeded command string length");
}
else
{
v2 = system(s);
if ( v2 )
syslog(2, "%s returned %d", s, v2);
}
}
else
{
v5 = _errno_location();
v6 = strerror(*v5);
syslog(2, "if_indextoname: %s", v6);
}
}
else
{
v3 = _errno_location();
v4 = strerror(*v3);
syslog(2, "inet_ntop: %s", v4);
}
}

canonical_decompiled_code:
void __fastcall func0(void *cp, unsigned int ifindex)
{
unsigned int v2; // eax
int *v3; // rax
char *v4; // rax
int *v5; // rax
char *v6; // rax
char v7[16]; // [rsp+0h] [rbp-148h] BYREF
char buf[48]; // [rsp+10h] [rbp-138h] BYREF
char s[264]; // [rsp+40h] [rbp-108h] BYREF

if ( inet_ntop(10, cp, buf, 0x2Eu) )
{
if ( if_indextoname(ifindex, v7) )
{
syslog(6, "adding default route via %s", buf);
if ( snprintf(s, 0x100uLL, "/sbin/ip -6 route add ::/0 via %s dev %s", buf, v7) > 255 )
{
syslog(2, "exceeded command string length");
}
else
{
v2 = system(s);
if ( v2 )
syslog(2, "%s returned %d", s, v2);
}
}
else
{
v5 = _errno_location();
v6 = strerror(*v5);
syslog(2, "if_indextoname: %s", v6);
}
}
else
{
v3 = _errno_location();
v4 = strerror(*v3);
syslog(2, "inet_ntop: %s", v4);
}
}

original_code:
void add_gateway(const struct in6_addr * addr, int if_index) {
    char cmd_string[256];
    char addr_str[46];
    char if_name[16];
    int ret;
    if (inet_ntop(10, addr, addr_str, sizeof(addr_str)) == ((void *)0)) {
        syslog(2, "inet_ntop: %s", strerror((*__errno_location ())));
        return;
    }
    if (if_indextoname(if_index, if_name) == ((void *)0)) {
        syslog(2, "if_indextoname: %s", strerror((*__errno_location ())));
        return;
    }
    syslog(6, "adding default route via %s", addr_str);
    if (snprintf(cmd_string, sizeof(cmd_string), "/sbin/ip -6 route add ::/0 via %s dev %s", addr_str, if_name) >= (ssize_t)sizeof(cmd_string)) {
        syslog(2, "exceeded command string length");
        return;
    }
    ret = system(cmd_string);
    if (ret != 0) {
        syslog(2, "%s returned %d", cmd_string, ret);
    }
}

canonical_original_code:
void add_gateway(struct in6_addr *addr, int if_index) {
    char cmd_string[256];
    char addr_str[46];
    char if_name[16];
    int ret;
    if (inet_ntop(10, addr, addr_str, sizeof(addr_str)) == ((void *)0)) {
        syslog(2, "inet_ntop: %s", strerror((*__errno_location ())));
        return;
    }
    if (if_indextoname(if_index, if_name) == ((void *)0)) {
        syslog(2, "if_indextoname: %s", strerror((*__errno_location ())));
        return;
    }
    syslog(6, "adding default route via %s", addr_str);
    if (snprintf(cmd_string, sizeof(cmd_string), "/sbin/ip -6 route add ::/0 via %s dev %s", addr_str, if_name) >= (long)sizeof(cmd_string)) {
        syslog(2, "exceeded command string length");
        return;
    }
    ret = system(cmd_string);
    if (ret != 0) {
        syslog(2, "%s returned %d", cmd_string, ret);
    }
}

variable_types: ret int


decompiled_code:
void __fastcall remove_gateway(void *cp, unsigned int ifindex)
{
unsigned int v2; // eax
int *v3; // rax
char *v4; // rax
int *v5; // rax
char *v6; // rax
char v7[16]; // [rsp+0h] [rbp-148h] BYREF
char buf[48]; // [rsp+10h] [rbp-138h] BYREF
char s[264]; // [rsp+40h] [rbp-108h] BYREF

if ( inet_ntop(10, cp, buf, 0x2Eu) )
{
if ( if_indextoname(ifindex, v7) )
{
syslog(6, "removing default route via %s", buf);
if ( snprintf(s, 0x100uLL, "/sbin/ip -6 route del ::/0 via %s dev %s", buf, v7) > 255 )
{
syslog(2, "exceeded command string length");
}
else
{
v2 = system(s);
if ( v2 )
syslog(2, "%s returned %d", s, v2);
}
}
else
{
v5 = _errno_location();
v6 = strerror(*v5);
syslog(2, "if_indextoname: %s", v6);
}
}
else
{
v3 = _errno_location();
v4 = strerror(*v3);
syslog(2, "inet_ntop: %s", v4);
}
}

canonical_decompiled_code:
void __fastcall func1(void *cp, unsigned int ifindex)
{
unsigned int v2; // eax
int *v3; // rax
char *v4; // rax
int *v5; // rax
char *v6; // rax
char v7[16]; // [rsp+0h] [rbp-148h] BYREF
char buf[48]; // [rsp+10h] [rbp-138h] BYREF
char s[264]; // [rsp+40h] [rbp-108h] BYREF

if ( inet_ntop(10, cp, buf, 0x2Eu) )
{
if ( if_indextoname(ifindex, v7) )
{
syslog(6, "removing default route via %s", buf);
if ( snprintf(s, 0x100uLL, "/sbin/ip -6 route del ::/0 via %s dev %s", buf, v7) > 255 )
{
syslog(2, "exceeded command string length");
}
else
{
v2 = system(s);
if ( v2 )
syslog(2, "%s returned %d", s, v2);
}
}
else
{
v5 = _errno_location();
v6 = strerror(*v5);
syslog(2, "if_indextoname: %s", v6);
}
}
else
{
v3 = _errno_location();
v4 = strerror(*v3);
syslog(2, "inet_ntop: %s", v4);
}
}

original_code:
void remove_gateway(const struct in6_addr *addr, int if_index) {
    char cmd_string[256];
    char addr_str[46];
    char if_name[16];
    int ret;
    if (inet_ntop(10, addr, addr_str, sizeof(addr_str)) == ((void *)0)) {
        syslog(2, "inet_ntop: %s", strerror((*__errno_location ())));
        return;
    }
    if (if_indextoname(if_index, if_name) == ((void *)0)) {
        syslog(2, "if_indextoname: %s", strerror((*__errno_location ())));
        return;
    }
    syslog(6, "removing default route via %s", addr_str);
    if (snprintf(cmd_string, sizeof(cmd_string), "/sbin/ip -6 route del ::/0 via %s dev %s", addr_str, if_name) >= (ssize_t)sizeof(cmd_string)) {
        syslog(2, "exceeded command string length");
        return;
    }
    ret = system(cmd_string);
    if (ret != 0) {
        syslog(2, "%s returned %d", cmd_string, ret);
    }
}

canonical_original_code:
void remove_gateway(struct in6_addr *addr, int if_index) {
    char cmd_string[256];
    char addr_str[46];
    char if_name[16];
    int ret;
    if (inet_ntop(10, addr, addr_str, sizeof(addr_str)) == ((void *)0)) {
        syslog(2, "inet_ntop: %s", strerror((*__errno_location ())));
        return;
    }
    if (if_indextoname(if_index, if_name) == ((void *)0)) {
        syslog(2, "if_indextoname: %s", strerror((*__errno_location ())));
        return;
    }
    syslog(6, "removing default route via %s", addr_str);
    if (snprintf(cmd_string, sizeof(cmd_string), "/sbin/ip -6 route del ::/0 via %s dev %s", addr_str, if_name) >= (long)sizeof(cmd_string)) {
        syslog(2, "exceeded command string length");
        return;
    }
    ret = system(cmd_string);
    if (ret != 0) {
        syslog(2, "%s returned %d", cmd_string, ret);
    }
}


decompiled_code:
int __fastcall print_key(const char *a1)
{
return puts(a1);
}

canonical_decompiled_code:
int __fastcall func7(const char *a1)
{
return puts(a1);
}

original_code:
static void
print_key (char *k, void* val)
{
   printf("%s\n", k);
}

canonical_original_code:
static void print_key(char *k, void *val)
{
   printf("%s\n", k);
}

variable_types:
k
char *

variable_types:
val
void *


decompiled_code:
unsigned __int8 *__fastcall tst_delete(unsigned __int8 *a1, char *a2)
{
unsigned __int8 *v2; // rbx
char *v3; // rdi
unsigned __int8 *v4; // rbp
int v6; // eax
unsigned __int8 *v7; // rdi
unsigned __int8 *v8; // rdi
char v9; // cl
int v10; // edx
int v11; // eax
_QWORD *v12; // rdi
__int64 v13; // rax

if ( !a2 )
return 0LL;
v2 = a1;
if ( !a1 )
return v2;
v3 = a2;
v4 = v2;
while ( 1 )
{
while ( 1 )
{
v9 = *a2;
v10 = *a2;
v11 = *v2;
if ( v10 == v11 )
break;
if ( v10 >= v11 )
v2 = (unsigned __int8 *)*((_QWORD *)v2 + 3);
else
v2 = (unsigned __int8 *)*((_QWORD *)v2 + 1);
if ( *((_QWORD *)v2 + 1) )
{
v4 = v2;
}
else if ( *((_QWORD *)v2 + 3) )
{
v4 = v2;
}
v3 = a2;
}
++a2;
if ( !v9 )
break;
v2 = (unsigned __int8 *)*((_QWORD *)v2 + 2);
if ( !v2 )
return v2;
}
v2 = (unsigned __int8 *)*((_QWORD *)v2 + 2);
if ( !v4 )
return v2;
v6 = *v3;
if ( *v4 == v6 )
{
v12 = (_QWORD *)*((_QWORD *)v4 + 2);
if ( v12 )
{
v13 = v12[3];
if ( v13 )
{
*((_QWORD *)v4 + 2) = v13;
free(v12);
}
else
{
tst_cleanup_localalias(v12);
*((_QWORD *)v4 + 2) = 0LL;
}
}
return v2;
}
v7 = (unsigned __int8 *)*((_QWORD *)v4 + 3);
if ( v7 )
{
if ( v6 == *v7 )
{
LABEL_17:
tst_cleanup_localalias(v7);
*((_QWORD *)v4 + 3) = 0LL;
return v2;
}
v8 = (unsigned __int8 *)*((_QWORD *)v4 + 1);
if ( !v8 || v6 != *v8 )
{
if ( !*((_QWORD *)v4 + 2) )
return v2;
goto LABEL_14;
}
LABEL_36:
tst_cleanup_localalias(v8);
*((_QWORD *)v4 + 1) = 0LL;
return v2;
}
v8 = (unsigned __int8 *)*((_QWORD *)v4 + 1);
if ( v8 )
{
if ( v6 != *v8 )
return v2;
goto LABEL_36;
}
if ( !*((_QWORD *)v4 + 2) )
return v2;
LABEL_14:
v4 = (unsigned __int8 *)*((_QWORD *)v4 + 2);
if ( !*v4 )
{
v7 = (unsigned __int8 *)*((_QWORD *)v4 + 3);
if ( v7 )
{
if ( v6 == *v7 )
goto LABEL_17;
}
}
return v2;
}

canonical_decompiled_code:
unsigned __int8 *__fastcall func10(unsigned __int8 *a1, char *a2)
{
unsigned __int8 *v2; // rbx
char *v3; // rdi
unsigned __int8 *v4; // rbp
int v6; // eax
unsigned __int8 *v7; // rdi
unsigned __int8 *v8; // rdi
char v9; // cl
int v10; // edx
int v11; // eax
_QWORD *v12; // rdi
__int64 v13; // rax

if ( !a2 )
return 0LL;
v2 = a1;
if ( !a1 )
return v2;
v3 = a2;
v4 = v2;
while ( 1 )
{
while ( 1 )
{
v9 = *a2;
v10 = *a2;
v11 = *v2;
if ( v10 == v11 )
break;
if ( v10 >= v11 )
v2 = (unsigned __int8 *)*((_QWORD *)v2 + 3);
else
v2 = (unsigned __int8 *)*((_QWORD *)v2 + 1);
if ( *((_QWORD *)v2 + 1) )
{
v4 = v2;
}
else if ( *((_QWORD *)v2 + 3) )
{
v4 = v2;
}
v3 = a2;
}
++a2;
if ( !v9 )
break;
v2 = (unsigned __int8 *)*((_QWORD *)v2 + 2);
if ( !v2 )
return v2;
}
v2 = (unsigned __int8 *)*((_QWORD *)v2 + 2);
if ( !v4 )
return v2;
v6 = *v3;
if ( *v4 == v6 )
{
v12 = (_QWORD *)*((_QWORD *)v4 + 2);
if ( v12 )
{
v13 = v12[3];
if ( v13 )
{
*((_QWORD *)v4 + 2) = v13;
free(v12);
}
else
{
func8(v12);
*((_QWORD *)v4 + 2) = 0LL;
}
}
return v2;
}
v7 = (unsigned __int8 *)*((_QWORD *)v4 + 3);
if ( v7 )
{
if ( v6 == *v7 )
{
LABEL_17:
func8(v7);
*((_QWORD *)v4 + 3) = 0LL;
return v2;
}
v8 = (unsigned __int8 *)*((_QWORD *)v4 + 1);
if ( !v8 || v6 != *v8 )
{
if ( !*((_QWORD *)v4 + 2) )
return v2;
goto LABEL_14;
}
LABEL_36:
func8(v8);
*((_QWORD *)v4 + 1) = 0LL;
return v2;
}
v8 = (unsigned __int8 *)*((_QWORD *)v4 + 1);
if ( v8 )
{
if ( v6 != *v8 )
return v2;
goto LABEL_36;
}
if ( !*((_QWORD *)v4 + 2) )
return v2;
LABEL_14:
v4 = (unsigned __int8 *)*((_QWORD *)v4 + 2);
if ( !*v4 )
{
v7 = (unsigned __int8 *)*((_QWORD *)v4 + 3);
if ( v7 )
{
if ( v6 == *v7 )
goto LABEL_17;
}
}
return v2;
}

original_code:
void * tst_delete(Tptr p, char *s)
{
   Tptr last_p = p;
   void * val= 0;
   char *last_s = s;
   if (!s)
   {
      return ((void *)0);
   }
   while (p)
   {
      if (*s == p->splitchar)
      {
  if (*s++ == 0)
  {
     val = (void*)(p->eqkid);
     break;
  }
  p = p->eqkid;
      }
      else
      {
  last_s = s;
  if (*s < p->splitchar)
     p = p->lokid;
  else
     p = p->hikid;
  if (p->lokid || p->hikid)
  {
     last_p = p;
  }
      }
   }
   if (last_p && p)
   {
      if (last_p->splitchar == *last_s)
      {
  if (last_p->eqkid)
  {
     if (last_p->eqkid->hikid)
     {
        Tptr tt = last_p->eqkid;
        last_p->eqkid = last_p->eqkid->hikid;
        free(tt);
     }
     else
     {
        tst_cleanup(last_p->eqkid);
        last_p->eqkid = ((void *)0);
     }
  }
      }
      else if (last_p->hikid)
      {
  if (last_p->hikid->splitchar == *last_s)
  {
     tst_cleanup(last_p->hikid);
     last_p->hikid = ((void *)0);
  }
  else if ((last_p->lokid) && (last_p->lokid->splitchar == *last_s))
  {
     tst_cleanup(last_p->lokid);
     last_p->lokid = ((void *)0);
  }
  else if (last_p->eqkid)
  {
     goto eqkid;
  }
      }
      else if (last_p->lokid)
      {
  if (last_p->lokid->splitchar == *last_s)
  {
     tst_cleanup(last_p->lokid);
     last_p->lokid = ((void *)0);
  }
      }
      else if (last_p->eqkid)
      {
  Tptr tt;
 eqkid:
  tt = last_p->eqkid;
  if (tt->splitchar == 0)
  {
     if (tt->hikid && tt->hikid->splitchar == *last_s)
     {
        tst_cleanup(tt->hikid);
        tt->hikid = ((void *)0);
     }
  }
      }
   }
   return val;
}

canonical_original_code:
void *tst_delete(struct tnode *p, char *s)
{
   struct tnode *last_p = p;
   void *val = 0;
   char *last_s = s;
   if (!s)
   {
      return ((void *)0);
   }
   while (p)
   {
      if (*s == p->splitchar)
      {
  if (*s++ == 0)
  {
     val = (void *)(p->eqkid);
     break;
  }
  p = p->eqkid;
      }
      else
      {
  last_s = s;
  if (*s < p->splitchar)
     p = p->lokid;
  else
     p = p->hikid;
  if (p->lokid || p->hikid)
  {
     last_p = p;
  }
      }
   }
   if (last_p && p)
   {
      if (last_p->splitchar == *last_s)
      {
  if (last_p->eqkid)
  {
     if (last_p->eqkid->hikid)
     {
        struct tnode *tt = last_p->eqkid;
        last_p->eqkid = last_p->eqkid->hikid;
        free(tt);
     }
     else
     {
        tst_cleanup(last_p->eqkid);
        last_p->eqkid = ((void *)0);
     }
  }
      }
      else if (last_p->hikid)
      {
  if (last_p->hikid->splitchar == *last_s)
  {
     tst_cleanup(last_p->hikid);
     last_p->hikid = ((void *)0);
  }
  else if ((last_p->lokid) && (last_p->lokid->splitchar == *last_s))
  {
     tst_cleanup(last_p->lokid);
     last_p->lokid = ((void *)0);
  }
  else if (last_p->eqkid)
  {
     goto eqkid;
  }
      }
      else if (last_p->lokid)
      {
  if (last_p->lokid->splitchar == *last_s)
  {
     tst_cleanup(last_p->lokid);
     last_p->lokid = ((void *)0);
  }
      }
      else if (last_p->eqkid)
      {
  struct tnode *tt;
 eqkid:
  tt = last_p->eqkid;
  if (tt->splitchar == 0)
  {
     if (tt->hikid && tt->hikid->splitchar == *last_s)
     {
        tst_cleanup(tt->hikid);
        tt->hikid = ((void *)0);
     }
  }
      }
   }
   return val;
}

variable_types: struct tnode { unsigned char splitchar; struct tnode *lokid; } *

variable_types:
s
char *

return_type: void *


decompiled_code:
_QWORD *tst_init()
{
return tst_insert_localalias(0LL, 0LL, 0LL);
}

canonical_decompiled_code:
_QWORD *func12()
{
return tst_insert_localalias(0LL, 0LL, 0LL);
}

original_code:
Tptr tst_init()
{
   return tst_insert(0, 0, 0);
}

canonical_original_code:
struct tnode *tst_init()
{
   return tst_insert(0, 0, 0);
}

return_type: struct tnode { unsigned char splitchar; struct tnode *lokid; } *


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

result = 1LL;
if ( !*(_BYTE *)a1 )
{
*(_QWORD *)(a1 + 16) = a2;
result = 0LL;
}
return result;
}

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

result = 1LL;
if ( !*(_BYTE *)a1 )
{
*(_QWORD *)(a1 + 16) = a2;
result = 0LL;
}
return result;
}

original_code:
int tst_attach(Tptr p, void *val)
{
   if (!p->splitchar)
   {
      p->eqkid = (Tptr)val;
      return 0;
   }
   return 1;
}

canonical_original_code:
int tst_attach(struct tnode *p, void *val)
{
   if (!p->splitchar)
   {
      p->eqkid = (struct tnode *)val;
      return 0;
   }
   return 1;
}

user_defined_types: struct tnode { unsigned char splitchar; struct tnode *lokid; }


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

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

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

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

original_code:
void* tst_retrieve(Tptr p)
{
   if (!p->splitchar)
   {
      return (void*)(p->eqkid);
   }
   else
   {
      return 0;
   }
}

canonical_original_code:
void *tst_retrieve(struct tnode *p)
{
   if (!p->splitchar)
   {
      return (void *)(p->eqkid);
   }
   else
   {
      return 0;
   }
}


decompiled_code:
int __fastcall nrf24_msleep(unsigned int a1)
{
struct timespec v2; // [rsp+0h] [rbp-18h] BYREF

v2.tv_sec = a1 / 0x3E8;
v2.tv_nsec = 1000000LL * (a1 % 0x3E8);
return nanosleep(&v2, 0LL);
}

canonical_decompiled_code:
int __fastcall func0(unsigned int a1)
{
struct timespec v2; // [rsp+0h] [rbp-18h] BYREF

v2.tv_sec = a1 / 0x3E8;
v2.tv_nsec = 1000000LL * (a1 % 0x3E8);
return nanosleep(&v2, 0LL);
}

original_code:
void nrf24_msleep(const uint32_t milliseconds)
{
 struct timespec req;
 uint32_t sec = milliseconds / 1000;
 uint32_t msec = milliseconds - (sec * 1000);
 req.tv_sec = sec;
 req.tv_nsec = msec * 1000000L;
 nanosleep(&req, (struct timespec *)((void *)0));
}

canonical_original_code:
void nrf24_msleep(unsigned int milliseconds)
{
 struct timespec req;
 unsigned int sec = milliseconds / 1000;
 unsigned int msec = milliseconds - (sec * 1000);
 req.tv_sec = sec;
 req.tv_nsec = msec * 1000000L;
 nanosleep(&req, (struct timespec *)((void *)0));
}

variable_types:
milliseconds
unsigned int

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

variable_types:
sec
unsigned int

variable_types:
msec
unsigned int


decompiled_code:
int __fastcall nrf24_usleep(unsigned int a1)
{
struct timespec v2; // [rsp+0h] [rbp-18h] BYREF

v2.tv_sec = a1 / 0xF4240;
v2.tv_nsec = 1000LL * (a1 % 0xF4240);
return nanosleep(&v2, 0LL);
}

canonical_decompiled_code:
int __fastcall func1(unsigned int a1)
{
struct timespec v2; // [rsp+0h] [rbp-18h] BYREF

v2.tv_sec = a1 / 0xF4240;
v2.tv_nsec = 1000LL * (a1 % 0xF4240);
return nanosleep(&v2, 0LL);
}

original_code:
void nrf24_usleep(const uint32_t microseconds)
{
 struct timespec req;
 uint32_t sec = microseconds / 1000000;
 uint32_t usec = microseconds - (sec * 1000000);
 req.tv_sec = sec;
 req.tv_nsec = usec * 1000L;
 nanosleep(&req, (struct timespec *)((void *)0));
}

canonical_original_code:
void nrf24_usleep(unsigned int microseconds)
{
 struct timespec req;
 unsigned int sec = microseconds / 1000000;
 unsigned int usec = microseconds - (sec * 1000000);
 req.tv_sec = sec;
 req.tv_nsec = usec * 1000L;
 nanosleep(&req, (struct timespec *)((void *)0));
}

variable_types:
microseconds
unsigned int

variable_types:
usec
unsigned int

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


variable_types:
controller
unsigned int

variable_types:
device
unsigned int

variable_types:
speed
unsigned int

variable_types:
bits
unsigned char

variable_types:
mode
unsigned char

variable_types: fd int

variable_types: result int

variable_types:
devicefile
char [256]


decompiled_code:
__int64 __fastcall nrf24_spi_close(int a1)
{
if ( a1 < 0 )
return 4294967195LL;
close(a1);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func1(int a1)
{
if ( a1 < 0 )
return 4294967195LL;
close(a1);
return 0LL;
}

original_code:
int32_t nrf24_spi_close(const int32_t handle)
{
 if (handle >= 0) {
  close(handle);
  return 0;
 }
 return -101;
}

canonical_original_code:
int nrf24_spi_close(int handle)
{
 if (handle >= 0) {
  close(handle);
  return 0;
 }
 return -101;
}

variable_types: handle int


decompiled_code:
int __fastcall nrf24_spi_transfer(int a1, __int64 a2, __int64 a3, unsigned __int16 a4)
{
int result; // eax
__int64 v5[2]; // [rsp+0h] [rbp-28h] BYREF
__int64 v6; // [rsp+10h] [rbp-18h]
__int64 v7; // [rsp+18h] [rbp-10h]

v6 = 0LL;
v7 = 0LL;
if ( a1 < 0 )
return -101;
if ( !a2 || !a3 )
return -100;
v5[0] = a2;
v5[1] = a3;
LODWORD(v6) = a4;
BYTE3(v7) = 1;
result = ioctl(a1, 0x40206B00uLL, v5);
if ( result <= 0 )
result = -104;
return result;
}

canonical_decompiled_code:
int __fastcall func2(int a1, __int64 a2, __int64 a3, unsigned __int16 a4)
{
int result; // eax
__int64 v5[2]; // [rsp+0h] [rbp-28h] BYREF
__int64 v6; // [rsp+10h] [rbp-18h]
__int64 v7; // [rsp+18h] [rbp-10h]

v6 = 0LL;
v7 = 0LL;
if ( a1 < 0 )
return -101;
if ( !a2 || !a3 )
return -100;
v5[0] = a2;
v5[1] = a3;
LODWORD(v6) = a4;
BYTE3(v7) = 1;
result = ioctl(a1, 0x40206B00uLL, v5);
if ( result <= 0 )
result = -104;
return result;
}

original_code:
int32_t nrf24_spi_transfer(const int32_t handle, uint8_t *tx, uint8_t *rx, const uint16_t len)
{
 int32_t result = 0;
 struct spi_ioc_transfer tr = {
  .tx_buf = 0,
  .rx_buf = 0,
  .len = 0,
  .delay_usecs = 0,
  .cs_change = 0
 };
 if (handle < 0) {
  return -101;
 }
 if (tx == 0 || rx == 0) {
  return -100;
 }
 tr.tx_buf = (unsigned long)tx;
 tr.rx_buf = (unsigned long)rx;
 tr.len = len;
 tr.delay_usecs = 0;
 tr.cs_change = 1;
 result = ioctl(handle, (((1U) << (((0 +8)+8)+14)) | ((('k')) << (0 +8)) | (((0)) << 0) | ((((sizeof(char[((((1)*(sizeof (struct spi_ioc_transfer))) < (1 << 14)) ? ((1)*(sizeof (struct spi_ioc_transfer))) : 0)])))) << ((0 +8)+8))), &tr);
 if (result < 1) {
  result = -104;
 }
 return result;
}

canonical_original_code:
int nrf24_spi_transfer(int handle, unsigned char *tx, unsigned char *rx, unsigned short len)
{
 int result = 0;
 struct spi_ioc_transfer tr = {
  .tx_buf = 0,
  .rx_buf = 0,
  .len = 0,
  .delay_usecs = 0,
  .cs_change = 0
 };
 if (handle < 0) {
  return -101;
 }
 if (tx == 0 || rx == 0) {
  return -100;
 }
 tr.tx_buf = (unsigned long)tx;
 tr.rx_buf = (unsigned long)rx;
 tr.len = len;
 tr.delay_usecs = 0;
 tr.cs_change = 1;
 result = ioctl(handle, (((1U) << (((0 +8)+8)+14)) | ((('k')) << (0 +8)) | (((0)) << 0) | ((((sizeof(char [-1])))) << ((0 +8)+8))), &tr);
 if (result < 1) {
  result = -104;
 }
 return result;
}

variable_types:
tx
unsigned char *

variable_types:
rx
unsigned char *

variable_types:
len
unsigned short

variable_types: struct spi_ioc_transfer { unsigned long long tx_buf; unsigned long long rx_buf; unsigned int len; unsigned int speed_hz; unsigned short delay_usecs; unsigned char bits_per_word; unsigned char cs_change; unsigned char tx_nbits; unsigned char rx_nbits; unsigned short pad; }


decompiled_code:
__int64 __fastcall nrf24_decode_uint8(_BYTE *a1, _BYTE *a2, int a3)
{
if ( a3 <= 0 || a2 == 0LL || !a1 )
return 4294967196LL;
*a1 = *a2;
return 1LL;
}

original_code:
int32_t nrf24_decode_uint8(uint8_t *value, const uint8_t *bytes, const int32_t len)
{
 if (value == 0 || bytes == 0 || len < (int32_t)sizeof(uint8_t)) {
  return -100;
 }
 memcpy(value, bytes, sizeof(uint8_t));
 return (int32_t)sizeof(uint8_t);
}

canonical_original_code:
int nrf24_decode_uint8(unsigned char *value, unsigned char *bytes, int len)
{
 if (value == 0 || bytes == 0 || len < (int)sizeof(unsigned char)) {
  return -100;
 }
 memcpy(value, bytes, sizeof(unsigned char));
 return (int)sizeof(unsigned char);
}

variable_types:
value
unsigned char *

variable_types:
bytes
unsigned char *

variable_types: len int


decompiled_code:
__int64 __fastcall nrf24_decode_uint16(_WORD *a1, _WORD *a2, int a3)
{
if ( a3 <= 1 || a2 == 0LL || !a1 )
return 4294967196LL;
*a1 = *a2;
return 2LL;
}

original_code:
int32_t nrf24_decode_uint16(uint16_t *value, const uint8_t *bytes, const int32_t len)
{
 if (value == 0 || bytes == 0 || len < (int32_t)sizeof(uint16_t)) {
  return -100;
 }
 memcpy(value, bytes, sizeof(uint16_t));
 return (int32_t)sizeof(uint16_t);
}

canonical_original_code:
int nrf24_decode_uint16(unsigned short *value, unsigned char *bytes, int len)
{
 if (value == 0 || bytes == 0 || len < (int)sizeof(unsigned short)) {
  return -100;
 }
 memcpy(value, bytes, sizeof(unsigned short));
 return (int)sizeof(unsigned short);
}

variable_types:
value
unsigned short *


decompiled_code:
__int64 __fastcall nrf24_decode_uint32(_DWORD *a1, _DWORD *a2, int a3)
{
if ( a3 <= 3 || a2 == 0LL || !a1 )
return 4294967196LL;
*a1 = *a2;
return 4LL;
}

canonical_decompiled_code:
__int64 __fastcall func5(_DWORD *a1, _DWORD *a2, int a3)
{
if ( a3 <= 3 || a2 == 0LL || !a1 )
return 4294967196LL;
*a1 = *a2;
return 4LL;
}

original_code:
int32_t nrf24_decode_uint32(uint32_t *value, const uint8_t *bytes, const int32_t len)
{
 if (value == 0 || bytes == 0 || len < (int32_t)sizeof(uint32_t)) {
  return -100;
 }
 memcpy(value, bytes, sizeof(uint32_t));
 return (int32_t)sizeof(uint32_t);
}

canonical_original_code:
int nrf24_decode_uint32(unsigned int *value, unsigned char *bytes, int len)
{
 if (value == 0 || bytes == 0 || len < (int)sizeof(unsigned int)) {
  return -100;
 }
 memcpy(value, bytes, sizeof(unsigned int));
 return (int)sizeof(unsigned int);
}

variable_types:
value
unsigned int *


decompiled_code:
__int64 __fastcall nrf24_decode_uint64(_QWORD *a1, _QWORD *a2, int a3)
{
if ( a3 <= 7 || a2 == 0LL || !a1 )
return 4294967196LL;
*a1 = *a2;
return 8LL;
}

canonical_decompiled_code:
__int64 __fastcall func7(_QWORD *a1, _QWORD *a2, int a3)
{
if ( a3 <= 7 || a2 == 0LL || !a1 )
return 4294967196LL;
*a1 = *a2;
return 8LL;
}

original_code:
int32_t nrf24_decode_uint64(uint64_t *value, const uint8_t *bytes, const int32_t len)
{
 if (value == 0 || bytes == 0 || len < (int32_t)sizeof(uint64_t)) {
  return -100;
 }
 memcpy(value, bytes, sizeof(uint64_t));
 return (int32_t)sizeof(uint64_t);
}

canonical_original_code:
int nrf24_decode_uint64(unsigned long *value, unsigned char *bytes, int len)
{
 if (value == 0 || bytes == 0 || len < (int)sizeof(unsigned long)) {
  return -100;
 }
 memcpy(value, bytes, sizeof(unsigned long));
 return (int)sizeof(unsigned long);
}

variable_types:
value
unsigned long *


repo: blueooh/CPerl-Chat

decompiled_code:
__int64 __fastcall cp_init_log(const char *a1)
{
log_fd = open(a1, 1090, 420LL);
return (unsigned int)-(log_fd == 0);
}

canonical_decompiled_code:
__int64 __fastcall func0(const char *a1)
{
log_fd = open(a1, 1090, 420LL);
return (unsigned int)-(log_fd == 0);
}

original_code:
int cp_init_log(const char * file)
{
    log_fd = open(file, 02| 02000 | 0100, 0644);
    if(!log_fd) {
        return -1;
    }
    return 0;
}

canonical_original_code:
int cp_init_log(char *file)
{
    log_fd = open(file, 02| 02000 | 0100, 0644);
    if(!log_fd) {
        return -1;
    }
    return 0;
}

variable_types:
file
char *


decompiled_code:
int __fastcall cp_get_log_time(char *s, int a2)
{
struct tm v3; // [rsp+0h] [rbp-58h] BYREF
time_t timer; // [rsp+38h] [rbp-20h] BYREF

timer = time(0LL);
localtime_r(&timer, &v3);
return snprintf(
s,
a2,
"[%04d.%02d.%02d %02d:%02d:%02d] ",
(unsigned int)(v3.tm_year + 1900),
(unsigned int)(v3.tm_mon + 1),
(unsigned int)v3.tm_mday,
(unsigned int)v3.tm_hour,
(unsigned int)v3.tm_min,
(unsigned int)v3.tm_sec);
}

canonical_decompiled_code:
int __fastcall func1(char *s, int a2)
{
struct tm v3; // [rsp+0h] [rbp-58h] BYREF
time_t timer; // [rsp+38h] [rbp-20h] BYREF

timer = time(0LL);
localtime_r(&timer, &v3);
return snprintf(
s,
a2,
"[%04d.%02d.%02d %02d:%02d:%02d] ",
(unsigned int)(v3.tm_year + 1900),
(unsigned int)(v3.tm_mon + 1),
(unsigned int)v3.tm_mday,
(unsigned int)v3.tm_hour,
(unsigned int)v3.tm_min,
(unsigned int)v3.tm_sec);
}

original_code:
int cp_get_log_time(char *buf, int size)
{
    int len;
    time_t now;
    struct tm cur_time;
    now = time(((void *)0));
    localtime_r(&now, &cur_time);
    len = snprintf(buf, size, "[%04d.%02d.%02d %02d:%02d:%02d] ",
            cur_time.tm_year+1900, cur_time.tm_mon+1,cur_time.tm_mday,
            cur_time.tm_hour,cur_time.tm_min,cur_time.tm_sec);
    return len;
}

canonical_original_code:
int cp_get_log_time(char *buf, int size)
{
    int len;
    long now;
    struct tm cur_time;
    now = time(((void *)0));
    localtime_r(&now, &cur_time);
    len = snprintf(buf, size, "[%04d.%02d.%02d %02d:%02d:%02d] ",
            cur_time.tm_year+1900, cur_time.tm_mon+1,cur_time.tm_mday,
            cur_time.tm_hour,cur_time.tm_min,cur_time.tm_sec);
    return len;
}

variable_types:
buf
char *

variable_types: size int

variable_types: now long

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


decompiled_code:
__int64 cp_log(char *format, ...)
{
char *v1; // r12
int v2; // ebx
char *v3; // rax
int v4; // eax
int v5; // eax
int v6; // ebp
gcc_va_list arg; // [rsp+8h] [rbp-4F0h] BYREF
char s[1024]; // [rsp+20h] [rbp-4D8h] BYREF

v1 = (char *)malloc(0x400uLL);
if ( v1 )
{
v2 = 1024;
while ( 1 )
{
va_start(arg, format);
v4 = vsnprintf(v1, v2, format, arg);
if ( v4 >= 0 && v2 > v4 )
break;
v2 *= 2;
if ( v4 >= 0 )
v2 = v4 + 1;
v3 = (char *)realloc(v1, v2);
if ( !v3 )
{
free(v1);
v1 = 0LL;
break;
}
v1 = v3;
}
}
else
{
v2 = 1024;
}
v5 = cp_get_log_time(s, 1024);
if ( v1[7] == 10 )
v6 = snprintf(&s[v5], v2, "%s", v1) + v5;
else
v6 = snprintf(&s[v5], v2 + 1, "%s\n", v1) + v5;
write(log_fd, s, v6);
free(v1);
return (unsigned int)v6;
}

canonical_decompiled_code:
__int64 func2(char *format, ...)
{
char *v1; // r12
int v2; // ebx
char *v3; // rax
int v4; // eax
int v5; // eax
int v6; // ebp
gcc_va_list arg; // [rsp+8h] [rbp-4F0h] BYREF
char s[1024]; // [rsp+20h] [rbp-4D8h] BYREF

v1 = (char *)malloc(0x400uLL);
if ( v1 )
{
v2 = 1024;
while ( 1 )
{
va_start(arg, format);
v4 = vsnprintf(v1, v2, format, arg);
if ( v4 >= 0 && v2 > v4 )
break;
v2 *= 2;
if ( v4 >= 0 )
v2 = v4 + 1;
v3 = (char *)realloc(v1, v2);
if ( !v3 )
{
free(v1);
v1 = 0LL;
break;
}
v1 = v3;
}
}
else
{
v2 = 1024;
}
v5 = func1(s, 1024);
if ( v1[7] == 10 )
v6 = snprintf(&s[v5], v2, "%s", v1) + v5;
else
v6 = snprintf(&s[v5], v2 + 1, "%s\n", v1) + v5;
write(log_fd, s, v6);
free(v1);
return (unsigned int)v6;
}

original_code:
int cp_log(char *buf, ...)
{
    char log_buf[1024];
    int log_size;
    va_list argptr; int vaa_size, vaa_num; char *vbuffer, *vaa_buffer2; vaa_size = 1024; vbuffer = malloc (vaa_size); if (vbuffer) { while (1) { __builtin_va_start(argptr,buf); vaa_num = vsnprintf (vbuffer, vaa_size, buf, argptr); __builtin_va_end(argptr); if ((vaa_num >= 0) && (vaa_num < vaa_size)) break; vaa_size = (vaa_num >= 0) ? vaa_num + 1 : vaa_size * 2; vaa_buffer2 = realloc (vbuffer, vaa_size); if (!vaa_buffer2) { free (vbuffer); vbuffer = ((void *)0); break; } vbuffer = vaa_buffer2; } };
    log_size = cp_get_log_time(log_buf, sizeof(log_buf));
    int vb_len = sizeof(vbuffer) - 1;
    if(vbuffer[vb_len] == '\n') {
        log_size += snprintf(log_buf + log_size, vaa_size, "%s", vbuffer);
    } else {
        log_size += snprintf(log_buf + log_size, vaa_size + 1, "%s\n", vbuffer);
    }
    write(log_fd, log_buf, log_size);
    free(vbuffer);
    return log_size;
}

canonical_original_code:
int cp_log(char *buf, ...)
{
    char log_buf[1024];
    int log_size;
    __builtin_va_list argptr; int vaa_size; int vaa_num; char *vbuffer; char *vaa_buffer2; vaa_size = 1024; vbuffer = malloc (vaa_size); if (vbuffer) { while (1) { __builtin_va_start(argptr,buf); vaa_num = vsnprintf (vbuffer, vaa_size, buf, argptr); __builtin_va_end(argptr); if ((vaa_num >= 0) && (vaa_num < vaa_size)) break; vaa_size = (vaa_num >= 0) ? vaa_num + 1 : vaa_size * 2; vaa_buffer2 = realloc (vbuffer, vaa_size); if (!vaa_buffer2) { free (vbuffer); vbuffer = ((void *)0); break; } vbuffer = vaa_buffer2; } };
    log_size = cp_get_log_time(log_buf, sizeof(log_buf));
    int vb_len = sizeof(vbuffer) - 1;
    if(vbuffer[vb_len] == '\n') {
        log_size += snprintf(log_buf + log_size, vaa_size, "%s", vbuffer);
    } else {
        log_size += snprintf(log_buf + log_size, vaa_size + 1, "%s\n", vbuffer);
    }
    write(log_fd, log_buf, log_size);
    free(vbuffer);
    return log_size;
}

variable_types:
vbuffer
char *


original_code:
void list_del(struct list_head *entry)
{
    __list_del(entry->prev, entry->next);
    entry->next = ((void *) 0x00100100);
    entry->prev = ((void *) 0x00200200);
}

variable_types: struct list_head { struct list_head *next; } *