decompiled_code:
__int64 __fastcall rdp_send_scancode(unsigned int a1, unsigned __int16 a2, unsigned __int8 a3)
{
unsigned __int16 v3; // bx
unsigned int v5; // er13

LOBYTE(v3) = a2;
v5 = a3;
update_modifier_state(a3, (a2 & 0xC000) == 0);
if ( (a3 & 0x80u) == 0 )
return rdp_send_input(a1, 4LL, a2, v5, 0LL);
HIBYTE(v3) = HIBYTE(a2) | 1;
return rdp_send_input(a1, 4LL, v3, (unsigned __int16)v5 & 0xFF7F, 0LL);
}

canonical_decompiled_code:
__int64 __fastcall func7(unsigned int a1, unsigned __int16 a2, unsigned __int8 a3)
{
unsigned __int16 v3; // bx
unsigned int v5; // er13

LOBYTE(v3) = a2;
v5 = a3;
func0(a3, (a2 & 0xC000) == 0);
if ( (a3 & 0x80u) == 0 )
return rdp_send_input(a1, 4LL, a2, v5, 0LL);
HIBYTE(v3) = HIBYTE(a2) | 1;
return rdp_send_input(a1, 4LL, v3, (unsigned __int16)v5 & 0xFF7F, 0LL);
}

original_code:
void
rdp_send_scancode(uint32 time, uint16 flags, uint8 scancode)
{
 update_modifier_state(scancode, !(flags & (0x4000 | 0x8000)));
 if (scancode & 0x80)
 {
  ;
  rdp_send_input(time, RDP_INPUT_SCANCODE, flags | 0x0100,
          scancode & ~0x80, 0);
 }
 else
 {
  ;
  rdp_send_input(time, RDP_INPUT_SCANCODE, flags, scancode, 0);
 }
}

canonical_original_code:
void rdp_send_scancode(unsigned int time, unsigned short flags, unsigned char scancode)
{
 update_modifier_state(scancode, !(flags & (0x4000 | 0x8000)));
 if (scancode & 0x80)
 {
  ;
  rdp_send_input(time, RDP_INPUT_SCANCODE, flags | 0x0100,
          scancode & ~0x80, 0);
 }
 else
 {
  ;
  rdp_send_input(time, RDP_INPUT_SCANCODE, flags, scancode, 0);
 }
}

variable_types:
time
unsigned int

variable_types:
flags
unsigned short


decompiled_code:
__int64 __fastcall handle_special_keys(unsigned int a1, unsigned int a2, unsigned int a3, int a4)
{
__int64 result; // rax

if ( a1 == 65387 )
{
result = 1LL;
if ( a4 )
{
rdp_send_scancode(a3, 0, 0xC6u);
rdp_send_scancode(a3, 0, 0xC6u);
result = 1LL;
}
}
else if ( a1 > 0xFF6B )
{
if ( a1 <= 0xFFE8 )
{
result = 0LL;
if ( a1 <= 0xFFE6 )
return result;
}
else
{
result = 0LL;
if ( a1 - 65515 > 3 )
return result;
}
if ( a4 )
{
rdp_send_scancode(a3, 0, 0x1Du);
rdp_send_scancode(a3, 0, 1u);
}
else
{
rdp_send_scancode(a3, 0xC000u, 1u);
rdp_send_scancode(a3, 0xC000u, 0x1Du);
}
result = 1LL;
}
else if ( a1 == 65293 )
{
if ( (unsigned int)get_key_state(a2, 65513LL) || (result = get_key_state(a2, 65514LL), (_DWORD)result) )
{
if ( (unsigned int)get_key_state(a2, 65507LL) || (result = get_key_state(a2, 65508LL), (_DWORD)result) )
{
result = 1LL;
if ( a4 )
{
xwin_toggle_fullscreen();
result = 1LL;
}
}
}
}
else if ( a1 == 65299 )
{
if ( a4 )
{
rdp_send_input(a3, 4LL, 0LL, 225LL, 0LL);
rdp_send_input(a3, 4LL, 0LL, 29LL, 0LL);
rdp_send_input(a3, 4LL, 0LL, 69LL, 0LL);
rdp_send_input(a3, 4LL, 0LL, 225LL, 0LL);
rdp_send_input(a3, 4LL, 0LL, 157LL, 0LL);
rdp_send_input(a3, 4LL, 0LL, 197LL, 0LL);
}
else
{
rdp_send_input(a3, 4LL, 49152LL, 29LL, 0LL);
}
result = 1LL;
}
else
{
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func8(unsigned int a1, unsigned int a2, unsigned int a3, int a4)
{
__int64 result; // rax

if ( a1 == 65387 )
{
result = 1LL;
if ( a4 )
{
func7(a3, 0, 0xC6u);
func7(a3, 0, 0xC6u);
result = 1LL;
}
}
else if ( a1 > 0xFF6B )
{
if ( a1 <= 0xFFE8 )
{
result = 0LL;
if ( a1 <= 0xFFE6 )
return result;
}
else
{
result = 0LL;
if ( a1 - 65515 > 3 )
return result;
}
if ( a4 )
{
func7(a3, 0, 0x1Du);
func7(a3, 0, 1u);
}
else
{
func7(a3, 0xC000u, 1u);
func7(a3, 0xC000u, 0x1Du);
}
result = 1LL;
}
else if ( a1 == 65293 )
{
if ( (unsigned int)get_key_state(a2, 65513LL) || (result = get_key_state(a2, 65514LL), (_DWORD)result) )
{
if ( (unsigned int)get_key_state(a2, 65507LL) || (result = get_key_state(a2, 65508LL), (_DWORD)result) )
{
result = 1LL;
if ( a4 )
{
xwin_toggle_fullscreen();
result = 1LL;
}
}
}
}
else if ( a1 == 65299 )
{
if ( a4 )
{
rdp_send_input(a3, 4LL, 0LL, 225LL, 0LL);
rdp_send_input(a3, 4LL, 0LL, 29LL, 0LL);
rdp_send_input(a3, 4LL, 0LL, 69LL, 0LL);
rdp_send_input(a3, 4LL, 0LL, 225LL, 0LL);
rdp_send_input(a3, 4LL, 0LL, 157LL, 0LL);
rdp_send_input(a3, 4LL, 0LL, 197LL, 0LL);
}
else
{
rdp_send_input(a3, 4LL, 49152LL, 29LL, 0LL);
}
result = 1LL;
}
else
{
result = 0LL;
}
return result;
}

original_code:
BOOL
handle_special_keys(uint32 keysym, unsigned int state, uint32 ev_time, BOOL pressed)
{
 switch (keysym)
 {
  case 0xff0d:
   if ((get_key_state(state, 0xffe9) || get_key_state(state, 0xffea))
       && (get_key_state(state, 0xffe3)
    || get_key_state(state, 0xffe4)))
   {
    if (pressed)
     xwin_toggle_fullscreen();
    return 1;
   }
   break;
  case 0xff6b:
   if (pressed)
   {
    rdp_send_scancode(ev_time, 0,
        (0x80 | 0x46));
    rdp_send_scancode(ev_time, 0,
        (0x80 | 0xc6));
   }
   return 1;
  case 0xff13:
   if (pressed)
   {
    rdp_send_input(ev_time, RDP_INPUT_SCANCODE, 0, 0xe1, 0);
    rdp_send_input(ev_time, RDP_INPUT_SCANCODE, 0, 0x1d, 0);
    rdp_send_input(ev_time, RDP_INPUT_SCANCODE, 0, 0x45, 0);
    rdp_send_input(ev_time, RDP_INPUT_SCANCODE, 0, 0xe1, 0);
    rdp_send_input(ev_time, RDP_INPUT_SCANCODE, 0, 0x9d, 0);
    rdp_send_input(ev_time, RDP_INPUT_SCANCODE, 0, 0xc5, 0);
   }
   else
   {
    rdp_send_input(ev_time, RDP_INPUT_SCANCODE, (0x4000 | 0x8000),
            0x1d, 0);
   }
   return 1;
  case 0xffe7:
  case 0xffeb:
  case 0xffed:
  case 0xffe8:
  case 0xffec:
  case 0xffee:
   if (pressed)
   {
    rdp_send_scancode(ev_time, 0, 0x1d);
    rdp_send_scancode(ev_time, 0, 0x1);
   }
   else
   {
    rdp_send_scancode(ev_time, (0x4000 | 0x8000), 0x1);
    rdp_send_scancode(ev_time, (0x4000 | 0x8000), 0x1d);
   }
   return 1;
 }
 return 0;
}

canonical_original_code:
int handle_special_keys(unsigned int keysym, unsigned int state, unsigned int ev_time, int pressed)
{
 switch (keysym)
 {
  case 0xff0d:
   if ((get_key_state(state, 0xffe9) || get_key_state(state, 0xffea))
       && (get_key_state(state, 0xffe3)
    || get_key_state(state, 0xffe4)))
   {
    if (pressed)
     xwin_toggle_fullscreen();
    return 1;
   }
   break;
  case 0xff6b:
   if (pressed)
   {
    rdp_send_scancode(ev_time, 0,
        (0x80 | 0x46));
    rdp_send_scancode(ev_time, 0,
        (0x80 | 0xc6));
   }
   return 1;
  case 0xff13:
   if (pressed)
   {
    rdp_send_input(ev_time, RDP_INPUT_SCANCODE, 0, 0xe1, 0);
    rdp_send_input(ev_time, RDP_INPUT_SCANCODE, 0, 0x1d, 0);
    rdp_send_input(ev_time, RDP_INPUT_SCANCODE, 0, 0x45, 0);
    rdp_send_input(ev_time, RDP_INPUT_SCANCODE, 0, 0xe1, 0);
    rdp_send_input(ev_time, RDP_INPUT_SCANCODE, 0, 0x9d, 0);
    rdp_send_input(ev_time, RDP_INPUT_SCANCODE, 0, 0xc5, 0);
   }
   else
   {
    rdp_send_input(ev_time, RDP_INPUT_SCANCODE, (0x4000 | 0x8000),
            0x1d, 0);
   }
   return 1;
  case 0xffe7:
  case 0xffeb:
  case 0xffed:
  case 0xffe8:
  case 0xffec:
  case 0xffee:
   if (pressed)
   {
    rdp_send_scancode(ev_time, 0, 0x1d);
    rdp_send_scancode(ev_time, 0, 0x1);
   }
   else
   {
    rdp_send_scancode(ev_time, (0x4000 | 0x8000), 0x1);
    rdp_send_scancode(ev_time, (0x4000 | 0x8000), 0x1d);
   }
   return 1;
 }
 return 0;
}

variable_types:
keysym
unsigned int

variable_types:
state
unsigned int

variable_types: pressed int

return_type: int


decompiled_code:
void __fastcall ensure_remote_modifiers(unsigned int a1, int a2)
{
unsigned __int16 v2; // bx

if ( (unsigned __int8)a2 > 0x45u )
{
if ( (_BYTE)a2 == 0xB8 )
return;
if ( (unsigned __int8)a2 <= 0xB8u )
{
if ( (_BYTE)a2 == 0x9D )
return;
}
else if ( (unsigned __int8)(a2 + 37) <= 1u )
{
return;
}
}
else if ( (unsigned __int8)a2 > 0x1Cu && ((1LL << ((unsigned __int8)a2 - 29)) & 0x1000A002001LL) != 0 )
{
return;
}
if ( ((a2 & 0x30000) != 0) != ((remote_modifier_state & 3) != 0) )
{
if ( (a2 & 0x20000) != 0 )
{
rdp_send_scancode(a1, 0, 0x2Au);
}
else if ( (a2 & 0x10000) != 0 )
{
rdp_send_scancode(a1, 0, 0x36u);
}
else if ( (remote_modifier_state & 2) != 0 )
{
rdp_send_scancode(a1, 0xC000u, 0x2Au);
}
else
{
rdp_send_scancode(a1, 0xC000u, 0x36u);
}
}
if ( ((a2 & 0x40000) != 0) != ((remote_modifier_state & 4) != 0) )
{
if ( (a2 & 0x40000) != 0 )
rdp_send_scancode(a1, 0, 0xB8u);
else
rdp_send_scancode(a1, 0xC000u, 0xB8u);
}
v2 = HIWORD(a2) & 0x100;
if ( ((a2 & 0x1000000) != 0) != (HIBYTE(remote_modifier_state) & 1) )
{
if ( v2 )
v2 = 2;
rdp_send_input(0LL, 0LL, 0LL, v2, 0LL);
update_modifier_state(0x45u, 1);
}
}

original_code:
void
ensure_remote_modifiers(uint32 ev_time, key_translation tr)
{
 switch (tr.scancode)
 {
  case 0x2a:
  case 0x36:
  case 0x1d:
  case (0x80 | 0x1d):
  case 0x38:
  case (0x80 | 0x38):
  case (0x80 | 0x5b):
  case (0x80 | 0x5c):
  case 0x45:
   return;
  default:
   break;
 }
 if (((tr.modifiers & ((1<<0) | (1<<1)))>0)
     != ((remote_modifier_state & ((1<<0) | (1<<1)))>0))
 {
  if (((tr.modifiers & (1<<1))>0))
  {
   rdp_send_scancode(ev_time, 0, 0x2a);
  }
  else if (((tr.modifiers & (1<<0))>0))
  {
   rdp_send_scancode(ev_time, 0, 0x36);
  }
  else
  {
   if (((remote_modifier_state & (1<<1))>0))
    rdp_send_scancode(ev_time, (0x4000 | 0x8000), 0x2a);
   else
    rdp_send_scancode(ev_time, (0x4000 | 0x8000), 0x36);
  }
 }
 if (((tr.modifiers & (1<<2))>0)
     != ((remote_modifier_state & (1<<2))>0))
 {
  if (((tr.modifiers & (1<<2))>0))
  {
   rdp_send_scancode(ev_time, 0, (0x80 | 0x38));
  }
  else
  {
   rdp_send_scancode(ev_time, (0x4000 | 0x8000), (0x80 | 0x38));
  }
 }
 if (((tr.modifiers & (1<<8))>0)
     != ((remote_modifier_state & (1<<8))>0))
 {
  uint16 new_remote_state = 0;
  if (((tr.modifiers & (1<<8))>0))
  {
   ;
   new_remote_state |= 0x0002;
  }
  else
  {
   ;
  }
  rdp_send_input(0, RDP_INPUT_SYNCHRONIZE, 0, new_remote_state, 0);
  update_modifier_state(0x45, 1);
 }
}

canonical_original_code:
void ensure_remote_modifiers(unsigned int ev_time, struct _key_translation tr)
{
 switch (tr.scancode)
 {
  case 0x2a:
  case 0x36:
  case 0x1d:
  case (0x80 | 0x1d):
  case 0x38:
  case (0x80 | 0x38):
  case (0x80 | 0x5b):
  case (0x80 | 0x5c):
  case 0x45:
   return;
  default:
   break;
 }
 if (((tr.modifiers & ((1<<0) | (1<<1)))>0)
     != ((remote_modifier_state & ((1<<0) | (1<<1)))>0))
 {
  if (((tr.modifiers & (1<<1))>0))
  {
   rdp_send_scancode(ev_time, 0, 0x2a);
  }
  else if (((tr.modifiers & (1<<0))>0))
  {
   rdp_send_scancode(ev_time, 0, 0x36);
  }
  else
  {
   if (((remote_modifier_state & (1<<1))>0))
    rdp_send_scancode(ev_time, (0x4000 | 0x8000), 0x2a);
   else
    rdp_send_scancode(ev_time, (0x4000 | 0x8000), 0x36);
  }
 }
 if (((tr.modifiers & (1<<2))>0)
     != ((remote_modifier_state & (1<<2))>0))
 {
  if (((tr.modifiers & (1<<2))>0))
  {
   rdp_send_scancode(ev_time, 0, (0x80 | 0x38));
  }
  else
  {
   rdp_send_scancode(ev_time, (0x4000 | 0x8000), (0x80 | 0x38));
  }
 }
 if (((tr.modifiers & (1<<8))>0)
     != ((remote_modifier_state & (1<<8))>0))
 {
  unsigned short new_remote_state = 0;
  if (((tr.modifiers & (1<<8))>0))
  {
   ;
   new_remote_state |= 0x0002;
  }
  else
  {
   ;
  }
  rdp_send_input(0, RDP_INPUT_SYNCHRONIZE, 0, new_remote_state, 0);
  update_modifier_state(0x45, 1);
 }
}

variable_types: struct _key_translation { unsigned char scancode; unsigned short modifiers; }

return_type: void


decompiled_code:
time_t __fastcall reset_modifier_keys(unsigned int a1)
{
time_t result; // rax
unsigned int v2; // ebp

result = time(0LL);
v2 = result;
if ( (remote_modifier_state & 2) != 0 )
{
result = get_key_state(a1, 65505LL);
if ( !(_DWORD)result )
result = rdp_send_scancode(v2, 0xC000u, 0x2Au);
}
if ( (remote_modifier_state & 1) != 0 )
{
result = get_key_state(a1, 65506LL);
if ( !(_DWORD)result )
result = rdp_send_scancode(v2, 0xC000u, 0x36u);
}
if ( (remote_modifier_state & 0x20) != 0 )
{
result = get_key_state(a1, 65507LL);
if ( !(_DWORD)result )
result = rdp_send_scancode(v2, 0xC000u, 0x1Du);
}
if ( (remote_modifier_state & 0x10) != 0 )
{
result = get_key_state(a1, 65508LL);
if ( !(_DWORD)result )
result = rdp_send_scancode(v2, 0xC000u, 0x9Du);
}
if ( (remote_modifier_state & 8) != 0 )
{
result = get_key_state(a1, 65513LL);
if ( !(_DWORD)result )
result = rdp_send_scancode(v2, 0xC000u, 0x38u);
}
if ( (remote_modifier_state & 4) != 0 )
{
result = get_key_state(a1, 65514LL);
if ( !(_DWORD)result )
{
result = get_key_state(a1, 65406LL);
if ( !(_DWORD)result )
result = rdp_send_scancode(v2, 0xC000u, 0xB8u);
}
}
return result;
}

canonical_decompiled_code:
time_t __fastcall func10(unsigned int a1)
{
time_t result; // rax
unsigned int v2; // ebp

result = time(0LL);
v2 = result;
if ( (remote_modifier_state & 2) != 0 )
{
result = get_key_state(a1, 65505LL);
if ( !(_DWORD)result )
result = func7(v2, 0xC000u, 0x2Au);
}
if ( (remote_modifier_state & 1) != 0 )
{
result = get_key_state(a1, 65506LL);
if ( !(_DWORD)result )
result = func7(v2, 0xC000u, 0x36u);
}
if ( (remote_modifier_state & 0x20) != 0 )
{
result = get_key_state(a1, 65507LL);
if ( !(_DWORD)result )
result = func7(v2, 0xC000u, 0x1Du);
}
if ( (remote_modifier_state & 0x10) != 0 )
{
result = get_key_state(a1, 65508LL);
if ( !(_DWORD)result )
result = func7(v2, 0xC000u, 0x9Du);
}
if ( (remote_modifier_state & 8) != 0 )
{
result = get_key_state(a1, 65513LL);
if ( !(_DWORD)result )
result = func7(v2, 0xC000u, 0x38u);
}
if ( (remote_modifier_state & 4) != 0 )
{
result = get_key_state(a1, 65514LL);
if ( !(_DWORD)result )
{
result = get_key_state(a1, 65406LL);
if ( !(_DWORD)result )
result = func7(v2, 0xC000u, 0xB8u);
}
}
return result;
}

original_code:
void
reset_modifier_keys(unsigned int state)
{
 uint32 ev_time;
 ev_time = time(((void *)0));
 if (((remote_modifier_state & (1<<1))>0)
     && !get_key_state(state, 0xffe1))
  rdp_send_scancode(ev_time, (0x4000 | 0x8000), 0x2a);
 if (((remote_modifier_state & (1<<0))>0)
     && !get_key_state(state, 0xffe2))
  rdp_send_scancode(ev_time, (0x4000 | 0x8000), 0x36);
 if (((remote_modifier_state & (1<<5))>0)
     && !get_key_state(state, 0xffe3))
  rdp_send_scancode(ev_time, (0x4000 | 0x8000), 0x1d);
 if (((remote_modifier_state & (1<<4))>0)
     && !get_key_state(state, 0xffe4))
  rdp_send_scancode(ev_time, (0x4000 | 0x8000), (0x80 | 0x1d));
 if (((remote_modifier_state & (1<<3))>0) && !get_key_state(state, 0xffe9))
  rdp_send_scancode(ev_time, (0x4000 | 0x8000), 0x38);
 if (((remote_modifier_state & (1<<2))>0) &&
     !get_key_state(state, 0xffea) && !get_key_state(state, 0xff7e))
  rdp_send_scancode(ev_time, (0x4000 | 0x8000), (0x80 | 0x38));
}

canonical_original_code:
void reset_modifier_keys(unsigned int state)
{
 unsigned int ev_time;
 ev_time = time(((void *)0));
 if (((remote_modifier_state & (1<<1))>0)
     && !get_key_state(state, 0xffe1))
  rdp_send_scancode(ev_time, (0x4000 | 0x8000), 0x2a);
 if (((remote_modifier_state & (1<<0))>0)
     && !get_key_state(state, 0xffe2))
  rdp_send_scancode(ev_time, (0x4000 | 0x8000), 0x36);
 if (((remote_modifier_state & (1<<5))>0)
     && !get_key_state(state, 0xffe3))
  rdp_send_scancode(ev_time, (0x4000 | 0x8000), 0x1d);
 if (((remote_modifier_state & (1<<4))>0)
     && !get_key_state(state, 0xffe4))
  rdp_send_scancode(ev_time, (0x4000 | 0x8000), (0x80 | 0x1d));
 if (((remote_modifier_state & (1<<3))>0) && !get_key_state(state, 0xffe9))
  rdp_send_scancode(ev_time, (0x4000 | 0x8000), 0x38);
 if (((remote_modifier_state & (1<<2))>0) &&
     !get_key_state(state, 0xffea) && !get_key_state(state, 0xff7e))
  rdp_send_scancode(ev_time, (0x4000 | 0x8000), (0x80 | 0x38));
}


decompiled_code:
__int64 __fastcall cache_get_bitmap(unsigned __int8 a1, unsigned __int16 a2)
{
__int64 result; // rax

if ( a1 > 2u || a2 > 0x257u || (result = bmpcache[600 * a1 + a2]) == 0 )
{
error((int)"get bitmap %d:%d\n", a1, (const char *)a2);
result = 0LL;
}
return result;
}

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

if ( a1 > 2u || a2 > 0x257u || (result = bmpcache[600 * a1 + a2]) == 0 )
{
error((int)"get bitmap %d:%d\n", a1, (const char *)a2);
result = 0LL;
}
return result;
}

original_code:
HBITMAP
cache_get_bitmap(uint8 cache_id, uint16 cache_idx)
{
 HBITMAP bitmap;
 if ((cache_id < (sizeof(bmpcache) / sizeof(bmpcache[0]))) && (cache_idx < (sizeof(bmpcache[0]) / sizeof(bmpcache[0][0]))))
 {
  bitmap = bmpcache[cache_id][cache_idx];
  if (bitmap != ((void *)0))
   return bitmap;
 }
 error("get bitmap %d:%d\n", cache_id, cache_idx);
 return ((void *)0);
}

canonical_original_code:
void *cache_get_bitmap(unsigned char cache_id, unsigned short cache_idx)
{
 void *bitmap;
 if ((cache_id < (sizeof(bmpcache) / sizeof(bmpcache[0]))) && (cache_idx < (sizeof(bmpcache[0]) / sizeof(bmpcache[0][0]))))
 {
  bitmap = bmpcache[cache_id][cache_idx];
  if (bitmap != ((void *)0))
   return bitmap;
 }
 error("get bitmap %d:%d\n", cache_id, cache_idx);
 return ((void *)0);
}

variable_types:
bitmap
void *

return_type: void *


decompiled_code:
void __fastcall cache_put_bitmap(unsigned __int8 a1, unsigned __int16 a2, __int64 a3)
{
if ( a1 > 2u || a2 > 0x257u )
{
error((int)"put bitmap %d:%d\n", a1, (const char *)a2);
}
else
{
if ( bmpcache[600 * a1 + a2] )
ui_destroy_bitmap();
bmpcache[600 * a1 + a2] = a3;
}
}

canonical_decompiled_code:
void __fastcall func1(unsigned __int8 a1, unsigned __int16 a2, __int64 a3)
{
if ( a1 > 2u || a2 > 0x257u )
{
error((int)"put bitmap %d:%d\n", a1, (const char *)a2);
}
else
{
if ( bmpcache[600 * a1 + a2] )
ui_destroy_bitmap();
bmpcache[600 * a1 + a2] = a3;
}
}

original_code:
void
cache_put_bitmap(uint8 cache_id, uint16 cache_idx, HBITMAP bitmap)
{
 HBITMAP old;
 if ((cache_id < (sizeof(bmpcache) / sizeof(bmpcache[0]))) && (cache_idx < (sizeof(bmpcache[0]) / sizeof(bmpcache[0][0]))))
 {
  old = bmpcache[cache_id][cache_idx];
  if (old != ((void *)0))
   ui_destroy_bitmap(old);
  bmpcache[cache_id][cache_idx] = bitmap;
 }
 else
 {
  error("put bitmap %d:%d\n", cache_id, cache_idx);
 }
}

canonical_original_code:
void cache_put_bitmap(unsigned char cache_id, unsigned short cache_idx, void *bitmap)
{
 void *old;
 if ((cache_id < (sizeof(bmpcache) / sizeof(bmpcache[0]))) && (cache_idx < (sizeof(bmpcache[0]) / sizeof(bmpcache[0][0]))))
 {
  old = bmpcache[cache_id][cache_idx];
  if (old != ((void *)0))
   ui_destroy_bitmap(old);
  bmpcache[cache_id][cache_idx] = bitmap;
 }
 else
 {
  error("put bitmap %d:%d\n", cache_id, cache_idx);
 }
}

variable_types:
old
void *


decompiled_code:
void __fastcall cache_put_font(unsigned __int8 a1, unsigned __int16 a2, __int16 a3, __int16 a4, __int16 a5, __int16 a6, __int64 a7)
{
unsigned __int64 v11; // r15

if ( a1 > 0xBu || a2 > 0xFFu )
{
error((int)"put font %d:%d\n", a1, (const char *)a2);
}
else
{
if ( qword_E24C8[512 * (unsigned __int64)a1 + 2 * a2] )
ui_destroy_glyph();
v11 = 16 * (((unsigned __int64)a1 << 8) + a2);
fontcache[v11 / 2] = a3;
word_E24C2[v11 / 2] = a4;
word_E24C4[v11 / 2] = a5;
word_E24C6[v11 / 2] = a6;
qword_E24C8[v11 / 8] = a7;
}
}

canonical_decompiled_code:
void __fastcall func2(unsigned __int8 a1, unsigned __int16 a2, __int16 a3, __int16 a4, __int16 a5, __int16 a6, __int64 a7)
{
unsigned __int64 v11; // r15

if ( a1 > 0xBu || a2 > 0xFFu )
{
error((int)"put font %d:%d\n", a1, (const char *)a2);
}
else
{
if ( qword_E24C8[512 * (unsigned __int64)a1 + 2 * a2] )
ui_destroy_glyph();
v11 = 16 * (((unsigned __int64)a1 << 8) + a2);
fontcache[v11 / 2] = a3;
word_E24C2[v11 / 2] = a4;
word_E24C4[v11 / 2] = a5;
word_E24C6[v11 / 2] = a6;
qword_E24C8[v11 / 8] = a7;
}
}

original_code:
void
cache_put_font(uint8 font, uint16 character, uint16 offset,
        uint16 baseline, uint16 width, uint16 height, HGLYPH pixmap)
{
 FONTGLYPH *glyph;
 if ((font < (sizeof(fontcache) / sizeof(fontcache[0]))) && (character < (sizeof(fontcache[0]) / sizeof(fontcache[0][0]))))
 {
  glyph = &fontcache[font][character];
  if (glyph->pixmap != ((void *)0))
   ui_destroy_glyph(glyph->pixmap);
  glyph->offset = offset;
  glyph->baseline = baseline;
  glyph->width = width;
  glyph->height = height;
  glyph->pixmap = pixmap;
 }
 else
 {
  error("put font %d:%d\n", font, character);
 }
}

canonical_original_code:
void cache_put_font(unsigned char font, unsigned short character, unsigned short offset, unsigned short baseline, unsigned short width, unsigned short height, void *pixmap)
{
 struct _FONTGLYPH *glyph;
 if ((font < (sizeof(fontcache) / sizeof(fontcache[0]))) && (character < (sizeof(fontcache[0]) / sizeof(fontcache[0][0]))))
 {
  glyph = &fontcache[font][character];
  if (glyph->pixmap != ((void *)0))
   ui_destroy_glyph(glyph->pixmap);
  glyph->offset = offset;
  glyph->baseline = baseline;
  glyph->width = width;
  glyph->height = height;
  glyph->pixmap = pixmap;
 }
 else
 {
  error("put font %d:%d\n", font, character);
 }
}

variable_types:
font
unsigned char

variable_types:
character
unsigned short

variable_types:
offset
unsigned short

variable_types:
baseline
unsigned short

variable_types:
width
unsigned short

variable_types:
height
unsigned short

variable_types:
pixmap
void *

variable_types: struct _FONTGLYPH { short offset; short baseline; unsigned short width; unsigned short height; void *pixmap; } *


decompiled_code:
void *__fastcall cache_put_text(unsigned __int8 a1, const void *a2, int a3)
{
int v4; // ebp
void *v5; // rdi
unsigned __int64 v6; // rax

v4 = a1;
if ( textcache[2 * a1] )
xfree();
v5 = (void *)xmalloc((unsigned int)a3);
v6 = 4LL * v4;
textcache[v6 / 2] = (__int64)v5;
dword_E14C8[v6] = a3;
return memcpy(v5, a2, a3);
}

canonical_decompiled_code:
void *__fastcall func3(unsigned __int8 a1, const void *a2, int a3)
{
int v4; // ebp
void *v5; // rdi
unsigned __int64 v6; // rax

v4 = a1;
if ( textcache[2 * a1] )
xfree();
v5 = (void *)xmalloc((unsigned int)a3);
v6 = 4LL * v4;
textcache[v6 / 2] = (__int64)v5;
dword_E14C8[v6] = a3;
return memcpy(v5, a2, a3);
}

original_code:
void
cache_put_text(uint8 cache_id, void *data, int length)
{
 DATABLOB *text;
 if (cache_id < (sizeof(textcache) / sizeof(textcache[0])))
 {
  text = &textcache[cache_id];
  if (text->data != ((void *)0))
   xfree(text->data);
  text->data = xmalloc(length);
  text->size = length;
  memcpy(text->data, data, length);
 }
 else
 {
  error("put text %d\n", cache_id);
 }
}

canonical_original_code:
void cache_put_text(unsigned char cache_id, void *data, int length)
{
 struct _DATABLOB *text;
 if (cache_id < (sizeof(textcache) / sizeof(textcache[0])))
 {
  text = &textcache[cache_id];
  if (text->data != ((void *)0))
   xfree(text->data);
  text->data = xmalloc(length);
  text->size = length;
  memcpy(text->data, data, length);
 }
 else
 {
  error("put text %d\n", cache_id);
 }
}

variable_types:
data
void *

variable_types: length int

variable_types: struct _DATABLOB { void *data; int size; } *


decompiled_code:
__int64 __fastcall cache_get_desktop(int errnum, int a2, int a3, int a4)
{
const char *v4; // rdx

v4 = (const char *)(unsigned int)(a4 * a2 * a3);
if ( (int)v4 + errnum <= (unsigned int)&unk_E1000 )
return (__int64)&deskcache + (unsigned int)errnum;
error((int)"get desktop %d:%d\n", errnum, v4);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func4(int errnum, int a2, int a3, int a4)
{
const char *v4; // rdx

v4 = (const char *)(unsigned int)(a4 * a2 * a3);
if ( (int)v4 + errnum <= (unsigned int)&unk_E1000 )
return (__int64)&deskcache + (unsigned int)errnum;
error((int)"get desktop %d:%d\n", errnum, v4);
return 0LL;
}

original_code:
uint8 *
cache_get_desktop(uint32 offset, int cx, int cy, int bytes_per_pixel)
{
 int length = cx * cy * bytes_per_pixel;
 if ((offset + length) <= sizeof(deskcache))
 {
  return &deskcache[offset];
 }
 error("get desktop %d:%d\n", offset, length);
 return ((void *)0);
}

canonical_original_code:
unsigned char *cache_get_desktop(unsigned int offset, int cx, int cy, int bytes_per_pixel)
{
 int length = cx * cy * bytes_per_pixel;
 if ((offset + length) <= sizeof(deskcache))
 {
  return &deskcache[offset];
 }
 error("get desktop %d:%d\n", offset, length);
 return ((void *)0);
}

variable_types:
offset
unsigned int

variable_types: cx int

variable_types: cy int

return_type: unsigned char *


decompiled_code:
void __fastcall cache_put_desktop(int errnum, int a2, int a3, int a4, int a5, char *a6)
{
unsigned int v6; // ebx
unsigned int v8; // eax
int v10; // er13
int v11; // er12

v6 = errnum;
v8 = a5 * a3 * a2;
if ( v8 + errnum > (unsigned int)&unk_E1000 )
{
error((int)"put desktop %d:%d\n", errnum, (const char *)v8);
}
else
{
v10 = a5 * a2;
v11 = a3 - 1;
if ( a3 )
{
do
{
memcpy((char *)&deskcache + v6, a6, v10);
a6 += a4;
v6 += v10;
--v11;
}
while ( v11 != -1 );
}
}
}

canonical_decompiled_code:
void __fastcall func5(int errnum, int a2, int a3, int a4, int a5, char *a6)
{
unsigned int v6; // ebx
unsigned int v8; // eax
int v10; // er13
int v11; // er12

v6 = errnum;
v8 = a5 * a3 * a2;
if ( v8 + errnum > (unsigned int)&unk_E1000 )
{
error((int)"put desktop %d:%d\n", errnum, (const char *)v8);
}
else
{
v10 = a5 * a2;
v11 = a3 - 1;
if ( a3 )
{
do
{
memcpy((char *)&deskcache + v6, a6, v10);
a6 += a4;
v6 += v10;
--v11;
}
while ( v11 != -1 );
}
}
}

original_code:
void
cache_put_desktop(uint32 offset, int cx, int cy, int scanline, int bytes_per_pixel, uint8 * data)
{
 int length = cx * cy * bytes_per_pixel;
 if ((offset + length) <= sizeof(deskcache))
 {
  cx *= bytes_per_pixel;
  while (cy--)
  {
   memcpy(&deskcache[offset], data, cx);
   data += scanline;
   offset += cx;
  }
 }
 else
 {
  error("put desktop %d:%d\n", offset, length);
 }
}

canonical_original_code:
void cache_put_desktop(unsigned int offset, int cx, int cy, int scanline, int bytes_per_pixel, unsigned char *data)
{
 int length = cx * cy * bytes_per_pixel;
 if ((offset + length) <= sizeof(deskcache))
 {
  cx *= bytes_per_pixel;
  while (cy--)
  {
   memcpy(&deskcache[offset], data, cx);
   data += scanline;
   offset += cx;
  }
 }
 else
 {
  error("put desktop %d:%d\n", offset, length);
 }
}

variable_types: scanline int

variable_types:
data
unsigned char *


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

if ( a1 > 0x1Fu || (result = cursorcache[a1]) == 0 )
{
error((int)"get cursor %d\n", a1, a3);
result = 0LL;
}
return result;
}

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

if ( a1 > 0x1Fu || (result = cursorcache[a1]) == 0 )
{
error((int)"get cursor %d\n", a1, a3);
result = 0LL;
}
return result;
}

original_code:
HCURSOR
cache_get_cursor(uint16 cache_idx)
{
 HCURSOR cursor;
 if (cache_idx < (sizeof(cursorcache) / sizeof(cursorcache[0])))
 {
  cursor = cursorcache[cache_idx];
  if (cursor != ((void *)0))
   return cursor;
 }
 error("get cursor %d\n", cache_idx);
 return ((void *)0);
}

canonical_original_code:
void *cache_get_cursor(unsigned short cache_idx)
{
 void *cursor;
 if (cache_idx < (sizeof(cursorcache) / sizeof(cursorcache[0])))
 {
  cursor = cursorcache[cache_idx];
  if (cursor != ((void *)0))
   return cursor;
 }
 error("get cursor %d\n", cache_idx);
 return ((void *)0);
}

variable_types:
cursor
void *


decompiled_code:
void __fastcall cache_put_cursor(unsigned __int16 a1, __int64 a2, const char *a3)
{
if ( a1 > 0x1Fu )
{
error((int)"put cursor %d\n", a1, a3);
}
else
{
if ( cursorcache[a1] )
ui_destroy_cursor();
cursorcache[a1] = a2;
}
}

canonical_decompiled_code:
void __fastcall func7(unsigned __int16 a1, __int64 a2, const char *a3)
{
if ( a1 > 0x1Fu )
{
error((int)"put cursor %d\n", a1, a3);
}
else
{
if ( cursorcache[a1] )
ui_destroy_cursor();
cursorcache[a1] = a2;
}
}

original_code:
void
cache_put_cursor(uint16 cache_idx, HCURSOR cursor)
{
 HCURSOR old;
 if (cache_idx < (sizeof(cursorcache) / sizeof(cursorcache[0])))
 {
  old = cursorcache[cache_idx];
  if (old != ((void *)0))
   ui_destroy_cursor(old);
  cursorcache[cache_idx] = cursor;
 }
 else
 {
  error("put cursor %d\n", cache_idx);
 }
}

canonical_original_code:
void cache_put_cursor(unsigned short cache_idx, void *cursor)
{
 void *old;
 if (cache_idx < (sizeof(cursorcache) / sizeof(cursorcache[0])))
 {
  old = cursorcache[cache_idx];
  if (old != ((void *)0))
   ui_destroy_cursor(old);
  cursorcache[cache_idx] = cursor;
 }
 else
 {
  error("put cursor %d\n", cache_idx);
 }
}

variable_types:
old
void *


variable_types:
code
unsigned char

variable_types: struct stream { unsigned char *p; unsigned char *end; unsigned char *data; unsigned int size; unsigned char *iso_hdr; unsigned char *mcs_hdr; unsigned char *sec_hdr; unsigned char *rdp_hdr; } *


variable_types:
length
unsigned short

user_defined_types: struct stream { unsigned char *p; unsigned char *end; unsigned char *data; unsigned int size; unsigned char *iso_hdr; unsigned char *mcs_hdr; unsigned char *sec_hdr; unsigned char *rdp_hdr; }


decompiled_code:
__int64 *iso_recv()
{
__int64 *result; // rax
const char *v1; // rdx
char v2[9]; // [rsp+Fh] [rbp-9h] BYREF

result = iso_recv_msg(v2);
if ( result )
{
if ( v2[0] != -16 )
{
error((int)"expected DT, got 0x%x\n", (unsigned __int8)v2[0], v1);
result = 0LL;
}
}
return result;
}

canonical_decompiled_code:
__int64 *func2()
{
__int64 *result; // rax
const char *v1; // rdx
char v2[9]; // [rsp+Fh] [rbp-9h] BYREF

result = iso_recv_msg(v2);
if ( result )
{
if ( v2[0] != -16 )
{
error((int)"expected DT, got 0x%x\n", (unsigned __int8)v2[0], v1);
result = 0LL;
}
}
return result;
}

original_code:
STREAM
iso_recv(void)
{
 STREAM s;
 uint8 code;
 s = iso_recv_msg(&code);
 if (s == ((void *)0))
  return ((void *)0);
 if (code != ISO_PDU_DT)
 {
  error("expected DT, got 0x%x\n", code);
  return ((void *)0);
 }
 return s;
}

canonical_original_code:
struct stream *iso_recv()
{
 struct stream *s;
 unsigned char code;
 s = iso_recv_msg(&code);
 if (s == ((void *)0))
  return ((void *)0);
 if (code != ISO_PDU_DT)
 {
  error("expected DT, got 0x%x\n", code);
  return ((void *)0);
 }
 return s;
}

return_type: struct stream { unsigned char *p; unsigned char *end; unsigned char *data; unsigned int size; unsigned char *iso_hdr; unsigned char *mcs_hdr; unsigned char *sec_hdr; unsigned char *rdp_hdr; } *


decompiled_code:
__int64 iso_connect()
{
__int64 result; // rax
const char *v1; // rdx
char v2[9]; // [rsp+Fh] [rbp-9h] BYREF

result = tcp_connect();
if ( (_DWORD)result )
{
iso_send_msg(224);
if ( iso_recv_msg(v2) )
{
result = 1LL;
if ( v2[0] != -48 )
{
error((int)"expected CC, got 0x%x\n", (unsigned __int8)v2[0], v1);
tcp_disconnect();
result = 0LL;
}
}
else
{
result = 0LL;
}
}
return result;
}

canonical_decompiled_code:
__int64 func3()
{
__int64 result; // rax
const char *v1; // rdx
char v2[9]; // [rsp+Fh] [rbp-9h] BYREF

result = tcp_connect();
if ( (_DWORD)result )
{
func0(224);
if ( iso_recv_msg(v2) )
{
result = 1LL;
if ( v2[0] != -48 )
{
error((int)"expected CC, got 0x%x\n", (unsigned __int8)v2[0], v1);
tcp_disconnect();
result = 0LL;
}
}
else
{
result = 0LL;
}
}
return result;
}

original_code:
BOOL
iso_connect(char *server)
{
 uint8 code;
 if (!tcp_connect(server))
  return (0);
 iso_send_msg(ISO_PDU_CR);
 if (iso_recv_msg(&code) == ((void *)0))
  return (0);
 if (code != ISO_PDU_CC)
 {
  error("expected CC, got 0x%x\n", code);
  tcp_disconnect();
  return (0);
 }
 return (1);
}

canonical_original_code:
int iso_connect(char *server)
{
 unsigned char code;
 if (!tcp_connect(server))
  return (0);
 iso_send_msg(ISO_PDU_CR);
 if (iso_recv_msg(&code) == ((void *)0))
  return (0);
 if (code != ISO_PDU_CC)
 {
  error("expected CC, got 0x%x\n", code);
  tcp_disconnect();
  return (0);
 }
 return (1);
}

variable_types:
server
char *


decompiled_code:
__int64 iso_disconnect()
{
iso_send_msg(128);
return tcp_disconnect();
}

canonical_decompiled_code:
__int64 func4()
{
func0(128);
return tcp_disconnect();
}

original_code:
void
iso_disconnect(void)
{
 iso_send_msg(ISO_PDU_DR);
 tcp_disconnect();
}

canonical_original_code:
void iso_disconnect()
{
 iso_send_msg(ISO_PDU_DR);
 tcp_disconnect();
}


repo: zhangzewen/Algorithms

decompiled_code:
_QWORD *create_node()
{
_QWORD *v0; // rax
_QWORD *v1; // rbx
void *v2; // rax
_QWORD *v3; // rcx

v0 = malloc(0x10uLL);
v1 = v0;
if ( v0 )
{
*(_BYTE *)v0 = 0;
*((_DWORD *)v0 + 1) = 1;
v2 = malloc(0xD0uLL);
v1[1] = v2;
if ( !v2 )
free(v1);
v3 = (_QWORD *)v1[1];
*v3 = 0LL;
v3[25] = 0LL;
memset(
(void *)((unsigned __int64)(v3 + 1) & 0xFFFFFFFFFFFFFFF8LL),
0,
8LL * (((unsigned int)v3 - (((_DWORD)v3 + 8) & 0xFFFFFFF8) + 208) >> 3));
}
return v1;
}

canonical_decompiled_code:
_QWORD *func7()
{
_QWORD *v0; // rax
_QWORD *v1; // rbx
void *v2; // rax
_QWORD *v3; // rcx

v0 = malloc(0x10uLL);
v1 = v0;
if ( v0 )
{
*(_BYTE *)v0 = 0;
*((_DWORD *)v0 + 1) = 1;
v2 = malloc(0xD0uLL);
v1[1] = v2;
if ( !v2 )
free(v1);
v3 = (_QWORD *)v1[1];
*v3 = 0LL;
v3[25] = 0LL;
memset(
(void *)((unsigned __int64)(v3 + 1) & 0xFFFFFFFFFFFFFFF8LL),
0,
8LL * (((unsigned int)v3 - (((_DWORD)v3 + 8) & 0xFFFFFFF8) + 208) >> 3));
}
return v1;
}

original_code:
struct node* create_node()
{
    struct node* new = ((void *)0);
    new = (struct node*)malloc(sizeof(struct node));
    if (((void *)0) == new) {
        return ((void *)0);
    }
    new->ch = '\0';
    new->count = 1;
    new->child = (struct node**)malloc(sizeof(struct node**) * 26);
    if (((void *)0) == new->child) {
        free(new);
    }
    memset(new->child, 0, sizeof(struct node**) * 26);
    return new;
}

canonical_original_code:
struct node *create_node()
{
    struct node *new = ((void *)0);
    new = (struct node *)malloc(sizeof(struct node));
    if (((void *)0) == new) {
        return ((void *)0);
    }
    new->ch = '\0';
    new->count = 1;
    new->child = (struct node **)malloc(sizeof(struct node **) * 26);
    if (((void *)0) == new->child) {
        free(new);
    }
    memset(new->child, 0, sizeof(struct node **) * 26);
    return new;
}

variable_types: struct node { char ch; int count; struct node **child; } *


original_code:
void node_free(struct node** node)
{
    if (((void *)0) == *node) {
        return ;
    }
    int index = 0;
    for(index = 0; index < 26; index++) {
        if ((*node)->child[index]) {
            free((*node)->child[index]);
        }
    }
    free((*node)->child);
    free(*node);
    *node = ((void *)0);
}

canonical_original_code:
void node_free(struct node **node)
{
    if (((void *)0) == *node) {
        return ;
    }
    int index = 0;
    for(index = 0; index < 26; index++) {
        if ((*node)->child[index]) {
            free((*node)->child[index]);
        }
    }
    free((*node)->child);
    free(*node);
    *node = ((void *)0);
}

variable_types: struct node { char ch; int count; struct node **child; } **

variable_types: index int


addText

original_code:
int addText(struct node* root, char* str)
{
    if (((void *)0) == str) {
        return 0;
    }
    char* ptr = str;
    struct node* nodeptr = root;
    while(*ptr != '\0') {
        int index = 0;
        if ((97 <= *ptr && *ptr <= 122)) {
            index = *ptr - 97;
        } else {
            index = *ptr - 65;
        }
        if (((void *)0) == nodeptr->child[index]) {
            struct node* tmp = create_node();
            if (((void *)0) == tmp) {
                return -1;
            }
            tmp->ch = index + 97;
            nodeptr->child[index] = tmp;
        } else {
            nodeptr->child[index]->count++;
        }
        ptr++;
        nodeptr = nodeptr->child[index];
    }
    return 0;
}

canonical_original_code:
int addText(struct node *root, char *str)
{
    if (((void *)0) == str) {
        return 0;
    }
    char *ptr = str;
    struct node *nodeptr = root;
    while(*ptr != '\0') {
        int index = 0;
        if ((97 <= *ptr && *ptr <= 122)) {
            index = *ptr - 97;
        } else {
            index = *ptr - 65;
        }
        if (((void *)0) == nodeptr->child[index]) {
            struct node *tmp = create_node();
            if (((void *)0) == tmp) {
                return -1;
            }
            tmp->ch = index + 97;
            nodeptr->child[index] = tmp;
        } else {
            nodeptr->child[index]->count++;
        }
        ptr++;
        nodeptr = nodeptr->child[index];
    }
    return 0;
}

variable_types:
str
char *

variable_types:
ptr
char *

user_defined_types: struct node { char ch; int count; struct node **child; }


searchText

decompiled_code:
__int64 __fastcall searchText(__int64 a1, char *a2)
{
char v2; // al
int v4; // eax

if ( !a2 )
return 0LL;
v2 = *a2;
if ( !*a2 )
return *(unsigned int *)(a1 + 4);
while ( 1 )
{
v4 = (unsigned __int8)(v2 - 97) > 0x19u ? v2 - 65 : v2 - 97;
a1 = *(_QWORD *)(*(_QWORD *)(a1 + 8) + 8LL * v4);
if ( !a1 )
break;
v2 = *++a2;
if ( !*a2 )
return *(unsigned int *)(a1 + 4);
}
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func10(__int64 a1, char *a2)
{
char v2; // al
int v4; // eax

if ( !a2 )
return 0LL;
v2 = *a2;
if ( !*a2 )
return *(unsigned int *)(a1 + 4);
while ( 1 )
{
v4 = (unsigned __int8)(v2 - 97) > 0x19u ? v2 - 65 : v2 - 97;
a1 = *(_QWORD *)(*(_QWORD *)(a1 + 8) + 8LL * v4);
if ( !a1 )
break;
v2 = *++a2;
if ( !*a2 )
return *(unsigned int *)(a1 + 4);
}
return 0LL;
}

original_code:
int searchText(struct node* root, char* str)
{
    if (((void *)0) == str) {
        return 0;
    }
    char* ptr = str;
    struct node* nodeptr = root;
    while (*ptr != '\0') {
        int index = 0;
        if ((97 <= *ptr && *ptr <= 122)) {
            index = *ptr - 97;
        } else {
            index = *ptr - 65;
        }
        if (((void *)0) == nodeptr->child[index]) {
            return 0;
        }
        ptr++;
        nodeptr = nodeptr->child[index];
    }
    return nodeptr->count;
}

canonical_original_code:
int searchText(struct node *root, char *str)
{
    if (((void *)0) == str) {
        return 0;
    }
    char *ptr = str;
    struct node *nodeptr = root;
    while (*ptr != '\0') {
        int index = 0;
        if ((97 <= *ptr && *ptr <= 122)) {
            index = *ptr - 97;
        } else {
            index = *ptr - 65;
        }
        if (((void *)0) == nodeptr->child[index]) {
            return 0;
        }
        ptr++;
        nodeptr = nodeptr->child[index];
    }
    return nodeptr->count;
}


decompiled_code:
__int64 __fastcall Empty_List(__int64 a1)
{
return a1;
}

canonical_decompiled_code:
__int64 __fastcall func11(__int64 a1)
{
return a1;
}

original_code:
struct Linear_List *Empty_List(LinkList L)
{
  return L;
}

canonical_original_code:
struct Linear_List *Empty_List(struct Linear_List *L)
{
  return L;
}

variable_types:
L
struct Linear_List *

return_type: struct Linear_List { int num; struct Linear_List *next; } *


Print

decompiled_code:
int __fastcall Print(const void **a1)
{
const void **v1; // rbx
int result; // eax

v1 = a1;
if ( !a1 )
return puts("\n the Linear_List is empty!!");
do
{
result = printf("%p %d %p\n", v1, *(unsigned int *)v1, v1[1]);
v1 = (const void **)v1[1];
}
while ( v1 );
return result;
}

canonical_decompiled_code:
int __fastcall func7(const void **a1)
{
const void **v1; // rbx
int result; // eax

v1 = a1;
if ( !a1 )
return puts("\n the Linear_List is empty!!");
do
{
result = printf("%p %d %p\n", v1, *(unsigned int *)v1, v1[1]);
v1 = (const void **)v1[1];
}
while ( v1 );
return result;
}

original_code:
void Print(LinkList L)
{
  LinkList p;
    p=L;
    if(p!=((void *)0))
    {
      while(p!=((void *)0)){
            printf ("%p   %d    %p\n", p, p->num, p->next);
            p=p->next;
        };
    }
    else
    {
        printf("\n the Linear_List is empty!!\n");
    }
}

canonical_original_code:
void Print(struct Linear_List *L)
{
  struct Linear_List *p;
    p=L;
    if(p!=((void *)0))
    {
      while(p!=((void *)0)){
            printf ("%p   %d    %p\n", p, p->num, p->next);
            p=p->next;
        };
    }
    else
    {
        printf("\n the Linear_List is empty!!\n");
    }
}

variable_types: struct Linear_List { int num; struct Linear_List *next; } *


SortingList

decompiled_code:
__int64 __fastcall SortingList(__int64 a1, int a2)
{
int v3; // edi
int *v5; // rcx
__int64 v6; // rax
int v7; // edx

if ( a1 )
{
v3 = a2 - 1;
if ( a2 - 1 > 0 )
{
do
{
v6 = *(_QWORD *)(a1 + 8);
if ( v6 )
{
v5 = (int *)a1;
while ( 1 )
{
v7 = *v5;
if ( *v5 >= *(_DWORD *)v6 )
{
*v5 = *(_DWORD *)v6;
*(_DWORD *)v6 = v7;
}
v5 = (int *)v6;
if ( !*(_QWORD *)(v6 + 8) )
break;
v6 = *(_QWORD *)(v6 + 8);
}
}
--v3;
}
while ( v3 );
}
}
else
{
printf(" It's a empty Linear List!Can not be sorted!");
}
return a1;
}

canonical_decompiled_code:
__int64 __fastcall func8(__int64 a1, int a2)
{
int v3; // edi
int *v5; // rcx
__int64 v6; // rax
int v7; // edx

if ( a1 )
{
v3 = a2 - 1;
if ( a2 - 1 > 0 )
{
do
{
v6 = *(_QWORD *)(a1 + 8);
if ( v6 )
{
v5 = (int *)a1;
while ( 1 )
{
v7 = *v5;
if ( *v5 >= *(_DWORD *)v6 )
{
*v5 = *(_DWORD *)v6;
*(_DWORD *)v6 = v7;
}
v5 = (int *)v6;
if ( !*(_QWORD *)(v6 + 8) )
break;
v6 = *(_QWORD *)(v6 + 8);
}
}
--v3;
}
while ( v3 );
}
}
else
{
printf(" It's a empty Linear List!Can not be sorted!");
}
return a1;
}

original_code:
struct Linear_List *SortingList(LinkList L, int length)
{
  int outer=0;
  int midvalue=0;
    LinkList p1=((void *)0);
    LinkList p2=((void *)0);
    if(L==((void *)0))
    {
            printf(" It's a  empty Linear List!Can not be sorted!");
            return ((void *)0) ;
    }
    else
    {
        for(outer=length-1;outer>=1;outer--)
        {
             p1=L;
             p2=L->next;
            while(p2!=((void *)0))
            {
                if(p1->num>=p2->num)
                   {
                       midvalue=p1->num;
                       p1->num=p2->num;
                       p2->num=midvalue;
                   }
                   p1=p2;
                   p2=p2->next;
            };
        }
    }
    return L;
}

canonical_original_code:
struct Linear_List *SortingList(struct Linear_List *L, int length)
{
  int outer = 0;
  int midvalue = 0;
    struct Linear_List *p1 = ((void *)0);
    struct Linear_List *p2 = ((void *)0);
    if(L==((void *)0))
    {
            printf(" It's a  empty Linear List!Can not be sorted!");
            return ((void *)0) ;
    }
    else
    {
        for(outer=length-1;outer>=1;outer--)
        {
             p1=L;
             p2=L->next;
            while(p2!=((void *)0))
            {
                if(p1->num>=p2->num)
                   {
                       midvalue=p1->num;
                       p1->num=p2->num;
                       p2->num=midvalue;
                   }
                   p1=p2;
                   p2=p2->next;
            };
        }
    }
    return L;
}

variable_types: length int

variable_types: outer int

variable_types: midvalue int

user_defined_types: struct Linear_List { int num; struct Linear_List *next; }


original_code:
struct Linear_List *Add_Node_List(LinkList L,struct Linear_List *Node)
{
    LinkList p1=((void *)0);
  LinkList p_front=((void *)0);
    if(L==((void *)0))
    {
        L=Node;
        Node->next=((void *)0);
    }
    p1=L;
    while(p1->num<Node->num&&p1->next!=((void *)0))
    {
    p_front=p1;
        p1=p1->next;
    }
    if(p1->next==((void *)0))
    {
        p1->next=Node;
        Node->next=((void *)0);
    }
    else if(p1->num>=Node->num)
    {
    p_front->next = Node;
    Node->next = p1;
    }
    else
    {
        printf("\n %d can not insert into the Linear_List!\n");
    }
   return L;
}

canonical_original_code:
struct Linear_List *Add_Node_List(struct Linear_List *L, struct Linear_List *Node)
{
    struct Linear_List *p1 = ((void *)0);
  struct Linear_List *p_front = ((void *)0);
    if(L==((void *)0))
    {
        L=Node;
        Node->next=((void *)0);
    }
    p1=L;
    while(p1->num<Node->num&&p1->next!=((void *)0))
    {
    p_front=p1;
        p1=p1->next;
    }
    if(p1->next==((void *)0))
    {
        p1->next=Node;
        Node->next=((void *)0);
    }
    else if(p1->num>=Node->num)
    {
    p_front->next = Node;
    Node->next = p1;
    }
    else
    {
        printf("\n %d can not insert into the Linear_List!\n");
    }
   return L;
}

variable_types:
Node
struct Linear_List *


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

if ( !a1 )
return 0LL;
LODWORD(result) = 0;
do
{
result = (unsigned int)(result + 1);
a1 = *(_QWORD *)(a1 + 8);
}
while ( a1 );
return result;
}

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

if ( !a1 )
return 0LL;
LODWORD(result) = 0;
do
{
result = (unsigned int)(result + 1);
a1 = *(_QWORD *)(a1 + 8);
}
while ( a1 );
return result;
}

original_code:
int Linear_List_Length(LinkList L)
{
    int length=0;
    LinkList p=((void *)0);
    p=L;
   while(p!=((void *)0)){
           length++;
            p=p->next;
        };
    return length;
}

canonical_original_code:
int Linear_List_Length(struct Linear_List *L)
{
    int length = 0;
    struct Linear_List *p = ((void *)0);
    p=L;
   while(p!=((void *)0)){
           length++;
            p=p->next;
        };
    return length;
}


SortingDList

decompiled_code:
__int64 __fastcall SortingDList(__int64 a1, int a2)
{
int v3; // edi
int *v5; // rcx
__int64 v6; // rax
int v7; // edx

if ( a1 )
{
v3 = a2;
if ( a2 > 0 )
{
do
{
v6 = *(_QWORD *)(a1 + 8);
if ( a1 != v6 )
{
v5 = (int *)a1;
while ( 1 )
{
v7 = *v5;
if ( *v5 >= *(_DWORD *)v6 )
{
*v5 = *(_DWORD *)v6;
*(_DWORD *)v6 = v7;
}
v5 = (int *)v6;
if ( a1 == *(_QWORD *)(v6 + 8) )
break;
v6 = *(_QWORD *)(v6 + 8);
}
}
--v3;
}
while ( v3 );
}
}
else
{
printf(" It's a empty Linear List!Can not be sorted!");
}
return a1;
}

canonical_decompiled_code:
__int64 __fastcall func9(__int64 a1, int a2)
{
int v3; // edi
int *v5; // rcx
__int64 v6; // rax
int v7; // edx

if ( a1 )
{
v3 = a2;
if ( a2 > 0 )
{
do
{
v6 = *(_QWORD *)(a1 + 8);
if ( a1 != v6 )
{
v5 = (int *)a1;
while ( 1 )
{
v7 = *v5;
if ( *v5 >= *(_DWORD *)v6 )
{
*v5 = *(_DWORD *)v6;
*(_DWORD *)v6 = v7;
}
v5 = (int *)v6;
if ( a1 == *(_QWORD *)(v6 + 8) )
break;
v6 = *(_QWORD *)(v6 + 8);
}
}
--v3;
}
while ( v3 );
}
}
else
{
printf(" It's a empty Linear List!Can not be sorted!");
}
return a1;
}

original_code:
struct DLinear_List *SortingDList(DLinkList L ,int length)
{
  int outer=0;
   int midvalue=0;
    DLinkList p1=((void *)0);
    DLinkList p2=((void *)0);
    if(L==((void *)0))
    {
            printf(" It's a  empty Linear List!Can not be sorted!");
            return ((void *)0) ;
    }
    else
    {
        for(outer=length;outer>0;outer--)
        {
             p1=L;
             p2=L->next;
            while(p2!=L)
            {
                if(p1->num>=p2->num)
                   {
                       midvalue=p1->num;
                       p1->num=p2->num;
                       p2->num=midvalue;
                   }
                   p1=p2;
                   p2=p2->next;
            };
        }
    }
    return L;
}

canonical_original_code:
struct DLinear_List *SortingDList(struct DLinear_List *L, int length)
{
  int outer = 0;
   int midvalue = 0;
    struct DLinear_List *p1 = ((void *)0);
    struct DLinear_List *p2 = ((void *)0);
    if(L==((void *)0))
    {
            printf(" It's a  empty Linear List!Can not be sorted!");
            return ((void *)0) ;
    }
    else
    {
        for(outer=length;outer>0;outer--)
        {
             p1=L;
             p2=L->next;
            while(p2!=L)
            {
                if(p1->num>=p2->num)
                   {
                       midvalue=p1->num;
                       p1->num=p2->num;
                       p2->num=midvalue;
                   }
                   p1=p2;
                   p2=p2->next;
            };
        }
    }
    return L;
}

variable_types:
L
struct DLinear_List *

variable_types: struct DLinear_List { int num; struct DLinear_List *next; } *


decompiled_code:
__int64 __fastcall DLinear_List_Length(__int64 a1)
{
__int64 v1; // rax
int i; // edx
__int64 result; // rax

if ( a1 )
{
v1 = *(_QWORD *)(a1 + 8);
for ( i = 0; v1 != a1; v1 = *(_QWORD *)(v1 + 8) )
++i;
result = (unsigned int)(i + 1);
}
else
{
puts("\nIt's an empty DLinkList!");
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func10(__int64 a1)
{
__int64 v1; // rax
int i; // edx
__int64 result; // rax

if ( a1 )
{
v1 = *(_QWORD *)(a1 + 8);
for ( i = 0; v1 != a1; v1 = *(_QWORD *)(v1 + 8) )
++i;
result = (unsigned int)(i + 1);
}
else
{
puts("\nIt's an empty DLinkList!");
result = 0LL;
}
return result;
}

original_code:
int DLinear_List_Length(DLinkList L)
{
 int length=0;
 DLinkList p;
 if(((void *)0)==L)
 {
  printf("\nIt's an empty DLinkList!\n");
  return 0;
 }
 p =L;
 while(p->next!= L)
 {
  length++;
  p=p->next;
 }
 return length+1;
}

canonical_original_code:
int DLinear_List_Length(struct DLinear_List *L)
{
 int length = 0;
 struct DLinear_List *p;
 if(((void *)0)==L)
 {
  printf("\nIt's an empty DLinkList!\n");
  return 0;
 }
 p =L;
 while(p->next!= L)
 {
  length++;
  p=p->next;
 }
 return length+1;
}

user_defined_types: struct DLinear_List { int num; struct DLinear_List *next; }


original_code:
struct DLinear_List *Add_Node_DList(DLinkList L ,struct DLinear_List *Node)
{
 DLinkList p;
 if(((void *)0) == L)
 {
   L=Node;
   L->next=L;
   L->before =L;
 }
 p = L->next;
 while(p != L && p->num <= Node->num)
 {
   printf("Add_Node_DList[%d]\n",181);
    p=p->next;
   printf("Add_Node_DList[%d]\n",183);
 }
 if(p == L)
 {
  Node->next = L;
  Node->before = L->before;
  L->before->next = Node;
  L->before = Node;
 }
 else if(p->num > Node->num)
 {
  printf("Add_Node_DList[%d]\n",194);
  Node->next = p;
  Node->before = p->before;
  p->before->next = Node;
  p->before = Node;
  printf("Add_Node_DList[%d]\n",199);
 }
 else
 {
  printf("\nCan not add the %d to the DList!\n",Node->num);
 }
 return L;
}

canonical_original_code:
struct DLinear_List *Add_Node_DList(struct DLinear_List *L, struct DLinear_List *Node)
{
 struct DLinear_List *p;
 if(((void *)0) == L)
 {
   L=Node;
   L->next=L;
   L->before =L;
 }
 p = L->next;
 while(p != L && p->num <= Node->num)
 {
   printf("Add_Node_DList[%d]\n",181);
    p=p->next;
   printf("Add_Node_DList[%d]\n",183);
 }
 if(p == L)
 {
  Node->next = L;
  Node->before = L->before;
  L->before->next = Node;
  L->before = Node;
 }
 else if(p->num > Node->num)
 {
  printf("Add_Node_DList[%d]\n",194);
  Node->next = p;
  Node->before = p->before;
  p->before->next = Node;
  p->before = Node;
  printf("Add_Node_DList[%d]\n",199);
 }
 else
 {
  printf("\nCan not add the %d to the DList!\n",Node->num);
 }
 return L;
}

variable_types:
Node
struct DLinear_List *

return_type: struct DLinear_List { int num; struct DLinear_List *next; } *


decompiled_code:
void __fastcall Destory_DList(void **a1)
{
_QWORD *v1; // rbx
_QWORD *v2; // rax
_QWORD *v3; // [rsp+8h] [rbp-20h] BYREF

v1 = *a1;
if ( *a1 )
{
while ( v1 != (_QWORD *)v1[1] )
{
v3 = v1;
v2 = (_QWORD *)v1[1];
if ( v1 != v2 )
{
do
{
printf("Destory_DList[%d]\n", 236LL);
v2 = (_QWORD *)v3[1];
v3 = v2;
}
while ( v1 != (_QWORD *)v2[1] );
}
*(_QWORD *)(v2[2] + 8LL) = v1;
v1[2] = v2[2];
v2[1] = v2;
v2[2] = v2;
Destory_Memory((void **)&v3);
}
Destory_Memory(a1);
}
else
{
puts("this is an empty list!");
}
}

original_code:
void Destory_DList(DLinkList *L)
{
  DLinkList p_head,p_current,p_front;
  if(*L == ((void *)0))
  {
    printf("this is an empty list!\n");
    return ;
  }
  p_head = *L;
  while(p_head->next != p_head)
  {
    for(p_current = p_head; p_current->next != p_head; p_current = p_current->next)
    {
     printf("Destory_DList[%d]\n",236);
    }
    p_current->before->next = p_head;
    p_head->before = p_current->before;
    p_current->next = p_current;
    p_current->before = p_current;
    Destory_Memory((void **)&p_current);
  }
  Destory_Memory((void **)L);
}

canonical_original_code:
void Destory_DList(struct DLinear_List **L)
{
  struct DLinear_List *p_head; struct DLinear_List *p_current; struct DLinear_List *p_front;
  if(*L == ((void *)0))
  {
    printf("this is an empty list!\n");
    return ;
  }
  p_head = *L;
  while(p_head->next != p_head)
  {
    for(p_current = p_head; p_current->next != p_head; p_current = p_current->next)
    {
     printf("Destory_DList[%d]\n",236);
    }
    p_current->before->next = p_head;
    p_head->before = p_current->before;
    p_current->next = p_current;
    p_current->before = p_current;
    Destory_Memory((void **)&p_current);
  }
  Destory_Memory((void **)L);
}

variable_types: struct DLinear_List { int num; struct DLinear_List *next; } **


decompiled_code:
__int64 __fastcall SortingDList(__int64 a1, int a2)
{
int v3; // edi
int *v5; // rcx
__int64 v6; // rax
int v7; // edx

if ( a1 )
{
v3 = a2 - 1;
if ( a2 - 1 > 0 )
{
do
{
v6 = *(_QWORD *)(a1 + 8);
if ( a1 != *(_QWORD *)(v6 + 8) )
{
v5 = (int *)a1;
while ( 1 )
{
v7 = *v5;
if ( *v5 >= *(_DWORD *)v6 )
{
*v5 = *(_DWORD *)v6;
*(_DWORD *)v6 = v7;
}
v5 = (int *)v6;
if ( *(_QWORD *)(*(_QWORD *)(v6 + 8) + 8LL) == a1 )
break;
v6 = *(_QWORD *)(v6 + 8);
}
}
--v3;
}
while ( v3 );
}
}
else
{
printf(" It's a empty Linear List!Can not be sorted!");
}
return a1;
}


decompiled_code:
__int64 __fastcall DLinear_List_Length(__int64 a1)
{
__int64 v1; // rax
unsigned int v2; // edx
__int64 result; // rax

v2 = 0;
if ( a1 )
{
do
{
++v2;
v1 = *(_QWORD *)(v1 + 8);
}
while ( *(_QWORD *)(v1 + 8) != a1 );
result = v2;
}
else
{
puts("\nIt's an empty DLinkList!");
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func10(__int64 a1)
{
__int64 v1; // rax
unsigned int v2; // edx
__int64 result; // rax

v2 = 0;
if ( a1 )
{
do
{
++v2;
v1 = *(_QWORD *)(v1 + 8);
}
while ( *(_QWORD *)(v1 + 8) != a1 );
result = v2;
}
else
{
puts("\nIt's an empty DLinkList!");
result = 0LL;
}
return result;
}


Print

decompiled_code:
int __fastcall Print(const void **a1)
{
const void **v1; // rbx

v1 = a1;
if ( !a1 )
{
puts("\nIt is an empty Dlinkedlist!");
exit(0);
}
do
{
printf("%p\t\t%p\t\t%d\t\t%p\n", v1[2], v1, *(unsigned int *)v1, v1[1]);
v1 = (const void **)v1[1];
}
while ( v1[1] != a1 );
return printf("%p\t\t%p\t\t%d\t\t%p\n", v1[2], v1, *(unsigned int *)v1, a1);
}

canonical_decompiled_code:
int __fastcall func8(const void **a1)
{
const void **v1; // rbx

v1 = a1;
if ( !a1 )
{
puts("\nIt is an empty Dlinkedlist!");
exit(0);
}
do
{
printf("%p\t\t%p\t\t%d\t\t%p\n", v1[2], v1, *(unsigned int *)v1, v1[1]);
v1 = (const void **)v1[1];
}
while ( v1[1] != a1 );
return printf("%p\t\t%p\t\t%d\t\t%p\n", v1[2], v1, *(unsigned int *)v1, a1);
}

original_code:
void Print(DLinkList L)
{
 DLinkList p;
 if(((void *)0)== L)
 {
  printf("\nIt is an empty Dlinkedlist!\n");
  exit(0);
 }
 else
 {
  p=L;
  while(p)
  {
   printf("%p		%p		%d		%p\n",p->before,p,p->num,p->next);
   p=p->next;
   if(p->next==L)
   {
    printf("%p		%p		%d		%p\n",p->before,p,p->num,p->next);
    break;
    }
  }
 }
}

canonical_original_code:
void Print(struct DLinear_List *L)
{
 struct DLinear_List *p;
 if(((void *)0)== L)
 {
  printf("\nIt is an empty Dlinkedlist!\n");
  exit(0);
 }
 else
 {
  p=L;
  while(p)
  {
   printf("%p		%p		%d		%p\n",p->before,p,p->num,p->next);
   p=p->next;
   if(p->next==L)
   {
    printf("%p		%p		%d		%p\n",p->before,p,p->num,p->next);
    break;
    }
  }
 }
}


decompiled_code:
__int64 __fastcall Create_List_Head(__int64 a1)
{
__int64 v1; // rax
__int64 result; // rax
int v3; // [rsp+4h] [rbp-14h] BYREF
__int64 v4; // [rsp+8h] [rbp-10h] BYREF

_isoc99_scanf(&unk_382, a1);
while ( 1 )
{
result = _isoc99_scanf(&unk_382, &v3);
if ( v3 < 0 )
break;
Init_Node(&v4);
*(_DWORD *)v4 = v3;
v1 = v4;
*(_QWORD *)(v4 + 8) = *(_QWORD *)(a1 + 8);
*(_QWORD *)(a1 + 8) = v1;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1)
{
__int64 v1; // rax
__int64 result; // rax
int v3; // [rsp+4h] [rbp-14h] BYREF
__int64 v4; // [rsp+8h] [rbp-10h] BYREF

_isoc99_scanf(&unk_382, a1);
while ( 1 )
{
result = _isoc99_scanf(&unk_382, &v3);
if ( v3 < 0 )
break;
Init_Node(&v4);
*(_DWORD *)v4 = v3;
v1 = v4;
*(_QWORD *)(v4 + 8) = *(_QWORD *)(a1 + 8);
*(_QWORD *)(a1 + 8) = v1;
}
return result;
}

original_code:
void Create_List_Head(LinkList phead)
{
 LinkList pnew;
 int data;
 scanf("%d",&phead->num);
 while(1)
 {
  scanf("%d",&data);
  if(data>=0)
  {
   Init_Node(&pnew);
   pnew->num=data;
   pnew->next = phead->next;
   phead->next = pnew;
  }
  else
  {
   break;
  }
 }
}

canonical_original_code:
void Create_List_Head(struct Linear_List *phead)
{
 struct Linear_List *pnew;
 int data;
 scanf("%d",&phead->num);
 while(1)
 {
  scanf("%d",&data);
  if(data>=0)
  {
   Init_Node(&pnew);
   pnew->num=data;
   pnew->next = phead->next;
   phead->next = pnew;
  }
  else
  {
   break;
  }
 }
}

variable_types: data int


canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1)
{
return a1;
}


visit

decompiled_code:
int __fastcall visit(unsigned int *a1)
{
return printf("%4d", *a1);
}

canonical_decompiled_code:
int __fastcall func8(unsigned int *a1)
{
return printf("%4d", *a1);
}

original_code:
void visit(const char data)
{
    printf("%c ",data);
}

canonical_original_code:
void visit(char data)
{
    printf("%c ",data);
}

variable_types: data char


decompiled_code:
int __fastcall visit(char a1)
{
return printf("%c ", (unsigned int)a1);
}

canonical_decompiled_code:
int __fastcall func2(char a1)
{
return printf("%c ", (unsigned int)a1);
}


decompiled_code:
__int64 __fastcall Create_List_Head(__int64 a1)
{
__int64 v1; // rax
__int64 result; // rax
int v3; // [rsp+4h] [rbp-14h]
__int64 v4; // [rsp+8h] [rbp-10h] BYREF

__isoc99_scanf();
while ( 1 )
{
result = __isoc99_scanf();
if ( v3 < 0 )
break;
Init_Node(&v4);
*(_DWORD *)v4 = v3;
v1 = v4;
*(_QWORD *)(v4 + 8) = *(_QWORD *)(a1 + 8);
*(_QWORD *)(a1 + 8) = v1;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func9(__int64 a1)
{
__int64 v1; // rax
__int64 result; // rax
int v3; // [rsp+4h] [rbp-14h]
__int64 v4; // [rsp+8h] [rbp-10h] BYREF

__isoc99_scanf();
while ( 1 )
{
result = __isoc99_scanf();
if ( v3 < 0 )
break;
Init_Node(&v4);
*(_DWORD *)v4 = v3;
v1 = v4;
*(_QWORD *)(v4 + 8) = *(_QWORD *)(a1 + 8);
*(_QWORD *)(a1 + 8) = v1;
}
return result;
}


canonical_decompiled_code:
int __fastcall func7(unsigned int *a1)
{
return printf("%4d", *a1);
}


repo: zhaoyao/lua-amf

decompiled_code:
void __fastcall amf_cursor_free(void *a1)
{
free(a1);
}

canonical_decompiled_code:
void __fastcall func0(void *a1)
{
free(a1);
}

original_code:
void
amf_cursor_free(amf_cursor *cur)
{
    free(cur);
}

canonical_original_code:
void amf_cursor_free(struct amf_cursor *cur)
{
    free(cur);
}

variable_types: struct amf_cursor { char *p; unsigned long left; int err; char *err_msg; } *


decompiled_code:
void *__fastcall amf_cursor_read_u8(unsigned __int8 **a1, _BYTE *a2)
{
void *result; // rax

if ( a1[1] )
{
result = (void *)**a1;
*a2 = (_BYTE)result;
++*a1;
--a1[1];
}
else
{
*((_DWORD *)a1 + 4) = 1;
result = &LC0;
a1[3] = (unsigned __int8 *)&LC0;
}
return result;
}

canonical_decompiled_code:
void *__fastcall func1(unsigned __int8 **a1, _BYTE *a2)
{
void *result; // rax

if ( a1[1] )
{
result = (void *)**a1;
*a2 = (_BYTE)result;
++*a1;
--a1[1];
}
else
{
*((_DWORD *)a1 + 4) = 1;
result = &LC0;
a1[3] = (unsigned __int8 *)&LC0;
}
return result;
}

original_code:
void
amf_cursor_read_u8(amf_cursor *c, uint8_t *i)
{
    do { if (c->left < 1) { c->err = 1; c->err_msg = "eof"; return; } } while(0);
    *i = (c->p[0] & 0xff);
    do { c->p += 1; c->left -= 1; } while(0);
}

canonical_original_code:
void amf_cursor_read_u8(struct amf_cursor *c, unsigned char *i)
{
    do { if (c->left < 1) { c->err = 1; c->err_msg = "eof"; return; } } while(0);
    *i = (c->p[0] & 0xff);
    do { c->p += 1; c->left -= 1; } while(0);
}

variable_types:
i
unsigned char *

user_defined_types: struct amf_cursor { char *p; unsigned long left; int err; char *err_msg; }


decompiled_code:
void *__fastcall amf_cursor_read_u16(char **a1, _WORD *a2)
{
void *result; // rax

if ( (unsigned __int64)a1[1] <= 1 )
{
*((_DWORD *)a1 + 4) = 1;
result = &LC0;
a1[3] = (char *)&LC0;
}
else
{
result = (void *)((**a1 << 8) | (unsigned int)(unsigned __int8)(*a1)[1]);
*a2 = (**a1 << 8) | (unsigned __int8)(*a1)[1];
*a1 += 2;
a1[1] -= 2;
}
return result;
}

canonical_decompiled_code:
void *__fastcall func2(char **a1, _WORD *a2)
{
void *result; // rax

if ( (unsigned __int64)a1[1] <= 1 )
{
*((_DWORD *)a1 + 4) = 1;
result = &LC0;
a1[3] = (char *)&LC0;
}
else
{
result = (void *)((**a1 << 8) | (unsigned int)(unsigned __int8)(*a1)[1]);
*a2 = (**a1 << 8) | (unsigned __int8)(*a1)[1];
*a1 += 2;
a1[1] -= 2;
}
return result;
}

original_code:
void
amf_cursor_read_u16(amf_cursor *c, uint16_t *i)
{
    do { if (c->left < 2) { c->err = 1; c->err_msg = "eof"; return; } } while(0);
    *i = ((c->p[0] & 0xff) << 8 | (c->p[1] & 0xff));
    do { c->p += 2; c->left -= 2; } while(0);
}

canonical_original_code:
void amf_cursor_read_u16(struct amf_cursor *c, unsigned short *i)
{
    do { if (c->left < 2) { c->err = 1; c->err_msg = "eof"; return; } } while(0);
    *i = ((c->p[0] & 0xff) << 8 | (c->p[1] & 0xff));
    do { c->p += 2; c->left -= 2; } while(0);
}

variable_types:
i
unsigned short *


decompiled_code:
void *__fastcall amf_cursor_read_u32(char **a1, _DWORD *a2)
{
void *result; // rax

if ( (unsigned __int64)a1[1] <= 3 )
{
*((_DWORD *)a1 + 4) = 1;
result = &LC0;
a1[3] = (char *)&LC0;
}
else
{
result = (void *)((unsigned __int16)((*a1)[2] << 8) | ((*a1)[1] << 16) & 0xFF0000 | (unsigned __int8)(*a1)[3] | (unsigned int)(**a1 << 24));
*a2 = (_DWORD)result;
*a1 += 4;
a1[1] -= 4;
}
return result;
}

variable_types:
i
unsigned int *


original_code:
void
amf_cursor_read_u29(amf_cursor *c, unsigned int *i)
{
    int ofs = 0, res = 0, tmp;
    do {
        do { if (c->left < 1) { c->err = 1; c->err_msg = "eof"; return; } } while(0);
        tmp = c->p[0];
        if (ofs == 3) {
            res <<= 8;
            res |= tmp & 0xff;
        } else {
            res <<= 7;
            res |= tmp & 0x7f;
        }
        do { c->p += 1; c->left -= 1; } while(0);
    } while ((++ofs < 4) && (tmp & 0x80));
 if(i != ((void *)0))
  *i = res;
}

canonical_original_code:
void amf_cursor_read_u29(struct amf_cursor *c, unsigned int *i)
{
    int ofs = 0; int res = 0; int tmp;
    do {
        do { if (c->left < 1) { c->err = 1; c->err_msg = "eof"; return; } } while(0);
        tmp = c->p[0];
        if (ofs == 3) {
            res <<= 8;
            res |= tmp & 0xff;
        } else {
            res <<= 7;
            res |= tmp & 0x7f;
        }
        do { c->p += 1; c->left -= 1; } while(0);
    } while ((++ofs < 4) && (tmp & 0x80));
 if(i != ((void *)0))
  *i = res;
}

variable_types: ofs int

variable_types: res int

variable_types: tmp int


decompiled_code:
void *__fastcall amf_buf_append(__int64 a1, const void *a2, size_t a3)
{
void *result; // rax
size_t v5; // r13

if ( *(_QWORD *)(a1 + 16) < a3 )
{
v5 = *(_QWORD *)(a1 + 8) + a3;
*(_QWORD *)a1 = realloc(*(void **)a1, 2 * v5);
*(_QWORD *)(a1 + 16) = v5;
}
result = memcpy((void *)(*(_QWORD *)a1 + *(_QWORD *)(a1 + 8)), a2, a3);
*(_QWORD *)(a1 + 8) += a3;
*(_QWORD *)(a1 + 16) -= a3;
return result;
}

original_code:
void
amf_buf_append(amf_buf *buf, const char *b, size_t len)
{
    if (buf->free < len) {
        size_t nlen = buf->len + len;
        buf->b = realloc(buf->b, nlen * 2);
        buf->free = nlen;
    }
    memcpy(buf->b + buf->len, b, len);
    buf->len += len;
    buf->free -= len;
}

canonical_original_code:
void amf_buf_append(struct amf_buf *buf, char *b, unsigned long len)
{
    if (buf->free < len) {
        unsigned long nlen = buf->len + len;
        buf->b = realloc(buf->b, nlen * 2);
        buf->free = nlen;
    }
    memcpy(buf->b + buf->len, b, len);
    buf->len += len;
    buf->free -= len;
}

variable_types: struct amf_buf { char *b; unsigned long len; void *(*alloc)(void *ud, void *ptr, unsigned long osize, unsigned long nsize); } *

variable_types:
b
char *

variable_types:
len
unsigned long

variable_types:
nlen
unsigned long


decompiled_code:
void __fastcall amf_buf_free(void *ptr)
{
free(*(void **)ptr);
free(ptr);
}

canonical_decompiled_code:
void __fastcall func2(void *ptr)
{
free(*(void **)ptr);
free(ptr);
}

original_code:
void
amf_buf_free(amf_buf *buf)
{
    free(buf->b);
    free(buf);
}

canonical_original_code:
void amf_buf_free(struct amf_buf *buf)
{
    free(buf->b);
    free(buf);
}

user_defined_types: struct amf_buf { char *b; unsigned long len; void *(*alloc)(void *ud, void *ptr, unsigned long osize, unsigned long nsize); }


decompiled_code:
void *__fastcall amf_buf_append_char(__int64 a1, char a2)
{
char v3[12]; // [rsp+Ch] [rbp-Ch] BYREF

v3[0] = a2;
return amf_buf_append(a1, v3, 1uLL);
}

canonical_decompiled_code:
void *__fastcall func3(__int64 a1, char a2)
{
char v3[12]; // [rsp+Ch] [rbp-Ch] BYREF

v3[0] = a2;
return func0(a1, v3, 1uLL);
}

original_code:
void
amf_buf_append_char(amf_buf *buf, char c)
{
    amf_buf_append(buf, &c, 1);
}

canonical_original_code:
void amf_buf_append_char(struct amf_buf *buf, char c)
{
    amf_buf_append(buf, &c, 1);
}

variable_types: c char


decompiled_code:
void *__fastcall amf_buf_append_double(__int64 a1, double a2)
{
double v3[2]; // [rsp+8h] [rbp-10h] BYREF

v3[0] = a2;
return append_be(a1, (char *)v3, 8uLL);
}

canonical_decompiled_code:
void *__fastcall func4(__int64 a1, double a2)
{
double v3[2]; // [rsp+8h] [rbp-10h] BYREF

v3[0] = a2;
return func1(a1, (char *)v3, 8uLL);
}

original_code:
void
amf_buf_append_double(amf_buf *buf, double d)
{
    _append_be(buf, (char *)&d, 8);
}

canonical_original_code:
void amf_buf_append_double(struct amf_buf *buf, double d)
{
    _append_be(buf, (char *)&d, 8);
}

variable_types: d double


decompiled_code:
void *__fastcall amf_buf_append_u16(__int64 a1, __int16 a2)
{
__int16 v3[6]; // [rsp+Ch] [rbp-Ch] BYREF

v3[0] = a2;
return append_be(a1, (char *)v3, 2uLL);
}

canonical_decompiled_code:
void *__fastcall func5(__int64 a1, __int16 a2)
{
__int16 v3[6]; // [rsp+Ch] [rbp-Ch] BYREF

v3[0] = a2;
return func1(a1, (char *)v3, 2uLL);
}

original_code:
void amf_buf_append_u16(amf_buf *buf, uint16_t u)
{
    _append_be(buf, (char *)&u, 2);
}

canonical_original_code:
void amf_buf_append_u16(struct amf_buf *buf, unsigned short u)
{
    _append_be(buf, (char *)&u, 2);
}

variable_types:
u
unsigned short


decompiled_code:
void *__fastcall amf_buf_append_u32(__int64 a1, int a2)
{
int v3[3]; // [rsp+Ch] [rbp-Ch] BYREF

v3[0] = a2;
return append_be(a1, (char *)v3, 4uLL);
}

canonical_decompiled_code:
void *__fastcall func6(__int64 a1, int a2)
{
int v3[3]; // [rsp+Ch] [rbp-Ch] BYREF

v3[0] = a2;
return func1(a1, (char *)v3, 4uLL);
}

original_code:
void amf_buf_append_u32(amf_buf *buf, uint32_t u)
{
    _append_be(buf, (char *)&u, 4);
}

canonical_original_code:
void amf_buf_append_u32(struct amf_buf *buf, unsigned int u)
{
    _append_be(buf, (char *)&u, 4);
}

variable_types:
u
unsigned int


original_code:
void amf_buf_append_u29(amf_buf *buf, int val)
{
    char b[4];
    int size;
    val &= 0x1fffffff;
    if (val <= 0x7f) {
        b[0] = val;
        size = 1;
    } else if (val <= 0x3fff) {
        b[1] = val & 0x7f;
        val >>= 7;
        b[0] = val | 0x80;
        size = 2;
    } else if (val <= 0x1fffff) {
        b[2] = val & 0x7f;
        val >>= 7;
        b[1] = val | 0x80;
        val >>= 7;
        b[0] = val | 0x80;
        size = 3;
    } else {
        b[3] = val;
        val >>= 8;
        b[2] = val | 0x80;
        val >>= 7;
        b[1] = val | 0x80;
        val >>= 7;
        b[0] = val | 0x80;
        size = 4;
    }
    amf_buf_append(buf, b, size);
}

canonical_original_code:
void amf_buf_append_u29(struct amf_buf *buf, int val)
{
    char b[4];
    int size;
    val &= 0x1fffffff;
    if (val <= 0x7f) {
        b[0] = val;
        size = 1;
    } else if (val <= 0x3fff) {
        b[1] = val & 0x7f;
        val >>= 7;
        b[0] = val | 0x80;
        size = 2;
    } else if (val <= 0x1fffff) {
        b[2] = val & 0x7f;
        val >>= 7;
        b[1] = val | 0x80;
        val >>= 7;
        b[0] = val | 0x80;
        size = 3;
    } else {
        b[3] = val;
        val >>= 8;
        b[2] = val | 0x80;
        val >>= 7;
        b[1] = val | 0x80;
        val >>= 7;
        b[0] = val | 0x80;
        size = 4;
    }
    amf_buf_append(buf, b, size);
}

variable_types: val int

variable_types:
b
char [4]

variable_types: size int


usage

decompiled_code:
void __noreturn usage()
{
fwrite(
"Usage: table_util\n"
" [-b number] or --buckets num buckets to adjust table\n"
" [-o file] or --out-file output filename\n"
" [-v] or --verbose verbose messages\n"
" file input table filename\n",
1uLL,
0xE4uLL,
stderr);
exit(1);
}

canonical_decompiled_code:
void __noreturn func0()
{
fwrite(
"Usage: table_util\n"
" [-b number] or --buckets num buckets to adjust table\n"
" [-o file] or --out-file output filename\n"
" [-v] or --verbose verbose messages\n"
" file input table filename\n",
1uLL,
0xE4uLL,
stderr);
exit(1);
}

original_code:
static void usage(void)
{
  (void)fprintf(stderr,
  "Usage: table_util\n"
  "  [-b number]   or --buckets    num buckets to adjust table\n"
  "  [-o file]     or --out-file   output filename\n"
  "  [-v]          or --verbose    verbose messages\n"
  "  file                          input table filename\n");
  exit(1);
}

canonical_original_code:
static void usage()
{
  (void)fprintf(stderr,
  "Usage: table_util\n"
  "  [-b number]   or --buckets    num buckets to adjust table\n"
  "  [-o file]     or --out-file   output filename\n"
  "  [-v]          or --verbose    verbose messages\n"
  "  file                          input table filename\n");
  exit(1);
}


original_code:
int expand_chars(const void *buf, const int buf_size,
       char *out, const int out_size)
{
  int buf_c;
  const unsigned char *buf_p, *spec_p;
  char *max_p, *out_p = out;
  max_p = out + out_size;
  for (buf_c = 0, buf_p = (const unsigned char *)buf;; buf_c++, buf_p++) {
    if (buf_size < 0) {
      if (*buf_p == '\0') {
 break;
      }
    }
    else {
      if (buf_c >= buf_size) {
 break;
      }
    }
    for (spec_p = (unsigned char *)"e\033^^\"\"''\\\\n\nr\rt\tb\bf\fa\007" + 1;
  *(spec_p - 1) != '\0';
  spec_p += 2) {
      if (*spec_p == *buf_p) {
 break;
      }
    }
    if (*(spec_p - 1) != '\0') {
      if (out_p + 2 >= max_p) {
 break;
      }
      (void)sprintf(out_p, "\\%c", *(spec_p - 1));
      out_p += 2;
      continue;
    }
    if (*buf_p < 128 && ((*__ctype_b_loc ())[(int) ((*buf_p))] & (unsigned short int) _ISprint)) {
      if (out_p + 1 >= max_p) {
 break;
      }
      *out_p = *(char *)buf_p;
      out_p += 1;
    }
    else {
      if (out_p + 4 >= max_p) {
 break;
      }
      (void)sprintf(out_p, "\\%03o", *buf_p);
      out_p += 4;
    }
  }
  return out_p - out;
}

canonical_original_code:
int expand_chars(void *buf, int buf_size, char *out, int out_size)
{
  int buf_c;
  unsigned char *buf_p; unsigned char *spec_p;
  char *max_p; char *out_p = out;
  max_p = out + out_size;
  for (buf_c = 0, buf_p = (unsigned char *)buf;; buf_c++, buf_p++) {
    if (buf_size < 0) {
      if (*buf_p == '\0') {
 break;
      }
    }
    else {
      if (buf_c >= buf_size) {
 break;
      }
    }
    for (spec_p = (unsigned char *)"e\033^^\"\"''\\\\n\nr\rt\tb\bf\fa\007" + 1;
  *(spec_p - 1) != '\0';
  spec_p += 2) {
      if (*spec_p == *buf_p) {
 break;
      }
    }
    if (*(spec_p - 1) != '\0') {
      if (out_p + 2 >= max_p) {
 break;
      }
      (void)sprintf(out_p, "\\%c", *(spec_p - 1));
      out_p += 2;
      continue;
    }
    if (*buf_p < 128 && ((*__ctype_b_loc ())[(int) ((*buf_p))] & (unsigned short) _ISprint)) {
      if (out_p + 1 >= max_p) {
 break;
      }
      *out_p = *(char *)buf_p;
      out_p += 1;
    }
    else {
      if (out_p + 4 >= max_p) {
 break;
      }
      (void)sprintf(out_p, "\\%03o", *buf_p);
      out_p += 4;
    }
  }
  return out_p - out;
}

variable_types:
buf
void *

variable_types:
out
char *


decompiled_code:
__int64 __fastcall dump_table(__int64 a1)
{
__int64 result; // rax
unsigned int v2; // ebx
unsigned int v3; // eax
unsigned int v4; // eax
int v5; // [rsp+8h] [rbp-2830h] BYREF
int v6; // [rsp+Ch] [rbp-282Ch] BYREF
__int64 v7; // [rsp+10h] [rbp-2828h] BYREF
__int64 v8; // [rsp+18h] [rbp-2820h] BYREF
char v9[10264]; // [rsp+20h] [rbp-2818h] BYREF

result = table_first(a1, &v8, &v6, &v7, &v5);
if ( (_DWORD)result == 1 )
{
v2 = 0;
do
{
v3 = (unsigned int)expand_chars(v8, v6, v9, 10240);
printf("%d: key '%.*s' (%d), ", v2, v3, v9, v3);
v4 = (unsigned int)expand_chars(v7, v5, v9, 10240);
printf("data '%.*s' (%d)\n", v4, v9, v4);
result = table_next(a1, &v8, &v6, &v7, &v5);
++v2;
}
while ( (_DWORD)result == 1 );
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1)
{
__int64 result; // rax
unsigned int v2; // ebx
unsigned int v3; // eax
unsigned int v4; // eax
int v5; // [rsp+8h] [rbp-2830h] BYREF
int v6; // [rsp+Ch] [rbp-282Ch] BYREF
__int64 v7; // [rsp+10h] [rbp-2828h] BYREF
__int64 v8; // [rsp+18h] [rbp-2820h] BYREF
char v9[10264]; // [rsp+20h] [rbp-2818h] BYREF

result = table_first(a1, &v8, &v6, &v7, &v5);
if ( (_DWORD)result == 1 )
{
v2 = 0;
do
{
v3 = (unsigned int)func1(v8, v6, v9, 10240);
printf("%d: key '%.*s' (%d), ", v2, v3, v9, v3);
v4 = (unsigned int)func1(v7, v5, v9, 10240);
printf("data '%.*s' (%d)\n", v4, v9, v4);
result = table_next(a1, &v8, &v6, &v7, &v5);
++v2;
}
while ( (_DWORD)result == 1 );
}
return result;
}

original_code:
static void dump_table(table_t *tab_p)
{
  char buf[10240];
  void *key_p, *data_p;
  int ret, key_size, data_size, len, entry_c;
  for (ret = table_first(tab_p, (void **)&key_p, &key_size,
    (void **)&data_p, &data_size), entry_c = 0;
       ret == 1;
       ret = table_next(tab_p, (void **)&key_p, &key_size,
   (void **)&data_p, &data_size), entry_c++) {
    len = expand_chars(key_p, key_size, buf, sizeof(buf));
    (void)printf("%d: key '%.*s' (%d), ", entry_c, len, buf, len);
    len = expand_chars(data_p, data_size, buf, sizeof(buf));
    (void)printf("data '%.*s' (%d)\n", len, buf, len);
  }
}

canonical_original_code:
static void dump_table(void *tab_p)
{
  char buf[10240];
  void *key_p; void *data_p;
  int ret; int key_size; int data_size; int len; int entry_c;
  for (ret = table_first(tab_p, (void **)&key_p, &key_size,
    (void **)&data_p, &data_size), entry_c = 0;
       ret == 1;
       ret = table_next(tab_p, (void **)&key_p, &key_size,
   (void **)&data_p, &data_size), entry_c++) {
    len = expand_chars(key_p, key_size, buf, sizeof(buf));
    (void)printf("%d: key '%.*s' (%d), ", entry_c, len, buf, len);
    len = expand_chars(data_p, data_size, buf, sizeof(buf));
    (void)printf("data '%.*s' (%d)\n", len, buf, len);
  }
}

variable_types:
buf
char [10240]

variable_types: ret int

variable_types: len int


main

canonical_name: main

decompiled_code:
// local variable allocation has failed, the output may be wrong!
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
int v3; // ebx
const char **v4; // rsi
int v5; // ebp
const char *v6; // r14
char v7; // r12
const char *v8; // r13
__int64 v9; // rax
__int64 v10; // rbx
unsigned int v11; // eax
const char *v12; // rax
char v13; // al
const char *v14; // rax
unsigned int v15; // eax
unsigned int v16; // eax
const char *v17; // rax
const char *v18; // rax
unsigned int v19; // eax
const char *v20; // rax
unsigned int v21; // [rsp+4h] [rbp-44h] BYREF
unsigned int v22; // [rsp+8h] [rbp-40h] BYREF
unsigned int v23[15]; // [rsp+Ch] [rbp-3Ch] BYREF

v3 = argc - 1;
v4 = argv + 1;
v5 = 0;
v6 = 0LL;
v7 = 0;
if ( argc - 1 > 0 )
{
while ( **v4 == 45 )
{
v13 = (*v4)[1];
if ( v13 == 111 )
{
if ( !--v3 )
((void (*)(void))usage)();
v6 = v4[1];
++v4;
}
else if ( v13 == 118 )
{
v7 = 1;
}
else
{
if ( v13 != 98 )
usage(*(_QWORD *)&argc, v4, envp);
if ( !--v3 )
((void (*)(void))usage)();
*(_QWORD *)&argc = v4[1];
v5 = atoi(*(const char **)&argc);
++v4;
}
--v3;
++v4;
if ( v3 <= 0 )
goto LABEL_19;
}
}
if ( v3 == 1 )
{
v8 = *v4;
v9 = table_read(*v4, v23, envp);
v10 = v9;
if ( v9 )
{
v11 = table_info(v9, &v21, &v22);
v23[0] = v11;
if ( v11 != 1 )
{
v12 = (const char *)table_strerror(v11);
fprintf(stderr, "table_util: unable to get info on table in '%s': %s\n", v8, v12);
exit(1);
}
printf("Read table of %d buckets and %d entries from '%s'\n", v21, v22, v8);
if ( v7 )
dump_table(v10);
if ( v5 > 0 )
{
v15 = table_adjust(v10, (unsigned int)v5);
v23[0] = v15;
if ( v15 != 1 )
{
v18 = (const char *)table_strerror(v15);
fprintf(stderr, "table_util: unable to adjust table to %d buckets: %s\n", (unsigned int)v5, v18);
exit(1);
}
if ( !v6 )
v6 = v8;
v16 = table_write(v10, v6, 416LL);
v23[0] = v16;
if ( v16 != 1 )
{
v17 = (const char *)table_strerror(v16);
fprintf(stderr, "table_util: unable to write table to '%s': %s\n", v6, v17);
exit(1);
}
printf("Wrote table to '%s'\n", v6);
}
v19 = table_free(v10);
v23[0] = v19;
if ( v19 != 1 )
{
v20 = (const char *)table_strerror(v19);
fprintf(stderr, "table_util: unable to free table: %s\n", v20);
}
exit(0);
}
v14 = (const char *)table_strerror(v23[0]);
fprintf(stderr, "table_util: unable to table_read from '%s': %s\n", v8, v14);
exit(1);
}
LABEL_19:
usage(*(_QWORD *)&argc, v4, envp);
}

canonical_decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
int v3; // ebx
const char **v4; // rsi
int v5; // ebp
const char *v6; // r14
char v7; // r12
const char *v8; // r13
__int64 v9; // rax
__int64 v10; // rbx
unsigned int v11; // eax
const char *v12; // rax
char v13; // al
const char *v14; // rax
unsigned int v15; // eax
unsigned int v16; // eax
const char *v17; // rax
const char *v18; // rax
unsigned int v19; // eax
const char *v20; // rax
unsigned int v21; // [rsp+4h] [rbp-44h] BYREF
unsigned int v22; // [rsp+8h] [rbp-40h] BYREF
unsigned int v23[15]; // [rsp+Ch] [rbp-3Ch] BYREF

v3 = argc - 1;
v4 = argv + 1;
v5 = 0;
v6 = 0LL;
v7 = 0;
if ( argc - 1 > 0 )
{
while ( **v4 == 45 )
{
v13 = (*v4)[1];
if ( v13 == 111 )
{
if ( !--v3 )
((void (*)(void))usage)();
v6 = v4[1];
++v4;
}
else if ( v13 == 118 )
{
v7 = 1;
}
else
{
if ( v13 != 98 )
func0(*(_QWORD *)&argc, v4, envp);
if ( !--v3 )
((void (*)(void))usage)();
*(_QWORD *)&argc = v4[1];
v5 = atoi(*(const char **)&argc);
++v4;
}
--v3;
++v4;
if ( v3 <= 0 )
goto LABEL_19;
}
}
if ( v3 == 1 )
{
v8 = *v4;
v9 = table_read(*v4, v23, envp);
v10 = v9;
if ( v9 )
{
v11 = table_info(v9, &v21, &v22);
v23[0] = v11;
if ( v11 != 1 )
{
v12 = (const char *)table_strerror(v11);
fprintf(stderr, "table_util: unable to get info on table in '%s': %s\n", v8, v12);
exit(1);
}
printf("Read table of %d buckets and %d entries from '%s'\n", v21, v22, v8);
if ( v7 )
func2(v10);
if ( v5 > 0 )
{
v15 = table_adjust(v10, (unsigned int)v5);
v23[0] = v15;
if ( v15 != 1 )
{
v18 = (const char *)table_strerror(v15);
fprintf(stderr, "table_util: unable to adjust table to %d buckets: %s\n", (unsigned int)v5, v18);
exit(1);
}
if ( !v6 )
v6 = v8;
v16 = table_write(v10, v6, 416LL);
v23[0] = v16;
if ( v16 != 1 )
{
v17 = (const char *)table_strerror(v16);
fprintf(stderr, "table_util: unable to write table to '%s': %s\n", v6, v17);
exit(1);
}
printf("Wrote table to '%s'\n", v6);
}
v19 = table_free(v10);
v23[0] = v19;
if ( v19 != 1 )
{
v20 = (const char *)table_strerror(v19);
fprintf(stderr, "table_util: unable to free table: %s\n", v20);
}
exit(0);
}
v14 = (const char *)table_strerror(v23[0]);
fprintf(stderr, "table_util: unable to table_read from '%s': %s\n", v8, v14);
exit(1);
}
LABEL_19:
func0(*(_QWORD *)&argc, v4, envp);
}

original_code:
int main(int argc, char **argv)
{
  table_t *tab_p;
  char do_write = 0, verbose = 0;
  char *out_file = ((void *)0), *in_file;
  int ret, entry_n, bucket_n, num_buckets = 0;
  for (argc--, argv++; argc > 0 && **argv == '-'; argc--, argv++) {
    switch (*(*argv + 1)) {
    case 'b':
      argc--, argv++;
      if (argc == 0) {
 usage();
      }
      num_buckets = atoi(*argv);
      break;
    case 'o':
      argc--, argv++;
      if (argc == 0) {
 usage();
      }
      out_file = *argv;
      break;
    case 'v':
      verbose = 1;
      break;
    default:
      usage();
      break;
    }
  }
  if (argc != 1) {
    usage();
  }
  in_file = *argv;
  tab_p = table_read(in_file, &ret);
  if (tab_p == ((void *)0)) {
    (void)fprintf(stderr, "table_util: unable to table_read from '%s': %s\n",
    in_file, table_strerror(ret));
    exit(1);
  }
  ret = table_info(tab_p, &bucket_n, &entry_n);
  if (ret != 1) {
    (void)fprintf(stderr,
    "table_util: unable to get info on table in '%s': %s\n",
    in_file, table_strerror(ret));
    exit(1);
  }
  (void)printf("Read table of %d buckets and %d entries from '%s'\n",
        bucket_n, entry_n, in_file);
  if (verbose) {
    dump_table(tab_p);
  }
  if (num_buckets > 0) {
    ret = table_adjust(tab_p, num_buckets);
    if (ret != 1) {
      (void)fprintf(stderr,
      "table_util: unable to adjust table to %d buckets: %s\n",
      num_buckets, table_strerror(ret));
      exit(1);
    }
    do_write = 1;
  }
  if (do_write) {
    if (out_file == ((void *)0)) {
      out_file = in_file;
    }
    ret = table_write(tab_p, out_file, 0640);
    if (ret != 1) {
      (void)fprintf(stderr, "table_util: unable to write table to '%s': %s\n",
      out_file, table_strerror(ret));
      exit(1);
    }
    (void)printf("Wrote table to '%s'\n", out_file);
  }
  ret = table_free(tab_p);
  if (ret != 1) {
    (void)fprintf(stderr, "table_util: unable to free table: %s\n",
    table_strerror(ret));
  }
  exit(0);
}

canonical_original_code:
int main(int argc, char **argv)
{
  void *tab_p;
  char do_write = 0; char verbose = 0;
  char *out_file = ((void *)0); char *in_file;
  int ret; int entry_n; int bucket_n; int num_buckets = 0;
  for (argc--, argv++; argc > 0 && **argv == '-'; argc--, argv++) {
    switch (*(*argv + 1)) {
    case 'b':
      argc--, argv++;
      if (argc == 0) {
 usage();
      }
      num_buckets = atoi(*argv);
      break;
    case 'o':
      argc--, argv++;
      if (argc == 0) {
 usage();
      }
      out_file = *argv;
      break;
    case 'v':
      verbose = 1;
      break;
    default:
      usage();
      break;
    }
  }
  if (argc != 1) {
    usage();
  }
  in_file = *argv;
  tab_p = table_read(in_file, &ret);
  if (tab_p == ((void *)0)) {
    (void)fprintf(stderr, "table_util: unable to table_read from '%s': %s\n",
    in_file, table_strerror(ret));
    exit(1);
  }
  ret = table_info(tab_p, &bucket_n, &entry_n);
  if (ret != 1) {
    (void)fprintf(stderr,
    "table_util: unable to get info on table in '%s': %s\n",
    in_file, table_strerror(ret));
    exit(1);
  }
  (void)printf("Read table of %d buckets and %d entries from '%s'\n",
        bucket_n, entry_n, in_file);
  if (verbose) {
    dump_table(tab_p);
  }
  if (num_buckets > 0) {
    ret = table_adjust(tab_p, num_buckets);
    if (ret != 1) {
      (void)fprintf(stderr,
      "table_util: unable to adjust table to %d buckets: %s\n",
      num_buckets, table_strerror(ret));
      exit(1);
    }
    do_write = 1;
  }
  if (do_write) {
    if (out_file == ((void *)0)) {
      out_file = in_file;
    }
    ret = table_write(tab_p, out_file, 0640);
    if (ret != 1) {
      (void)fprintf(stderr, "table_util: unable to write table to '%s': %s\n",
      out_file, table_strerror(ret));
      exit(1);
    }
    (void)printf("Wrote table to '%s'\n", out_file);
  }
  ret = table_free(tab_p);
  if (ret != 1) {
    (void)fprintf(stderr, "table_util: unable to free table: %s\n",
    table_strerror(ret));
  }
  exit(0);
}

variable_types: argc int

variable_types:
argv
char **

variable_types: verbose char


repo: zhenkai/muc

decompiled_code:
__int64 __fastcall jcr_cdata(__int64 a1, __int64 a2, __int64 a3)
{
__int64 result; // rax
__int64 v4; // rdi

result = jcr;
v4 = *(_QWORD *)(jcr + 112);
if ( v4 )
result = xmlnode_insert_cdata(v4, a2, a3);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, __int64 a2, __int64 a3)
{
__int64 result; // rax
__int64 v4; // rdi

result = jcr;
v4 = *(_QWORD *)(jcr + 112);
if ( v4 )
result = xmlnode_insert_cdata(v4, a2, a3);
return result;
}

original_code:
void jcr_cdata(void *m, const char *cdata, int len) {
  if (jcr->current != ((void *)0))
    xmlnode_insert_cdata(jcr->current, cdata, len);
}

canonical_original_code:
void jcr_cdata(void *m, char *cdata, int len) {
  if (jcr->current != ((void *)0))
    xmlnode_insert_cdata(jcr->current, cdata, len);
}

variable_types:
m
void *

variable_types:
cdata
char *


decompiled_code:
__int64 log_alert(const char *a1, __int64 a2, ...)
{
__int64 v2; // rax
__int64 v3; // rax
__int64 v5[2]; // [rsp+0h] [rbp-2E8h] BYREF
char v6[496]; // [rsp+10h] [rbp-2D8h] BYREF
gcc_va_list va; // [rsp+208h] [rbp-E0h] BYREF

va_start(va, a2);
v5[0] = 0LL;
v5[1] = 0LL;
memset(v6, 0, sizeof(v6));
v2 = g_static_mutex_get_mutex_impl(&jcr_log_lock);
g_mutex_lock(v2);
ap_vsnprintf(v5, 512LL, a2, va);
g_log(0LL, 8LL, "%s: %s", a1, (const char *)v5);
v3 = g_static_mutex_get_mutex_impl(&jcr_log_lock);
return g_mutex_unlock(v3);
}

canonical_decompiled_code:
__int64 func2(const char *a1, __int64 a2, ...)
{
__int64 v2; // rax
__int64 v3; // rax
__int64 v5[2]; // [rsp+0h] [rbp-2E8h] BYREF
char v6[496]; // [rsp+10h] [rbp-2D8h] BYREF
gcc_va_list va; // [rsp+208h] [rbp-E0h] BYREF

va_start(va, a2);
v5[0] = 0LL;
v5[1] = 0LL;
memset(v6, 0, sizeof(v6));
v2 = g_static_mutex_get_mutex_impl(&jcr_log_lock);
g_mutex_lock(v2);
ap_vsnprintf(v5, 512LL, a2, va);
g_log(0LL, 8LL, "%s: %s", a1, (const char *)v5);
v3 = g_static_mutex_get_mutex_impl(&jcr_log_lock);
return g_mutex_unlock(v3);
}

original_code:
void log_alert(char *zone, const char *fmt, ...) {
  va_list ap;
  char logmsg[512] = "";
  g_mutex_lock (g_static_mutex_get_mutex_impl (&_jcr_log_lock));
  __builtin_va_start(ap,fmt);
  ap_vsnprintf(logmsg, 512, fmt, ap);
  g_log(((gchar*) 0), G_LOG_LEVEL_CRITICAL, "%s: %s", zone, logmsg);
  __builtin_va_end(ap);
  g_mutex_unlock (g_static_mutex_get_mutex_impl (&_jcr_log_lock));
}

canonical_original_code:
void log_alert(char *zone, char *fmt, ...) {
  __builtin_va_list ap;
  char logmsg[512] = "";
  g_mutex_lock (g_static_mutex_get_mutex_impl (&_jcr_log_lock));
  __builtin_va_start(ap,fmt);
  ap_vsnprintf(logmsg, 512, fmt, ap);
  g_log(((char *) 0), G_LOG_LEVEL_CRITICAL, "%s: %s", zone, logmsg);
  __builtin_va_end(ap);
  g_mutex_unlock (g_static_mutex_get_mutex_impl (&_jcr_log_lock));
}

variable_types:
zone
char *

variable_types:
fmt
char *

variable_types:
logmsg
char [512]


decompiled_code:
__int64 log_error(const char *a1, __int64 a2, ...)
{
__int64 v2; // rax
__int64 v3; // rax
__int64 v5[2]; // [rsp+0h] [rbp-2E8h] BYREF
char v6[496]; // [rsp+10h] [rbp-2D8h] BYREF
gcc_va_list va; // [rsp+208h] [rbp-E0h] BYREF

va_start(va, a2);
v5[0] = 0LL;
v5[1] = 0LL;
memset(v6, 0, sizeof(v6));
v2 = g_static_mutex_get_mutex_impl(&jcr_log_lock);
g_mutex_lock(v2);
ap_vsnprintf(v5, 512LL, a2, va);
g_log(0LL, 4LL, "%s: %s", a1, (const char *)v5);
v3 = g_static_mutex_get_mutex_impl(&jcr_log_lock);
return g_mutex_unlock(v3);
}

canonical_decompiled_code:
__int64 func3(const char *a1, __int64 a2, ...)
{
__int64 v2; // rax
__int64 v3; // rax
__int64 v5[2]; // [rsp+0h] [rbp-2E8h] BYREF
char v6[496]; // [rsp+10h] [rbp-2D8h] BYREF
gcc_va_list va; // [rsp+208h] [rbp-E0h] BYREF

va_start(va, a2);
v5[0] = 0LL;
v5[1] = 0LL;
memset(v6, 0, sizeof(v6));
v2 = g_static_mutex_get_mutex_impl(&jcr_log_lock);
g_mutex_lock(v2);
ap_vsnprintf(v5, 512LL, a2, va);
g_log(0LL, 4LL, "%s: %s", a1, (const char *)v5);
v3 = g_static_mutex_get_mutex_impl(&jcr_log_lock);
return g_mutex_unlock(v3);
}

original_code:
void log_error(char *zone, const char *fmt, ...) {
  va_list ap;
  char logmsg[512] = "";
  g_mutex_lock (g_static_mutex_get_mutex_impl (&_jcr_log_lock));
  __builtin_va_start(ap,fmt);
  ap_vsnprintf(logmsg, 512, fmt, ap);
  g_log(((gchar*) 0), G_LOG_LEVEL_ERROR, "%s: %s", zone, logmsg);
  __builtin_va_end(ap);
  g_mutex_unlock (g_static_mutex_get_mutex_impl (&_jcr_log_lock));
}

canonical_original_code:
void log_error(char *zone, char *fmt, ...) {
  __builtin_va_list ap;
  char logmsg[512] = "";
  g_mutex_lock (g_static_mutex_get_mutex_impl (&_jcr_log_lock));
  __builtin_va_start(ap,fmt);
  ap_vsnprintf(logmsg, 512, fmt, ap);
  g_log(((char *) 0), G_LOG_LEVEL_ERROR, "%s: %s", zone, logmsg);
  __builtin_va_end(ap);
  g_mutex_unlock (g_static_mutex_get_mutex_impl (&_jcr_log_lock));
}


decompiled_code:
__int64 log_notice(const char *a1, __int64 a2, ...)
{
__int64 v2; // rax
__int64 v3; // rax
__int64 v5[2]; // [rsp+0h] [rbp-2E8h] BYREF
char v6[496]; // [rsp+10h] [rbp-2D8h] BYREF
gcc_va_list va; // [rsp+208h] [rbp-E0h] BYREF

va_start(va, a2);
v5[0] = 0LL;
v5[1] = 0LL;
memset(v6, 0, sizeof(v6));
v2 = g_static_mutex_get_mutex_impl(&jcr_log_lock);
g_mutex_lock(v2);
ap_vsnprintf(v5, 512LL, a2, va);
g_log(0LL, 32LL, "%s: %s", a1, (const char *)v5);
v3 = g_static_mutex_get_mutex_impl(&jcr_log_lock);
return g_mutex_unlock(v3);
}

canonical_decompiled_code:
__int64 func4(const char *a1, __int64 a2, ...)
{
__int64 v2; // rax
__int64 v3; // rax
__int64 v5[2]; // [rsp+0h] [rbp-2E8h] BYREF
char v6[496]; // [rsp+10h] [rbp-2D8h] BYREF
gcc_va_list va; // [rsp+208h] [rbp-E0h] BYREF

va_start(va, a2);
v5[0] = 0LL;
v5[1] = 0LL;
memset(v6, 0, sizeof(v6));
v2 = g_static_mutex_get_mutex_impl(&jcr_log_lock);
g_mutex_lock(v2);
ap_vsnprintf(v5, 512LL, a2, va);
g_log(0LL, 32LL, "%s: %s", a1, (const char *)v5);
v3 = g_static_mutex_get_mutex_impl(&jcr_log_lock);
return g_mutex_unlock(v3);
}

original_code:
void log_notice(char *zone, const char *fmt, ...) {
  va_list ap;
  char logmsg[512] = "";
  g_mutex_lock (g_static_mutex_get_mutex_impl (&_jcr_log_lock));
  __builtin_va_start(ap,fmt);
  ap_vsnprintf(logmsg, 512, fmt, ap);
  g_log(((gchar*) 0), G_LOG_LEVEL_MESSAGE, "%s: %s", zone, logmsg);
  __builtin_va_end(ap);
  g_mutex_unlock (g_static_mutex_get_mutex_impl (&_jcr_log_lock));
}

canonical_original_code:
void log_notice(char *zone, char *fmt, ...) {
  __builtin_va_list ap;
  char logmsg[512] = "";
  g_mutex_lock (g_static_mutex_get_mutex_impl (&_jcr_log_lock));
  __builtin_va_start(ap,fmt);
  ap_vsnprintf(logmsg, 512, fmt, ap);
  g_log(((char *) 0), G_LOG_LEVEL_MESSAGE, "%s: %s", zone, logmsg);
  __builtin_va_end(ap);
  g_mutex_unlock (g_static_mutex_get_mutex_impl (&_jcr_log_lock));
}


decompiled_code:
__int64 log_warn(const char *a1, __int64 a2, ...)
{
__int64 v2; // rax
__int64 v3; // rax
__int64 v5[2]; // [rsp+0h] [rbp-2E8h] BYREF
char v6[496]; // [rsp+10h] [rbp-2D8h] BYREF
gcc_va_list va; // [rsp+208h] [rbp-E0h] BYREF

va_start(va, a2);
v5[0] = 0LL;
v5[1] = 0LL;
memset(v6, 0, sizeof(v6));
v2 = g_static_mutex_get_mutex_impl(&jcr_log_lock);
g_mutex_lock(v2);
ap_vsnprintf(v5, 512LL, a2, va);
g_log(0LL, 16LL, "%s: %s", a1, (const char *)v5);
v3 = g_static_mutex_get_mutex_impl(&jcr_log_lock);
return g_mutex_unlock(v3);
}

canonical_decompiled_code:
__int64 func5(const char *a1, __int64 a2, ...)
{
__int64 v2; // rax
__int64 v3; // rax
__int64 v5[2]; // [rsp+0h] [rbp-2E8h] BYREF
char v6[496]; // [rsp+10h] [rbp-2D8h] BYREF
gcc_va_list va; // [rsp+208h] [rbp-E0h] BYREF

va_start(va, a2);
v5[0] = 0LL;
v5[1] = 0LL;
memset(v6, 0, sizeof(v6));
v2 = g_static_mutex_get_mutex_impl(&jcr_log_lock);
g_mutex_lock(v2);
ap_vsnprintf(v5, 512LL, a2, va);
g_log(0LL, 16LL, "%s: %s", a1, (const char *)v5);
v3 = g_static_mutex_get_mutex_impl(&jcr_log_lock);
return g_mutex_unlock(v3);
}

original_code:
void log_warn(char *zone, const char *fmt, ...) {
  va_list ap;
  char logmsg[512] = "";
  g_mutex_lock (g_static_mutex_get_mutex_impl (&_jcr_log_lock));
  __builtin_va_start(ap,fmt);
  ap_vsnprintf(logmsg, 512, fmt, ap);
  g_log(((gchar*) 0), G_LOG_LEVEL_WARNING, "%s: %s", zone, logmsg);
  __builtin_va_end(ap);
  g_mutex_unlock (g_static_mutex_get_mutex_impl (&_jcr_log_lock));
}

canonical_original_code:
void log_warn(char *zone, char *fmt, ...) {
  __builtin_va_list ap;
  char logmsg[512] = "";
  g_mutex_lock (g_static_mutex_get_mutex_impl (&_jcr_log_lock));
  __builtin_va_start(ap,fmt);
  ap_vsnprintf(logmsg, 512, fmt, ap);
  g_log(((char *) 0), G_LOG_LEVEL_WARNING, "%s: %s", zone, logmsg);
  __builtin_va_end(ap);
  g_mutex_unlock (g_static_mutex_get_mutex_impl (&_jcr_log_lock));
}


decompiled_code:
__int64 log_debug(const char *a1, __int64 a2, ...)
{
__int64 v2; // rax
__int64 v3; // rax
__int64 v5[2]; // [rsp+0h] [rbp-2E8h] BYREF
char v6[496]; // [rsp+10h] [rbp-2D8h] BYREF
gcc_va_list va; // [rsp+208h] [rbp-E0h] BYREF

va_start(va, a2);
v5[0] = 0LL;
v5[1] = 0LL;
memset(v6, 0, sizeof(v6));
v2 = g_static_mutex_get_mutex_impl(&jcr_log_lock);
g_mutex_lock(v2);
ap_vsnprintf(v5, 512LL, a2, va);
g_log(0LL, 128LL, "%s: %s", a1, (const char *)v5);
v3 = g_static_mutex_get_mutex_impl(&jcr_log_lock);
return g_mutex_unlock(v3);
}

canonical_decompiled_code:
__int64 func6(const char *a1, __int64 a2, ...)
{
__int64 v2; // rax
__int64 v3; // rax
__int64 v5[2]; // [rsp+0h] [rbp-2E8h] BYREF
char v6[496]; // [rsp+10h] [rbp-2D8h] BYREF
gcc_va_list va; // [rsp+208h] [rbp-E0h] BYREF

va_start(va, a2);
v5[0] = 0LL;
v5[1] = 0LL;
memset(v6, 0, sizeof(v6));
v2 = g_static_mutex_get_mutex_impl(&jcr_log_lock);
g_mutex_lock(v2);
ap_vsnprintf(v5, 512LL, a2, va);
g_log(0LL, 128LL, "%s: %s", a1, (const char *)v5);
v3 = g_static_mutex_get_mutex_impl(&jcr_log_lock);
return g_mutex_unlock(v3);
}

original_code:
void log_debug(char *zone, const char *fmt, ...) {
  va_list ap;
  char logmsg[512] = "";
  g_mutex_lock (g_static_mutex_get_mutex_impl (&_jcr_log_lock));
  __builtin_va_start(ap,fmt);
  ap_vsnprintf(logmsg, 512, fmt, ap);
  g_log(((gchar*) 0), G_LOG_LEVEL_DEBUG, "%s: %s", zone, logmsg);
  __builtin_va_end(ap);
  g_mutex_unlock (g_static_mutex_get_mutex_impl (&_jcr_log_lock));
}

canonical_original_code:
void log_debug(char *zone, char *fmt, ...) {
  __builtin_va_list ap;
  char logmsg[512] = "";
  g_mutex_lock (g_static_mutex_get_mutex_impl (&_jcr_log_lock));
  __builtin_va_start(ap,fmt);
  ap_vsnprintf(logmsg, 512, fmt, ap);
  g_log(((char *) 0), G_LOG_LEVEL_DEBUG, "%s: %s", zone, logmsg);
  __builtin_va_end(ap);
  g_mutex_unlock (g_static_mutex_get_mutex_impl (&_jcr_log_lock));
}


decompiled_code:
void *jutil_timestamp()
{
struct tm *v0; // rax
bool v1; // zf
void *result; // rax
time_t timer; // [rsp+8h] [rbp-10h] BYREF

timer = time(0LL);
if ( timer == -1 )
return 0LL;
v0 = gmtime(&timer);
v1 = (unsigned int)ap_snprintf(
&timestamp_4,
21LL,
"%d-%02d-%02dT%02d:%02d:%02dZ",
(unsigned int)(v0->tm_year + 1900),
(unsigned int)(v0->tm_mon + 1),
(unsigned int)v0->tm_mday,
(unsigned int)v0->tm_hour,
(unsigned int)v0->tm_min,
(unsigned int)v0->tm_sec) == -1;
result = &timestamp_4;
if ( v1 )
result = 0LL;
return result;
}

canonical_decompiled_code:
void *func7()
{
struct tm *v0; // rax
bool v1; // zf
void *result; // rax
time_t timer; // [rsp+8h] [rbp-10h] BYREF

timer = time(0LL);
if ( timer == -1 )
return 0LL;
v0 = gmtime(&timer);
v1 = (unsigned int)ap_snprintf(
&timestamp_4,
21LL,
"%d-%02d-%02dT%02d:%02d:%02dZ",
(unsigned int)(v0->tm_year + 1900),
(unsigned int)(v0->tm_mon + 1),
(unsigned int)v0->tm_mday,
(unsigned int)v0->tm_hour,
(unsigned int)v0->tm_min,
(unsigned int)v0->tm_sec) == -1;
result = &timestamp_4;
if ( v1 )
result = 0LL;
return result;
}

original_code:
char *jutil_timestamp(void)
{
    time_t t;
    struct tm *new_time;
    static char timestamp[21];
    int ret;
    t = time(((void *)0));
    if(t == (time_t)-1)
        return ((void *)0);
    new_time = gmtime(&t);
    ret = ap_snprintf(timestamp, 21, "%d-%02d-%02dT%02d:%02d:%02dZ", 1900+new_time->tm_year,
                   new_time->tm_mon+1, new_time->tm_mday, new_time->tm_hour,
                   new_time->tm_min, new_time->tm_sec);
    if(ret == -1)
        return ((void *)0);
    return timestamp;
}

canonical_original_code:
char *jutil_timestamp()
{
    long t;
    struct tm *new_time;
    static char timestamp[21];
    int ret;
    t = time(((void *)0));
    if(t == (time_t)-1)
        return ((void *)0);
    new_time = gmtime(&t);
    ret = ap_snprintf(timestamp, 21, "%d-%02d-%02dT%02d:%02d:%02dZ", 1900+new_time->tm_year,
                   new_time->tm_mon+1, new_time->tm_mday, new_time->tm_hour,
                   new_time->tm_min, new_time->tm_sec);
    if(ret == -1)
        return ((void *)0);
    return timestamp;
}

variable_types: t 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; } *

variable_types:
timestamp
char [21]

return_type: char *


decompiled_code:
void *jutil_timestamp_0091()
{
struct tm *v0; // rax
bool v1; // zf
void *result; // rax
time_t timer; // [rsp+8h] [rbp-10h] BYREF

timer = time(0LL);
if ( timer == -1 )
return 0LL;
v0 = gmtime(&timer);
v1 = (unsigned int)ap_snprintf(
&timestamp_3,
18LL,
"%d%02d%02dT%02d:%02d:%02d",
(unsigned int)(v0->tm_year + 1900),
(unsigned int)(v0->tm_mon + 1),
(unsigned int)v0->tm_mday,
(unsigned int)v0->tm_hour,
(unsigned int)v0->tm_min,
(unsigned int)v0->tm_sec) == -1;
result = &timestamp_3;
if ( v1 )
result = 0LL;
return result;
}

canonical_decompiled_code:
void *func8()
{
struct tm *v0; // rax
bool v1; // zf
void *result; // rax
time_t timer; // [rsp+8h] [rbp-10h] BYREF

timer = time(0LL);
if ( timer == -1 )
return 0LL;
v0 = gmtime(&timer);
v1 = (unsigned int)ap_snprintf(
&timestamp_3,
18LL,
"%d%02d%02dT%02d:%02d:%02d",
(unsigned int)(v0->tm_year + 1900),
(unsigned int)(v0->tm_mon + 1),
(unsigned int)v0->tm_mday,
(unsigned int)v0->tm_hour,
(unsigned int)v0->tm_min,
(unsigned int)v0->tm_sec) == -1;
result = &timestamp_3;
if ( v1 )
result = 0LL;
return result;
}

original_code:
char *jutil_timestamp_0091(void)
{
    time_t t;
    struct tm *new_time;
    static char timestamp[18];
    int ret;
    t = time(((void *)0));
    if(t == (time_t)-1)
        return ((void *)0);
    new_time = gmtime(&t);
    ret = ap_snprintf(timestamp, 18, "%d%02d%02dT%02d:%02d:%02d", 1900+new_time->tm_year,
                   new_time->tm_mon+1, new_time->tm_mday, new_time->tm_hour,
                   new_time->tm_min, new_time->tm_sec);
    if(ret == -1)
        return ((void *)0);
    return timestamp;
}

canonical_original_code:
char *jutil_timestamp_0091()
{
    long t;
    struct tm *new_time;
    static char timestamp[18];
    int ret;
    t = time(((void *)0));
    if(t == (time_t)-1)
        return ((void *)0);
    new_time = gmtime(&t);
    ret = ap_snprintf(timestamp, 18, "%d%02d%02dT%02d:%02d:%02d", 1900+new_time->tm_year,
                   new_time->tm_mon+1, new_time->tm_mday, new_time->tm_hour,
                   new_time->tm_min, new_time->tm_sec);
    if(ret == -1)
        return ((void *)0);
    return timestamp;
}

variable_types:
timestamp
char [18]

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