original_code:
void plot_symbol_char (char c)
{
static double dx = 0.5 * (1.0 - 0.666666666), dy = -0.5 * 0.5;
  tp->refpoint.x= HP_pos.x - tp->chardiff.x / 2.0;
  tp->refpoint.y= HP_pos.y - tp->chardiff.y / 2.0;
  tp->offset.x = tp->chardiff.x * dx - tp->linediff.x * dy;
  tp->offset.y = tp->chardiff.y * dx - tp->linediff.y * dy;
 ASCII_to_char ((int) c);
  Pen_action_to_tmpfile (MOVE_TO, &tp->refpoint, 0);
}

canonical_original_code:
void plot_symbol_char(char c)
{
static double dx = 0.5 * (1.0 - 0.666666666); static double dy = -0.5 * 0.5;
  tp->refpoint.x= HP_pos.x - tp->chardiff.x / 2.0;
  tp->refpoint.y= HP_pos.y - tp->chardiff.y / 2.0;
  tp->offset.x = tp->chardiff.x * dx - tp->linediff.x * dy;
  tp->offset.y = tp->chardiff.y * dx - tp->linediff.y * dy;
 ASCII_to_char ((int) c);
  Pen_action_to_tmpfile (MOVE_TO, &tp->refpoint, 0);
}

variable_types: dx double

variable_types: dy double


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

if ( a2 )
{
result = *(_QWORD *)(a2 + 24);
*(_QWORD *)(a1 + 24) = result;
if ( result )
*(_QWORD *)(result + 16) = a1;
*(_QWORD *)(a1 + 16) = a2;
*(_QWORD *)(a2 + 24) = a1;
}
else
{
result = first_buf;
if ( first_buf )
{
*(_QWORD *)(a1 + 24) = first_buf;
*(_QWORD *)(a1 + 16) = 0LL;
first_buf = a1;
*(_QWORD *)(result + 16) = a1;
}
else
{
first_buf = a1;
*(_QWORD *)(a1 + 16) = 0LL;
*(_QWORD *)(a1 + 24) = 0LL;
}
}
return result;
}

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

if ( a2 )
{
result = *(_QWORD *)(a2 + 24);
*(_QWORD *)(a1 + 24) = result;
if ( result )
*(_QWORD *)(result + 16) = a1;
*(_QWORD *)(a1 + 16) = a2;
*(_QWORD *)(a2 + 24) = a1;
}
else
{
result = first_buf;
if ( first_buf )
{
*(_QWORD *)(a1 + 24) = first_buf;
*(_QWORD *)(a1 + 16) = 0LL;
first_buf = a1;
*(_QWORD *)(result + 16) = a1;
}
else
{
first_buf = a1;
*(_QWORD *)(a1 + 16) = 0LL;
*(_QWORD *)(a1 + 24) = 0LL;
}
}
return result;
}

original_code:
void link_RowBuf (RowBuf *act, RowBuf *prev)
{
  if (prev == ((void *)0))
  {
 if (first_buf == ((void *)0))
 {
  first_buf = act;
  act->next = act->prev = ((void *)0);
  return;
 }
 act->next = first_buf;
 act->prev = ((void *)0);
 first_buf->prev = act;
 first_buf = act;
  }
  else
  {
 if ((act->next = prev->next) != ((void *)0))
  act->next->prev = act;
 act->prev = prev;
 prev->next = act;
  }
}

canonical_original_code:
void link_RowBuf(struct Row *act, struct Row *prev)
{
  if (prev == ((void *)0))
  {
 if (first_buf == ((void *)0))
 {
  first_buf = act;
  act->next = act->prev = ((void *)0);
  return;
 }
 act->next = first_buf;
 act->prev = ((void *)0);
 first_buf->prev = act;
 first_buf = act;
  }
  else
  {
 if ((act->next = prev->next) != ((void *)0))
  act->next->prev = act;
 act->prev = prev;
 prev->next = act;
  }
}

variable_types: struct Row { unsigned char *buf; int index; struct Row *prev; } *

variable_types:
prev
struct Row *

return_type: void


decompiled_code:
__int64 __fastcall unlink_RowBuf(__int64 a1)
{
__int64 result; // rax
__int64 v2; // rdx

result = *(_QWORD *)(a1 + 16);
v2 = *(_QWORD *)(a1 + 24);
if ( result )
{
*(_QWORD *)(result + 24) = v2;
if ( !v2 )
{
last_buf = result;
goto LABEL_4;
}
LABEL_3:
*(_QWORD *)(v2 + 16) = result;
LABEL_4:
*(_QWORD *)(a1 + 16) = 0LL;
*(_QWORD *)(a1 + 24) = 0LL;
return result;
}
if ( v2 )
{
first_buf = *(_QWORD *)(a1 + 24);
goto LABEL_3;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1)
{
__int64 result; // rax
__int64 v2; // rdx

result = *(_QWORD *)(a1 + 16);
v2 = *(_QWORD *)(a1 + 24);
if ( result )
{
*(_QWORD *)(result + 24) = v2;
if ( !v2 )
{
last_buf = result;
goto LABEL_4;
}
LABEL_3:
*(_QWORD *)(v2 + 16) = result;
LABEL_4:
*(_QWORD *)(a1 + 16) = 0LL;
*(_QWORD *)(a1 + 24) = 0LL;
return result;
}
if ( v2 )
{
first_buf = *(_QWORD *)(a1 + 24);
goto LABEL_3;
}
return result;
}

original_code:
void unlink_RowBuf (RowBuf *act)
{
  if ((act->prev==((void *)0)) && (act->next==((void *)0)))
 return;
  if (act->prev)
 act->prev->next = act->next;
  else
 first_buf = act->next;
  if (act->next)
 act->next->prev = act->prev;
  else
 last_buf = act->prev;
  act->next = act->prev = ((void *)0);
}

canonical_original_code:
void unlink_RowBuf(struct Row *act)
{
  if ((act->prev==((void *)0)) && (act->next==((void *)0)))
 return;
  if (act->prev)
 act->prev->next = act->next;
  else
 first_buf = act->next;
  if (act->next)
 act->next->prev = act->prev;
  else
 last_buf = act->prev;
  act->next = act->prev = ((void *)0);
}

user_defined_types: struct Row { unsigned char *buf; int index; struct Row *prev; }


Getdate

decompiled_code:
char *Getdate()
{
char *v0; // r12
time_t timer; // [rsp+8h] [rbp-10h] BYREF

timer = time(0LL);
v0 = ctime(&timer);
v0[(int)strlen(v0) - 1] = 0;
return v0;
}

canonical_decompiled_code:
char *func5()
{
char *v0; // r12
time_t timer; // [rsp+8h] [rbp-10h] BYREF

timer = time(0LL);
v0 = ctime(&timer);
v0[(int)strlen(v0) - 1] = 0;
return v0;
}

original_code:
char *Getdate (void)
{
int len;
long t;
char *p;
  t = time((long *) 0);
  p = ctime(&t);
  len = strlen(p);
  *(p + len - 1) = '\0';
  return p;
}

canonical_original_code:
char *Getdate()
{
int len;
long t;
char *p;
  t = time((long *) 0);
  p = ctime(&t);
  len = strlen(p);
  *(p + len - 1) = '\0';
  return p;
}

variable_types: len int

variable_types: t long

variable_types:
p
char *

return_type: char *


original_code:
void KCMY_to_K (int nb)
{
int i;
Byte *pK = p_K, *pC = p_C, *pM = p_M, *pY = p_Y;
  for (i=0; i < nb; i++)
 *pK++ |= ((*pC++ | *pM++) | *pY++);
}

canonical_original_code:
void KCMY_to_K(int nb)
{
int i;
unsigned char *pK = p_K; unsigned char *pC = p_C; unsigned char *pM = p_M; unsigned char *pY = p_Y;
  for (i=0; i < nb; i++)
 *pK++ |= ((*pC++ | *pM++) | *pY++);
}

variable_types: nb int

variable_types: i int

variable_types:
pK
unsigned char *

variable_types:
pC
unsigned char *

variable_types:
pM
unsigned char *

variable_types:
pY
unsigned char *


original_code:
void K_to_CMY (int nb)
{
int i;
Byte *pK = p_K, *pC = p_C, *pM = p_M, *pY = p_Y;
  for (i=0; i < nb; i++, pK++)
  {
 *pC++ |= *pK;
 *pM++ |= *pK;
 *pY++ |= *pK;
  }
}

canonical_original_code:
void K_to_CMY(int nb)
{
int i;
unsigned char *pK = p_K; unsigned char *pC = p_C; unsigned char *pM = p_M; unsigned char *pY = p_Y;
  for (i=0; i < nb; i++, pK++)
  {
 *pC++ |= *pK;
 *pM++ |= *pK;
 *pY++ |= *pK;
  }
}


exchange

decompiled_code:
__int64 __fastcall exchange(__int64 a1)
{
size_t v1; // r12
void *v2; // rsp
void *v3; // r15
int v4; // ebp
int v5; // er14
__int64 result; // rax

v1 = 8 * (last_nonopt - first_nonopt);
v2 = alloca(0LL);
v3 = (void *)(a1 + 8LL * first_nonopt);
v4 = first_nonopt;
memcpy(0LL, v3, v1);
v5 = last_nonopt;
memcpy(v3, (const void *)(a1 + 8LL * last_nonopt), 8LL * (optind - last_nonopt));
memcpy((void *)(a1 + 8LL * (v4 + optind - v5)), 0LL, v1);
last_nonopt = optind;
result = (unsigned int)(optind - v5);
first_nonopt = result + v4;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1)
{
size_t v1; // r12
void *v2; // rsp
void *v3; // r15
int v4; // ebp
int v5; // er14
__int64 result; // rax

v1 = 8 * (last_nonopt - first_nonopt);
v2 = alloca(0LL);
v3 = (void *)(a1 + 8LL * first_nonopt);
v4 = first_nonopt;
memcpy(0LL, v3, v1);
v5 = last_nonopt;
memcpy(v3, (const void *)(a1 + 8LL * last_nonopt), 8LL * (optind - last_nonopt));
memcpy((void *)(a1 + 8LL * (v4 + optind - v5)), 0LL, v1);
last_nonopt = optind;
result = (unsigned int)(optind - v5);
first_nonopt = result + v4;
return result;
}

original_code:
static void
exchange (char ** argv)
{
  int nonopts_size = (last_nonopt - first_nonopt) * sizeof (char *);
  char **temp = (char **) __alloca (nonopts_size);
  memcpy ((temp), (&argv[first_nonopt]), (nonopts_size));
  memcpy ((&argv[first_nonopt]), (&argv[last_nonopt]), ((optind - last_nonopt) * sizeof (char *)));
  memcpy ((&argv[first_nonopt + optind - last_nonopt]), (temp), (nonopts_size));
  first_nonopt += (optind - last_nonopt);
  last_nonopt = optind;
}

canonical_original_code:
static void exchange(char **argv)
{
  int nonopts_size = (last_nonopt - first_nonopt) * sizeof (char *);
  char **temp = (char **) __alloca (nonopts_size);
  memcpy ((temp), (&argv[first_nonopt]), (nonopts_size));
  memcpy ((&argv[first_nonopt]), (&argv[last_nonopt]), ((optind - last_nonopt) * sizeof (char *)));
  memcpy ((&argv[first_nonopt + optind - last_nonopt]), (temp), (nonopts_size));
  first_nonopt += (optind - last_nonopt);
  last_nonopt = optind;
}

variable_types:
argv
char **

variable_types:
temp
char **


decompiled_code:
__int64 __fastcall g_bit_nth_lsf(int a1, int a2)
{
do
{
if ( (a1 & (1 << ++a2)) != 0 )
return (unsigned int)a2;
}
while ( a2 <= 31 );
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 __fastcall func0(int a1, int a2)
{
do
{
if ( (a1 & (1 << ++a2)) != 0 )
return (unsigned int)a2;
}
while ( a2 <= 31 );
return 0xFFFFFFFFLL;
}

original_code:
extern gint
g_bit_nth_lsf (guint32 mask,
        gint nth_bit)
{
  do
    {
      nth_bit++;
      if (mask & (1 << (guint) nth_bit))
 return nth_bit;
    }
  while (nth_bit < 32);
  return -1;
}

canonical_original_code:
extern int g_bit_nth_lsf(unsigned int mask, int nth_bit)
{
  do
    {
      nth_bit++;
      if (mask & (1 << (unsigned int) nth_bit))
 return nth_bit;
    }
  while (nth_bit < 32);
  return -1;
}

variable_types:
mask
unsigned int

return_type: int


decompiled_code:
__int64 __fastcall g_bit_nth_msf(int a1, int a2)
{
int v2; // ecx

v2 = a2;
if ( a2 < 0 )
v2 = 32;
do
{
if ( (a1 & (1 << --v2)) != 0 )
return (unsigned int)v2;
}
while ( v2 > 0 );
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 __fastcall func1(int a1, int a2)
{
int v2; // ecx

v2 = a2;
if ( a2 < 0 )
v2 = 32;
do
{
if ( (a1 & (1 << --v2)) != 0 )
return (unsigned int)v2;
}
while ( v2 > 0 );
return 0xFFFFFFFFLL;
}

original_code:
extern gint
g_bit_nth_msf (guint32 mask,
        gint nth_bit)
{
  if (nth_bit < 0)
    nth_bit = 32;
  do
    {
      nth_bit--;
      if (mask & (1 << (guint) nth_bit))
 return nth_bit;
    }
  while (nth_bit > 0);
  return -1;
}

canonical_original_code:
extern int g_bit_nth_msf(unsigned int mask, int nth_bit)
{
  if (nth_bit < 0)
    nth_bit = 32;
  do
    {
      nth_bit--;
      if (mask & (1 << (unsigned int) nth_bit))
 return nth_bit;
    }
  while (nth_bit > 0);
  return -1;
}


decompiled_code:
__int64 __fastcall g_bit_storage(unsigned int a1)
{
__int64 result; // rax

LODWORD(result) = 0;
do
{
result = (unsigned int)(result + 1);
a1 >>= 1;
}
while ( a1 );
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(unsigned int a1)
{
__int64 result; // rax

LODWORD(result) = 0;
do
{
result = (unsigned int)(result + 1);
a1 >>= 1;
}
while ( a1 );
return result;
}

original_code:
extern guint
g_bit_storage (guint number)
{
  register guint n_bits = 0;
  do
    {
      n_bits++;
      number >>= 1;
    }
  while (number);
  return n_bits;
}

canonical_original_code:
extern unsigned int g_bit_storage(unsigned int number)
{
  register unsigned int n_bits = 0;
  do
    {
      n_bits++;
      number >>= 1;
    }
  while (number);
  return n_bits;
}

variable_types:
number
unsigned int

return_type: unsigned int


decompiled_code:
__int64 g_atexit()
{
return g_log(0LL, 4LL, "Could not register atexit() function: %s", "no implementation");
}

canonical_decompiled_code:
__int64 func3()
{
return g_log(0LL, 4LL, "Could not register atexit() function: %s", "no implementation");
}

original_code:
void
g_atexit (GVoidFunc func)
{
  gint result;
  gchar *error = ((void *)0);
  result = 0;
  error = "no implementation";
  if (error)
    g_log ((((void *)0)), G_LOG_LEVEL_ERROR, "Could not register atexit() function: %s", error);
}

canonical_original_code:
void g_atexit(void (*func)())
{
  int result;
  char *error = ((void *)0);
  result = 0;
  error = "no implementation";
  if (error)
    g_log ((((void *)0)), G_LOG_LEVEL_ERROR, "Could not register atexit() function: %s", error);
}

variable_types:
func
void (*)()

variable_types: result int

variable_types:
error
char *


decompiled_code:
size_t g_snprintf(char *s, size_t n, __int64 a3, ...)
{
const char *v3; // r12
gcc_va_list va; // [rsp+8h] [rbp-E0h] BYREF

va_start(va, a3);
v3 = (const char *)g_strdup_vprintf(a3, va);
strncpy(s, v3, n);
s[n - 1] = 0;
g_free(v3);
return strlen(s);
}

canonical_decompiled_code:
size_t func4(char *s, size_t n, __int64 a3, ...)
{
const char *v3; // r12
gcc_va_list va; // [rsp+8h] [rbp-E0h] BYREF

va_start(va, a3);
v3 = (const char *)g_strdup_vprintf(a3, va);
strncpy(s, v3, n);
s[n - 1] = 0;
g_free(v3);
return strlen(s);
}

original_code:
gint
g_snprintf (gchar *str,
     gulong n,
     gchar const *fmt,
     ...)
{
  gchar *printed;
  va_list args;
  __builtin_va_start(args,fmt);
  printed = g_strdup_vprintf (fmt, args);
  __builtin_va_end(args);
  strncpy (str, printed, n);
  str[n-1] = '\0';
  g_free (printed);
  return strlen (str);
}

canonical_original_code:
int g_snprintf(char *str, unsigned long n, char *fmt, ...)
{
  char *printed;
  __builtin_va_list args;
  __builtin_va_start(args,fmt);
  printed = g_strdup_vprintf (fmt, args);
  __builtin_va_end(args);
  strncpy (str, printed, n);
  str[n-1] = '\0';
  g_free (printed);
  return strlen (str);
}

variable_types:
str
char *

variable_types:
n
unsigned long

variable_types:
fmt
char *

variable_types:
printed
char *


decompiled_code:
size_t __fastcall g_vsnprintf(char *s, size_t n, __int64 a3, __int64 a4)
{
const char *v4; // r12

v4 = (const char *)g_strdup_vprintf(a3, a4);
strncpy(s, v4, n);
s[n - 1] = 0;
g_free(v4);
return strlen(s);
}

canonical_decompiled_code:
size_t __fastcall func5(char *s, size_t n, __int64 a3, __int64 a4)
{
const char *v4; // r12

v4 = (const char *)g_strdup_vprintf(a3, a4);
strncpy(s, v4, n);
s[n - 1] = 0;
g_free(v4);
return strlen(s);
}

original_code:
gint
g_vsnprintf (gchar *str,
      gulong n,
      gchar const *fmt,
      va_list args)
{
  gchar *printed;
  printed = g_strdup_vprintf (fmt, args);
  strncpy (str, printed, n);
  str[n-1] = '\0';
  g_free (printed);
  return strlen (str);
}

canonical_original_code:
int g_vsnprintf(char *str, unsigned long n, char *fmt, __builtin_va_list args)
{
  char *printed;
  printed = g_strdup_vprintf (fmt, args);
  strncpy (str, printed, n);
  str[n-1] = '\0';
  g_free (printed);
  return strlen (str);
}


decompiled_code:
__int64 __fastcall g_parse_debug_string(__int64 a1, __int64 a2, unsigned int a3)
{
unsigned int v4; // er12
_DWORD *v5; // rax
const char *v7; // rbp
char *v8; // rax
char *v9; // r13
__int64 v10; // r15
unsigned int v11; // er14
char v12; // [rsp+Fh] [rbp-49h]
const char *v13; // [rsp+18h] [rbp-40h]

if ( !a1 )
{
v4 = 0;
g_log(
0LL,
8LL,
"file %s: line %d (%s): assertion `%s' failed.",
"gutils.c",
187LL,
"g_parse_debug_string",
"string != NULL");
return v4;
}
if ( (unsigned int)g_strcasecmp(a1, "all") )
{
v4 = 0;
v13 = (const char *)g_strdup(a1);
v7 = v13;
if ( !*v13 )
{
LABEL_16:
g_free(v13);
return v4;
}
while ( 1 )
{
v8 = strchr(v7, 58);
v9 = v8;
if ( !v8 )
break;
*v8 = 0;
v12 = 1;
if ( a3 )
goto LABEL_10;
LABEL_14:
v7 = v9 + 1;
if ( !v9[1] || !v12 )
goto LABEL_16;
}
v9 = (char *)&v7[strlen(v7)];
*v9 = 0;
if ( !a3 )
goto LABEL_16;
v12 = 0;
LABEL_10:
v10 = a2;
v11 = 0;
do
{
if ( !(unsigned int)g_strcasecmp(*(_QWORD *)v10, v7) )
v4 |= *(_DWORD *)(v10 + 8);
++v11;
v10 += 16LL;
}
while ( a3 > v11 );
goto LABEL_14;
}
if ( !a3 )
return 0;
v4 = 0;
v5 = (_DWORD *)(a2 + 8);
do
{
v4 |= *v5;
v5 += 4;
}
while ( (_DWORD *)(a2 + 16LL * (a3 - 1) + 24) != v5 );
return v4;
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1, __int64 a2, unsigned int a3)
{
unsigned int v4; // er12
_DWORD *v5; // rax
const char *v7; // rbp
char *v8; // rax
char *v9; // r13
__int64 v10; // r15
unsigned int v11; // er14
char v12; // [rsp+Fh] [rbp-49h]
const char *v13; // [rsp+18h] [rbp-40h]

if ( !a1 )
{
v4 = 0;
g_log(
0LL,
8LL,
"file %s: line %d (%s): assertion `%s' failed.",
"gutils.c",
187LL,
"g_parse_debug_string",
"string != NULL");
return v4;
}
if ( (unsigned int)g_strcasecmp(a1, "all") )
{
v4 = 0;
v13 = (const char *)g_strdup(a1);
v7 = v13;
if ( !*v13 )
{
LABEL_16:
g_free(v13);
return v4;
}
while ( 1 )
{
v8 = strchr(v7, 58);
v9 = v8;
if ( !v8 )
break;
*v8 = 0;
v12 = 1;
if ( a3 )
goto LABEL_10;
LABEL_14:
v7 = v9 + 1;
if ( !v9[1] || !v12 )
goto LABEL_16;
}
v9 = (char *)&v7[strlen(v7)];
*v9 = 0;
if ( !a3 )
goto LABEL_16;
v12 = 0;
LABEL_10:
v10 = a2;
v11 = 0;
do
{
if ( !(unsigned int)g_strcasecmp(*(_QWORD *)v10, v7) )
v4 |= *(_DWORD *)(v10 + 8);
++v11;
v10 += 16LL;
}
while ( a3 > v11 );
goto LABEL_14;
}
if ( !a3 )
return 0;
v4 = 0;
v5 = (_DWORD *)(a2 + 8);
do
{
v4 |= *v5;
v5 += 4;
}
while ( (_DWORD *)(a2 + 16LL * (a3 - 1) + 24) != v5 );
return v4;
}

original_code:
guint
g_parse_debug_string (const gchar *string,
         GDebugKey *keys,
         guint nkeys)
{
  guint i;
  guint result = 0;
  (void)({ if (!(string != ((void *)0))) { g_log ((((void *)0)), G_LOG_LEVEL_CRITICAL, "file %s: line %d (%s): assertion `%s' failed.", "gutils.c", 187, __PRETTY_FUNCTION__, "string != NULL"); return 0; }; });
  if (!g_strcasecmp (string, "all"))
    {
      for (i=0; i<nkeys; i++)
 result |= keys[i].value;
    }
  else
    {
      gchar *str = g_strdup (string);
      gchar *p = str;
      gchar *q;
      gboolean done = (0);
      while (*p && !done)
 {
   q = strchr (p, ':');
   if (!q)
     {
       q = p + strlen(p);
       done = (!(0));
     }
   *q = 0;
   for (i=0; i<nkeys; i++)
     if (!g_strcasecmp(keys[i].key, p))
       result |= keys[i].value;
   p = q+1;
 }
      g_free (str);
    }
  return result;
}

canonical_original_code:
unsigned int g_parse_debug_string(char *string, struct _GDebugKey *keys, unsigned int nkeys)
{
  unsigned int i;
  unsigned int result = 0;
  (void)({ if (!(string != ((void *)0))) { g_log ((((void *)0)), G_LOG_LEVEL_CRITICAL, "file %s: line %d (%s): assertion `%s' failed.", "gutils.c", 187, __PRETTY_FUNCTION__, "string != NULL"); return 0; }; });
  if (!g_strcasecmp (string, "all"))
    {
      for (i=0; i<nkeys; i++)
 result |= keys[i].value;
    }
  else
    {
      char *str = g_strdup (string);
      char *p = str;
      char *q;
      int done = (0);
      while (*p && !done)
 {
   q = strchr (p, ':');
   if (!q)
     {
       q = p + strlen(p);
       done = (!(0));
     }
   *q = 0;
   for (i=0; i<nkeys; i++)
     if (!g_strcasecmp(keys[i].key, p))
       result |= keys[i].value;
   p = q+1;
 }
      g_free (str);
    }
  return result;
}

variable_types:
string
char *

variable_types: struct _GDebugKey { char *key; unsigned int value; } *

variable_types:
nkeys
unsigned int

variable_types:
i
unsigned int

variable_types:
result
unsigned int

variable_types:
p
char *

variable_types:
q
char *

variable_types: done int


decompiled_code:
const char *__fastcall g_basename(const char *a1)
{
char *v2; // rax
char *v3; // rdi
bool v4; // zf
const char *result; // rax

if ( a1 )
{
v2 = strrchr(a1, 47);
v3 = v2 + 1;
v4 = v2 == 0LL;
result = a1;
if ( !v4 )
result = v3;
}
else
{
g_log(
0LL,
8LL,
"file %s: line %d (%s): assertion `%s' failed.",
"gutils.c",
230LL,
"g_basename",
"file_name != NULL");
result = 0LL;
}
return result;
}

canonical_decompiled_code:
const char *__fastcall func7(const char *a1)
{
char *v2; // rax
char *v3; // rdi
bool v4; // zf
const char *result; // rax

if ( a1 )
{
v2 = strrchr(a1, 47);
v3 = v2 + 1;
v4 = v2 == 0LL;
result = a1;
if ( !v4 )
result = v3;
}
else
{
g_log(
0LL,
8LL,
"file %s: line %d (%s): assertion `%s' failed.",
"gutils.c",
230LL,
"g_basename",
"file_name != NULL");
result = 0LL;
}
return result;
}

original_code:
gchar*
g_basename (const gchar *file_name)
{
  register gchar *base;
  (void)({ if (!(file_name != ((void *)0))) { g_log ((((void *)0)), G_LOG_LEVEL_CRITICAL, "file %s: line %d (%s): assertion `%s' failed.", "gutils.c", 230, __PRETTY_FUNCTION__, "file_name != NULL"); return ((void *)0); }; });
  base = strrchr (file_name, '/');
  if (base)
    return base + 1;
  return (gchar*) file_name;
}

canonical_original_code:
char *g_basename(char *file_name)
{
  register char *base;
  (void)({ if (!(file_name != ((void *)0))) { g_log ((((void *)0)), G_LOG_LEVEL_CRITICAL, "file %s: line %d (%s): assertion `%s' failed.", "gutils.c", 230, __PRETTY_FUNCTION__, "file_name != NULL"); return ((void *)0); }; });
  base = strrchr (file_name, '/');
  if (base)
    return base + 1;
  return (char *) file_name;
}

variable_types:
base
char *


decompiled_code:
_BOOL8 __fastcall g_path_is_absolute(_BYTE *a1)
{
if ( a1 )
return *a1 == 47;
g_log(
0LL,
8LL,
"file %s: line %d (%s): assertion `%s' failed.",
"gutils.c",
247LL,
"g_path_is_absolute",
"file_name != NULL");
return 0LL;
}

canonical_decompiled_code:
_BOOL8 __fastcall func8(_BYTE *a1)
{
if ( a1 )
return *a1 == 47;
g_log(
0LL,
8LL,
"file %s: line %d (%s): assertion `%s' failed.",
"gutils.c",
247LL,
"g_path_is_absolute",
"file_name != NULL");
return 0LL;
}

original_code:
gboolean
g_path_is_absolute (const gchar *file_name)
{
  (void)({ if (!(file_name != ((void *)0))) { g_log ((((void *)0)), G_LOG_LEVEL_CRITICAL, "file %s: line %d (%s): assertion `%s' failed.", "gutils.c", 247, __PRETTY_FUNCTION__, "file_name != NULL"); return (0); }; });
  if (file_name[0] == '/')
    return (!(0));
  return (0);
}

canonical_original_code:
int g_path_is_absolute(char *file_name)
{
  (void)({ if (!(file_name != ((void *)0))) { g_log ((((void *)0)), G_LOG_LEVEL_CRITICAL, "file %s: line %d (%s): assertion `%s' failed.", "gutils.c", 247, __PRETTY_FUNCTION__, "file_name != NULL"); return (0); }; });
  if (file_name[0] == '/')
    return (!(0));
  return (0);
}


decompiled_code:
__int64 g_get_current_dir()
{
char *v0; // rax
char *v1; // rbp
__int64 v2; // r12

v0 = (char *)g_malloc(4097LL);
*v0 = 0;
v1 = v0;
if ( !(unsigned int)getcwd(v0, 0x1000uLL) || !*v1 )
*(_WORD *)v1 = 47;
v2 = g_strdup(v1);
g_free(v1);
return v2;
}

canonical_decompiled_code:
__int64 func9()
{
char *v0; // rax
char *v1; // rbp
__int64 v2; // r12

v0 = (char *)g_malloc(4097LL);
*v0 = 0;
v1 = v0;
if ( !(unsigned int)getcwd(v0, 0x1000uLL) || !*v1 )
*(_WORD *)v1 = 47;
v2 = g_strdup(v1);
g_free(v1);
return v2;
}

original_code:
gchar*
g_get_current_dir (void)
{
  gchar *buffer;
  gchar *dir;
  buffer = ((gchar *) g_malloc ((unsigned) sizeof (gchar) * ((4096 + 1))));
  *buffer = 0;
  dir = getcwd (buffer, (4096 + 1) - 1);
  if (!dir || !*buffer)
    {
      buffer[0] = '/';
      buffer[1] = 0;
    }
  dir = g_strdup (buffer);
  g_free (buffer);
  return dir;
}

canonical_original_code:
char *g_get_current_dir()
{
  char *buffer;
  char *dir;
  buffer = ((char *) g_malloc ((unsigned int) sizeof (gchar) * ((4096 + 1))));
  *buffer = 0;
  dir = getcwd (buffer, (4096 + 1) - 1);
  if (!dir || !*buffer)
    {
      buffer[0] = '/';
      buffer[1] = 0;
    }
  dir = g_strdup (buffer);
  g_free (buffer);
  return dir;
}

variable_types:
buffer
char *

variable_types:
dir
char *


decompiled_code:
char *__fastcall g_getenv(const char *a1)
{
if ( a1 )
return getenv(a1);
g_log(0LL, 8LL, "file %s: line %d (%s): assertion `%s' failed.", "gutils.c", 335LL, "g_getenv", "variable != NULL");
return 0LL;
}

canonical_decompiled_code:
char *__fastcall func10(const char *a1)
{
if ( a1 )
return getenv(a1);
g_log(0LL, 8LL, "file %s: line %d (%s): assertion `%s' failed.", "gutils.c", 335LL, "g_getenv", "variable != NULL");
return 0LL;
}

original_code:
gchar*
g_getenv (const gchar *variable)
{
  (void)({ if (!(variable != ((void *)0))) { g_log ((((void *)0)), G_LOG_LEVEL_CRITICAL, "file %s: line %d (%s): assertion `%s' failed.", "gutils.c", 335, __PRETTY_FUNCTION__, "variable != NULL"); return ((void *)0); }; });
  return getenv (variable);
}

canonical_original_code:
char *g_getenv(char *variable)
{
  (void)({ if (!(variable != ((void *)0))) { g_log ((((void *)0)), G_LOG_LEVEL_CRITICAL, "file %s: line %d (%s): assertion `%s' failed.", "gutils.c", 335, __PRETTY_FUNCTION__, "variable != NULL"); return ((void *)0); }; });
  return getenv (variable);
}

variable_types:
variable
char *


decompiled_code:
const char *get_log_name()
{
return "c:/home/work/tools/mc-4.5.4/src/_mcdbg.log";
}

canonical_decompiled_code:
const char *func0()
{
return "c:/home/work/tools/mc-4.5.4/src/_mcdbg.log";
}

original_code:
static char *get_log_name(void)
{ return std_log_name?std_log_name:"c:/home/work/tools/mc-4.5.4/src/_mcdbg.log";
}

canonical_original_code:
static char *get_log_name()
{ return std_log_name?std_log_name:"c:/home/work/tools/mc-4.5.4/src/_mcdbg.log";
}


decompiled_code:
char *__fastcall g_log(__int64 a1, __int64 a2, __int64 a3, __int64 a4, __int64 a5, __int64 a6, char a7)
{
return &a7;
}

canonical_decompiled_code:
char *__fastcall func3(__int64 a1, __int64 a2, __int64 a3, __int64 a4, __int64 a5, __int64 a6, char a7)
{
return &a7;
}

original_code:
void
g_log (const gchar *log_domain,
       GLogLevelFlags log_level,
       const gchar *format,
       ...)
{
  va_list args;
  __builtin_va_start(args,format);
  __builtin_va_end(args);
}

canonical_original_code:
void g_log(char *log_domain, enum GLogLevelFlags log_level, char *format, ...)
{
  __builtin_va_list args;
  __builtin_va_start(args,format);
  __builtin_va_end(args);
}

variable_types: enum GLogLevelFlags { G_LOG_FLAG_RECURSION=expr, G_LOG_FLAG_FATAL=expr, G_LOG_LEVEL_ERROR=expr, G_LOG_LEVEL_CRITICAL=expr, G_LOG_LEVEL_WARNING=expr, G_LOG_LEVEL_MESSAGE=expr, G_LOG_LEVEL_INFO=expr, G_LOG_LEVEL_DEBUG=expr, G_LOG_LEVEL_MASK=expr }

variable_types:
format
char *


decompiled_code:
// attributes: thunk
void *g_malloc(size_t size)
{
return malloc(size);
}

canonical_decompiled_code:
void *func3(size_t size)
{
return malloc(size);
}

original_code:
gpointer
g_malloc (gulong size)
{
  return malloc(size);
}

canonical_original_code:
void *g_malloc(unsigned long size)
{
  return malloc(size);
}

variable_types:
size
unsigned long

return_type: void *


decompiled_code:
// attributes: thunk
void *g_realloc(void *ptr, size_t size)
{
return realloc(ptr, size);
}

canonical_decompiled_code:
void *func4(void *ptr, size_t size)
{
return realloc(ptr, size);
}

original_code:
gpointer
g_realloc (gpointer mem,
    gulong size)
{ return realloc(mem,size);
}

canonical_original_code:
void *g_realloc(void *mem, unsigned long size)
{ return realloc(mem,size);
}

variable_types:
mem
void *


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

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

original_code:
void
g_free (gpointer mem)
{
  if(mem)free(mem);
}

canonical_original_code:
void g_free(void *mem)
{
  if(mem)free(mem);
}


decompiled_code:
__int64 is_unix_shell()
{
return (unsigned int)unix_shell;
}

canonical_decompiled_code:
__int64 func0()
{
return (unsigned int)unix_shell;
}

original_code:
int is_unix_shell()
{ return unix_shell; }


decompiled_code:
void OS_adjust()
{
char *v0; // rbx
char v1; // al
char *v2; // rax
void *v3; // rbp

v0 = shell;
v1 = *shell;
if ( *shell )
{
do
{
if ( v1 == 47 )
v1 = 92;
*v0++ = v1;
v1 = *v0;
}
while ( *v0 );
v0 = shell;
}
v2 = &v0[strlen(v0) - 2];
if ( *v2 == 115 && v2[1] == 104 && !v2[2] )
unix_shell = 1;
v3 = (void *)(int)getcwd2(0LL, 0LL);
chdir2(home_dir);
home_dir = (int)getcwd2(0LL, 0LL);
if ( (_DWORD)v3 )
{
chdir2(v3);
free(v3);
}
}

canonical_decompiled_code:
void func1()
{
char *v0; // rbx
char v1; // al
char *v2; // rax
void *v3; // rbp

v0 = shell;
v1 = *shell;
if ( *shell )
{
do
{
if ( v1 == 47 )
v1 = 92;
*v0++ = v1;
v1 = *v0;
}
while ( *v0 );
v0 = shell;
}
v2 = &v0[strlen(v0) - 2];
if ( *v2 == 115 && v2[1] == 104 && !v2[2] )
unix_shell = 1;
v3 = (void *)(int)getcwd2(0LL, 0LL);
chdir2(home_dir);
home_dir = (int)getcwd2(0LL, 0LL);
if ( (_DWORD)v3 )
{
chdir2(v3);
free(v3);
}
}

original_code:
void OS_adjust()
{ char *d=0,*p=shell;
  while(*p){ *p=*p=='/'?'\\':*p; p++; }
  p=shell+strlen(shell)-2;
  if(!strcmp(p,"sh"))unix_shell=1;
  d=_getcwd2(((void *)0),0);
  _chdir2(home_dir);
  home_dir=_getcwd2(((void *)0),0);
  if(d) { _chdir2(d); free(d); }
}

canonical_original_code:
void OS_adjust()
{ char *d = 0; char *p = shell;
  while(*p){ *p=*p=='/'?'\\':*p; p++; }
  p=shell+strlen(shell)-2;
  if(!strcmp(p,"sh"))unix_shell=1;
  d=_getcwd2(((void *)0),0);
  _chdir2(home_dir);
  home_dir=_getcwd2(((void *)0),0);
  if(d) { _chdir2(d); free(d); }
}

variable_types:
d
char *


decompiled_code:
__int64 __fastcall my_rename(char *old, char *a2)
{
unsigned int v2; // er12
char v4[280]; // [rsp+0h] [rbp-118h] BYREF

if ( !tmpnam(v4) )
return (unsigned int)-1;
unlink(v4);
copy_isra_0(a2, v4);
unlink(a2);
v2 = rename(old, a2);
if ( v2 )
copy_isra_0(v4, a2);
unlink(v4);
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func1(char *old, char *a2)
{
unsigned int v2; // er12
char v4[280]; // [rsp+0h] [rbp-118h] BYREF

if ( !tmpnam(v4) )
return (unsigned int)-1;
unlink(v4);
func0(a2, v4);
unlink(a2);
v2 = rename(old, a2);
if ( v2 )
func0(v4, a2);
unlink(v4);
return v2;
}

original_code:
int my_rename(char *oldname, char *newname)
{ int rc;
  char tmp_backup[256];
  if(!tmpnam(tmp_backup))return -1;
  rc=unlink(tmp_backup);
  rc=copy(newname,tmp_backup);
  rc=unlink(newname);
  rc=rename(oldname,newname);
  if(rc)copy(tmp_backup,newname);
  unlink(tmp_backup);
  return rc;
}

variable_types:
oldname
char *

variable_types:
newname
char *

variable_types: rc int


upCase

decompiled_code:
__int64 __fastcall upCase(unsigned int a1)
{
__int64 result; // rax

result = a1 & 0xFFFFFFDF;
if ( (unsigned __int8)(a1 - 97) >= 0x1Au )
result = a1;
return result;
}

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

result = a1 & 0xFFFFFFDF;
if ( (unsigned __int8)(a1 - 97) >= 0x1Au )
result = a1;
return result;
}

original_code:
char upCase(char Ch)
{
 if ((Ch >= 'a') && (Ch <= 'z'))
       return Ch & 0xDF;
  else return Ch;
}

variable_types: Ch char

return_type: char


loCase

decompiled_code:
__int64 __fastcall loCase(unsigned int a1)
{
__int64 result; // rax

result = a1 | 0x20;
if ( (unsigned __int8)(a1 - 65) >= 0x1Au )
result = a1;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(unsigned int a1)
{
__int64 result; // rax

result = a1 | 0x20;
if ( (unsigned __int8)(a1 - 65) >= 0x1Au )
result = a1;
return result;
}

original_code:
char loCase(char Ch)
{
 if ((Ch >= 'A') && (Ch <= 'Z'))
       return Ch | 0x20;
  else return Ch;
}


extractDir

decompiled_code:
char *__fastcall extractDir(char *src)
{
__int64 v1; // rcx
__int64 v2; // rax
size_t v3; // rbx
int v4; // esi
char *v5; // rax
char *v6; // r8
char *v7; // rax

LODWORD(v2) = strlen(src);
v1 = 0x200000000801LL;
v2 = (int)v2;
while ( 1 )
{
v3 = (int)v2;
if ( (int)v2 <= 0 )
break;
v4 = (unsigned __int8)src[--v2];
if ( (unsigned __int8)(v4 - 47) <= 0x2Du )
{
if ( _bittest64(&v1, (unsigned int)(v4 - 47)) )
break;
}
}
v5 = (char *)malloc((int)v3 + 1);
v6 = v5;
if ( v5 )
{
v7 = strncpy(v5, src, v3);
v7[v3] = 0;
v6 = v7;
}
return v6;
}

canonical_decompiled_code:
char *__fastcall func2(char *src)
{
__int64 v1; // rcx
__int64 v2; // rax
size_t v3; // rbx
int v4; // esi
char *v5; // rax
char *v6; // r8
char *v7; // rax

LODWORD(v2) = strlen(src);
v1 = 0x200000000801LL;
v2 = (int)v2;
while ( 1 )
{
v3 = (int)v2;
if ( (int)v2 <= 0 )
break;
v4 = (unsigned __int8)src[--v2];
if ( (unsigned __int8)(v4 - 47) <= 0x2Du )
{
if ( _bittest64(&v1, (unsigned int)(v4 - 47)) )
break;
}
}
v5 = (char *)malloc((int)v3 + 1);
v6 = v5;
if ( v5 )
{
v7 = strncpy(v5, src, v3);
v7[v3] = 0;
v6 = v7;
}
return v6;
}

original_code:
char *extractDir(char *pathName)
{
 char *dir;
 int len = strlen(pathName);
 while ((len-- > 0) &&
        (pathName[len] != '/') &&
        (pathName[len] != '\\') &&
        (pathName[len] != ':')) ;
 dir = malloc(++len + 1);
 if (dir)
 {
  strncpy(dir, pathName, len);
  dir[len] = 0;
 }
 return dir;
}

variable_types:
pathName
char *

variable_types: len int


extractName

decompiled_code:
char *__fastcall extractName(const char *a1)
{
int v1; // er12
int v3; // eax
size_t v4; // rdi
int v5; // ebx
__int64 v6; // rsi
const char *v7; // rdx
char *v8; // rax
char *v9; // r8

v1 = 0;
v3 = strlen(a1);
v4 = 2LL;
v5 = v3;
if ( v3 > 0 )
{
v6 = 0x200000000801LL;
v1 = v3;
v7 = &a1[v3 - 1];
do
{
if ( (unsigned __int8)(*v7 - 47) <= 0x2Du && _bittest64(&v6, (unsigned int)*(unsigned __int8 *)v7 - 47) )
{
v1 = v3 - v5;
v4 = v3 - v5 + 2;
goto LABEL_7;
}
--v7;
--v5;
}
while ( v5 );
v4 = v3 + 2;
}
LABEL_7:
v8 = (char *)malloc(v4);
v9 = v8;
if ( v8 )
v9 = strncpy(v8, &a1[v5], v1 + 1);
return v9;
}

canonical_decompiled_code:
char *__fastcall func3(const char *a1)
{
int v1; // er12
int v3; // eax
size_t v4; // rdi
int v5; // ebx
__int64 v6; // rsi
const char *v7; // rdx
char *v8; // rax
char *v9; // r8

v1 = 0;
v3 = strlen(a1);
v4 = 2LL;
v5 = v3;
if ( v3 > 0 )
{
v6 = 0x200000000801LL;
v1 = v3;
v7 = &a1[v3 - 1];
do
{
if ( (unsigned __int8)(*v7 - 47) <= 0x2Du && _bittest64(&v6, (unsigned int)*(unsigned __int8 *)v7 - 47) )
{
v1 = v3 - v5;
v4 = v3 - v5 + 2;
goto LABEL_7;
}
--v7;
--v5;
}
while ( v5 );
v4 = v3 + 2;
}
LABEL_7:
v8 = (char *)malloc(v4);
v9 = v8;
if ( v8 )
v9 = strncpy(v8, &a1[v5], v1 + 1);
return v9;
}

original_code:
char *extractName(char *pathName)
{
 char *name;
 int len = strlen(pathName);
 int slen = len;
 while ((len > 0) &&
        (pathName[len-1] != '/') &&
        (pathName[len-1] != '\\') &&
        (pathName[len-1] != ':')) len--;
 name = malloc(slen - len + 2);
 if (name)
  strncpy(name, &pathName[len], slen - len + 1);
 return name;
}

variable_types:
name
char *

variable_types: slen int


removeStartSpaces

decompiled_code:
char *__fastcall removeStartSpaces(char *dest)
{
unsigned __int64 v1; // rax
char *v2; // rsi
int v3; // edx
__int64 v4; // rcx

v1 = (unsigned __int8)*dest;
v2 = dest;
v3 = 0;
v4 = 0x100002600LL;
if ( !(_BYTE)v1 )
return dest;
while ( (unsigned __int8)v1 <= 0x20u && _bittest64(&v4, v1) )
{
v1 = (unsigned __int8)*++v2;
++v3;
if ( !(_BYTE)v1 )
return strcpy(dest, v2);
}
if ( !v3 )
return dest;
return strcpy(dest, v2);
}

canonical_decompiled_code:
char *__fastcall func4(char *dest)
{
unsigned __int64 v1; // rax
char *v2; // rsi
int v3; // edx
__int64 v4; // rcx

v1 = (unsigned __int8)*dest;
v2 = dest;
v3 = 0;
v4 = 0x100002600LL;
if ( !(_BYTE)v1 )
return dest;
while ( (unsigned __int8)v1 <= 0x20u && _bittest64(&v4, v1) )
{
v1 = (unsigned __int8)*++v2;
++v3;
if ( !(_BYTE)v1 )
return strcpy(dest, v2);
}
if ( !v3 )
return dest;
return strcpy(dest, v2);
}

original_code:
char *removeStartSpaces(char *sz)
{
 int i = 0;
 char ch;
 while (((ch = sz[i]) != 0) &&
        ((ch == ' ') || (ch == '\t') || (ch == '\n') || (ch == '\r'))) i++;
 if (i != 0) strcpy(sz, &sz[i]);
 return sz;
}

variable_types:
sz
char *

variable_types: i int

variable_types: ch char


removeLastSpaces

decompiled_code:
const char *__fastcall removeLastSpaces(const char *a1)
{
__int64 v1; // rax
__int64 v2; // rcx
unsigned __int64 v3; // rdx

LODWORD(v1) = strlen(a1) - 1;
if ( (int)v1 >= 0 )
{
v2 = 0x100002600LL;
v1 = (int)v1;
while ( 1 )
{
v3 = (unsigned __int8)a1[v1];
if ( (unsigned __int8)v3 > 0x20u || !_bittest64(&v2, v3) )
break;
a1[v1--] = 0;
if ( (int)v1 < 0 )
return a1;
}
}
return a1;
}

canonical_decompiled_code:
const char *__fastcall func5(const char *a1)
{
__int64 v1; // rax
__int64 v2; // rcx
unsigned __int64 v3; // rdx

LODWORD(v1) = strlen(a1) - 1;
if ( (int)v1 >= 0 )
{
v2 = 0x100002600LL;
v1 = (int)v1;
while ( 1 )
{
v3 = (unsigned __int8)a1[v1];
if ( (unsigned __int8)v3 > 0x20u || !_bittest64(&v2, v3) )
break;
a1[v1--] = 0;
if ( (int)v1 < 0 )
return a1;
}
}
return a1;
}

original_code:
char *removeLastSpaces(char *sz)
{
 int i = strlen(sz) - 1;
 char ch;
 while ((i >= 0) &&
        (((ch = sz[i]) == ' ') || (ch == '\t') ||
          (ch == '\n') || (ch == '\r'))) sz[i--] = 0;
 return sz;
}


Token

original_code:
int Token(char *sz, char *wordlist)
{
 int sp = 0;
 int tp = 0;
 int tl = 0;
 int wn = 1;
 while ((wordlist[tl] | wordlist[tl + 1]) != 0) tl++;
 while (tp <= tl)
  {
   if (wordlist[tp] == 0)
    {
     strcpy(sz, &sz[sp]);
     return wn;
    }
   if ((sz[sp] != 0) && (loCase(sz[sp]) == loCase(wordlist[tp])))
         { sp++; tp++; }
    else {
          sp = 0; wn++;
          while ((wordlist[tp++] != 0) && (tp < tl)) ;
         }
  }
 return 0;
}

variable_types:
wordlist
char *

variable_types: sp int

variable_types: tp int

variable_types: tl int

variable_types: wn int


GetToken

decompiled_code:
__int64 __fastcall GetToken(__int64 a1, int a2)
{
__int64 v2; // rdx
int i; // ecx
__int64 v4; // rax

if ( a2 <= 1 )
return a1;
LODWORD(v2) = 0;
for ( i = 1; i != a2; ++i )
{
v4 = (int)v2 + 1;
do
v2 = (int)v4++;
while ( *(_BYTE *)(a1 + v4 - 2) );
}
return a1 + v2;
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1, int a2)
{
__int64 v2; // rdx
int i; // ecx
__int64 v4; // rax

if ( a2 <= 1 )
return a1;
LODWORD(v2) = 0;
for ( i = 1; i != a2; ++i )
{
v4 = (int)v2 + 1;
do
v2 = (int)v4++;
while ( *(_BYTE *)(a1 + v4 - 2) );
}
return a1 + v2;
}

original_code:
char *GetToken(char *wordlist, int no)
{
 int i;
 int sp = 0;
 for (i = 1; i < no; i++)
  while (wordlist[sp++] != 0) ;
 return &wordlist[sp];
}

variable_types: no int


decVal

decompiled_code:
__int64 __fastcall decVal(char *dest)
{
int v1; // edx
char v2; // al
const char *v3; // rbx
size_t v4; // r13
int v5; // ebp
__int64 v6; // r12
size_t v7; // rdx

v1 = strlen(dest);
v2 = *dest;
if ( *dest == 43 )
{
v3 = dest + 1;
LODWORD(v4) = v1 - 1;
strncpy(dest, dest + 1, v1);
v2 = *dest;
if ( (unsigned __int8)(*dest - 48) > 9u )
return 0LL;
v5 = 0;
}
else
{
if ( v2 != 45 )
{
if ( (unsigned __int8)(v2 - 48) <= 9u )
{
v3 = dest + 1;
LODWORD(v4) = v1;
v5 = 0;
goto LABEL_5;
}
return 0LL;
}
v3 = dest + 1;
LODWORD(v4) = v1 - 1;
v5 = 1;
strncpy(dest, dest + 1, v1);
v2 = *dest;
if ( (unsigned __int8)(*dest - 48) > 9u )
return 0LL;
}
LABEL_5:
v4 = (int)v4;
v6 = 0LL;
do
{
v6 = (char)(v2 - 48) + 10 * v6;
v7 = v4--;
strncpy(dest, v3, v7);
v2 = *dest;
}
while ( (unsigned __int8)(*dest - 48) <= 9u );
if ( v5 )
v6 = -v6;
return v6;
}

canonical_decompiled_code:
__int64 __fastcall func8(char *dest)
{
int v1; // edx
char v2; // al
const char *v3; // rbx
size_t v4; // r13
int v5; // ebp
__int64 v6; // r12
size_t v7; // rdx

v1 = strlen(dest);
v2 = *dest;
if ( *dest == 43 )
{
v3 = dest + 1;
LODWORD(v4) = v1 - 1;
strncpy(dest, dest + 1, v1);
v2 = *dest;
if ( (unsigned __int8)(*dest - 48) > 9u )
return 0LL;
v5 = 0;
}
else
{
if ( v2 != 45 )
{
if ( (unsigned __int8)(v2 - 48) <= 9u )
{
v3 = dest + 1;
LODWORD(v4) = v1;
v5 = 0;
goto LABEL_5;
}
return 0LL;
}
v3 = dest + 1;
LODWORD(v4) = v1 - 1;
v5 = 1;
strncpy(dest, dest + 1, v1);
v2 = *dest;
if ( (unsigned __int8)(*dest - 48) > 9u )
return 0LL;
}
LABEL_5:
v4 = (int)v4;
v6 = 0LL;
do
{
v6 = (char)(v2 - 48) + 10 * v6;
v7 = v4--;
strncpy(dest, v3, v7);
v2 = *dest;
}
while ( (unsigned __int8)(*dest - 48) <= 9u );
if ( v5 )
v6 = -v6;
return v6;
}

original_code:
long decVal(char *s)
{
 long Value = 0;
 char ch;
 int sl = strlen(s);
 int sign = 0;
 switch (s[0])
 {
  case '-': sign = 1;
  case '+': strncpy(s, &s[1], sl--); break;
 }
 while (((ch = s[0]) >= '0') && (ch <= '9'))
  {
   Value = Value * 10 + (ch - '0');
   strncpy(s, &s[1], sl--);
  }
 return (sign ? -Value : Value);
}

variable_types:
s
char *

variable_types: Value long

variable_types: sl int

variable_types: sign int

return_type: long


hexChar

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

result = (unsigned int)(a1 + 48);
if ( (char)a1 >= 10 )
result = (unsigned int)(a1 + 55);
return result;
}

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

result = (unsigned int)(a1 + 48);
if ( (char)a1 >= 10 )
result = (unsigned int)(a1 + 55);
return result;
}

original_code:
char hexChar(char Val)
{
 return (Val > 9? Val - 10 + 'A' : Val + '0');
}

variable_types: Val char


hexVal

decompiled_code:
__int64 __fastcall hexVal(char *dest)
{
__int64 v1; // r13
size_t i; // rbx
__int64 v3; // r13
__int64 v4; // rax
char v5; // al

v1 = 0LL;
for ( i = (int)strlen(dest); ; --i )
{
v5 = upCase(*dest);
if ( (unsigned __int8)(v5 - 48) > 9u )
break;
v3 = 16 * v1;
v4 = (char)(v5 - 48);
LABEL_4:
v1 = v4 + v3;
strncpy(dest, dest + 1, i);
}
if ( (unsigned __int8)(v5 - 65) <= 5u )
{
v3 = 16 * v1;
v4 = (char)(v5 - 55);
goto LABEL_4;
}
return v1;
}

canonical_decompiled_code:
__int64 __fastcall func10(char *dest)
{
__int64 v1; // r13
size_t i; // rbx
__int64 v3; // r13
__int64 v4; // rax
char v5; // al

v1 = 0LL;
for ( i = (int)strlen(dest); ; --i )
{
v5 = func0(*dest);
if ( (unsigned __int8)(v5 - 48) > 9u )
break;
v3 = 16 * v1;
v4 = (char)(v5 - 48);
LABEL_4:
v1 = v4 + v3;
strncpy(dest, dest + 1, i);
}
if ( (unsigned __int8)(v5 - 65) <= 5u )
{
v3 = 16 * v1;
v4 = (char)(v5 - 55);
goto LABEL_4;
}
return v1;
}

original_code:
ulong hexVal(char *s)
{
 ulong Value = 0;
 char ch;
 int sl = strlen(s);
 while ((((ch = upCase(s[0])) >= '0') && (ch <= '9')) ||
        ((ch >= 'A') && (ch <= 'F')))
  {
   Value = (Value << 4) + (ch > '9'? ch - 'A' + 10 : ch - '0');
   strncpy(s, &s[1], sl--);
  }
 return Value;
}

canonical_original_code:
unsigned long hexVal(char *s)
{
 unsigned long Value = 0;
 char ch;
 int sl = strlen(s);
 while ((((ch = upCase(s[0])) >= '0') && (ch <= '9')) ||
        ((ch >= 'A') && (ch <= 'F')))
  {
   Value = (Value << 4) + (ch > '9'? ch - 'A' + 10 : ch - '0');
   strncpy(s, &s[1], sl--);
  }
 return Value;
}

variable_types:
Value
unsigned long

return_type: unsigned long


hexStr

decompiled_code:
__int64 __fastcall hexStr(char a1, int a2, __int64 a3)
{
__int64 v3; // r8
__int64 v5; // rsi
char v6; // al
__int64 v7; // r9
_BYTE *v8; // rcx

LOBYTE(v3) = a1;
if ( a2 )
{
v5 = a3 + a2 - 1 - (unsigned int)(a2 - 1);
while ( 1 )
{
v6 = hexChar(v3 & 0xF);
*v8 = v6;
if ( v8 == (_BYTE *)v5 )
break;
if ( !v3 )
return v7;
}
}
return a3;
}

canonical_decompiled_code:
__int64 __fastcall func11(char a1, int a2, __int64 a3)
{
__int64 v3; // r8
__int64 v5; // rsi
char v6; // al
__int64 v7; // r9
_BYTE *v8; // rcx

LOBYTE(v3) = a1;
if ( a2 )
{
v5 = a3 + a2 - 1 - (unsigned int)(a2 - 1);
while ( 1 )
{
v6 = func9(v3 & 0xF);
*v8 = v6;
if ( v8 == (_BYTE *)v5 )
break;
if ( !v3 )
return v7;
}
}
return a3;
}

original_code:
char *hexStr(ulong val, int nch, char *buff)
{
 char fch = 1;
 while (nch && (val | fch))
  {
   buff[--nch] = hexChar(val & 0x0F);
   val >>= 4;
   fch = 0;
  }
 return &buff[nch];
}

canonical_original_code:
char *hexStr(unsigned long val, int nch, char *buff)
{
 char fch = 1;
 while (nch && (val | fch))
  {
   buff[--nch] = hexChar(val & 0x0F);
   val >>= 4;
   fch = 0;
  }
 return &buff[nch];
}

variable_types:
val
unsigned long

variable_types: nch int

variable_types:
buff
char *

variable_types: fch char


strfirst

decompiled_code:
__int64 __fastcall strfirst(char a1, char *a2)
{
char v2; // dl
__int64 result; // rax

v2 = *a2;
result = 0LL;
if ( !*a2 )
return 0xFFFFFFFFLL;
while ( v2 != a1 )
{
v2 = a2[++result];
if ( !v2 )
return 0xFFFFFFFFLL;
}
return (unsigned int)result;
}

canonical_decompiled_code:
__int64 __fastcall func12(char a1, char *a2)
{
char v2; // dl
__int64 result; // rax

v2 = *a2;
result = 0LL;
if ( !*a2 )
return 0xFFFFFFFFLL;
while ( v2 != a1 )
{
v2 = a2[++result];
if ( !v2 )
return 0xFFFFFFFFLL;
}
return (unsigned int)result;
}

original_code:
int strfirst(char Ch, char *S)
{
 int pos = 0;
 while ((S[pos]) && (S[pos] != Ch)) pos++;
 if (!S[pos]) return -1; else return pos;
}

variable_types: Ch char

variable_types:
S
char *

variable_types: pos int


strlast

decompiled_code:
__int64 __fastcall strlast(char a1, const char *a2)
{
__int64 result; // rax
const char *v3; // rsi

result = (unsigned int)strlen(a2) - 1;
if ( (int)result >= 0 )
{
v3 = &a2[(int)result];
do
{
if ( *v3 == a1 )
break;
result = (unsigned int)(result - 1);
--v3;
}
while ( (_DWORD)result != -1 );
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func13(char a1, const char *a2)
{
__int64 result; // rax
const char *v3; // rsi

result = (unsigned int)strlen(a2) - 1;
if ( (int)result >= 0 )
{
v3 = &a2[(int)result];
do
{
if ( *v3 == a1 )
break;
result = (unsigned int)(result - 1);
--v3;
}
while ( (_DWORD)result != -1 );
}
return result;
}

original_code:
int strlast(char Ch, char *S)
{
 int pos = strlen(S) - 1;
 while ((pos >= 0) && (S[pos] != Ch)) pos--;
 return pos;
}


firstwordlen

decompiled_code:
__int64 __fastcall firstwordlen(_BYTE *a1)
{
__int64 v1; // rax
char v2; // dl
unsigned int v3; // er8

if ( (*a1 & 0xDF) == 0 || *a1 == 9 )
return 0LL;
v1 = 1LL;
do
{
v2 = a1[v1];
v3 = v1++;
}
while ( (v2 & 0xDF) != 0 && v2 != 9 );
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func14(_BYTE *a1)
{
__int64 v1; // rax
char v2; // dl
unsigned int v3; // er8

if ( (*a1 & 0xDF) == 0 || *a1 == 9 )
return 0LL;
v1 = 1LL;
do
{
v2 = a1[v1];
v3 = v1++;
}
while ( (v2 & 0xDF) != 0 && v2 != 9 );
return v3;
}

original_code:
int firstwordlen(char *S)
{
 int pos = 0;
 while ((S[pos]) && (S[pos] != ' ') && (S[pos] != '\t')) pos++;
 return pos;
}


strdel

decompiled_code:
size_t __fastcall strdel(const char *a1, int a2, int a3)
{
size_t result; // rax
char *v6; // rdi

result = strlen(a1);
if ( (int)result > a2 )
{
v6 = (char *)&a1[a2];
if ( a2 + a3 < (int)result )
result = (size_t)strcpy(v6, &a1[a2 + a3]);
else
*v6 = 0;
}
return result;
}

canonical_decompiled_code:
size_t __fastcall func15(const char *a1, int a2, int a3)
{
size_t result; // rax
char *v6; // rdi

result = strlen(a1);
if ( (int)result > a2 )
{
v6 = (char *)&a1[a2];
if ( a2 + a3 < (int)result )
result = (size_t)strcpy(v6, &a1[a2 + a3]);
else
*v6 = 0;
}
return result;
}

original_code:
void strdel(char *S, int start, int count)
{
 int len = strlen(S);
 if (start < len)
 {
  if (start + count < len)
   strcpy((char *)&S[start], (char *)&S[start + count]);
  else
   S[start] = 0;
 }
}

variable_types: start int

variable_types: count int

variable_types: len int


main

canonical_name: main

repo: OSLL/hwaddr-cache

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
const char *v3; // r8
unsigned __int64 v4; // r12
int v5; // eax
int v6; // ebp
int v7; // er12
char buf[4]; // [rsp+8h] [rbp-20h] BYREF
char v10[28]; // [rsp+Ch] [rbp-1Ch] BYREF

if ( argc <= 3 )
{
write(1, "too few arguments, command, remote and local ip expected\n", 0x39uLL);
v7 = 1;
}
else
{
v3 = argv[1];
if ( !strcmp("ref", v3) )
{
v4 = 1074331137LL;
}
else
{
v4 = 1074331138LL;
if ( strcmp("unref", v3) )
{
write(1, "unknown command", 0xFuLL);
return 1;
}
}
if ( inet_pton(2, argv[2], buf) <= 0 )
{
write(1, "cannot not parse destination ip address\n", 0x28uLL);
v7 = 1;
}
else if ( inet_pton(2, argv[3], v10) <= 0 )
{
write(1, "cannot not parse source ip address\n", 0x23uLL);
v7 = 1;
}
else
{
v5 = open("/proc/hwaddr/cache", 1);
v6 = v5;
if ( v5 == -1 )
{
write(1, "cannot open /proc/hwaddr/cache\n", 0x1FuLL);
v7 = 1;
}
else
{
v7 = ioctl(v5, v4, buf);
if ( v7 )
{
write(1, "cannot ioctl /proc/hwaddr/cache\n", 0x20uLL);
v7 = 1;
}
else
{
close(v6);
}
}
}
}
return v7;
}

original_code:
int main(int argc, char **argv)
{
 struct hwaddr_rfreq request;
 unsigned long command = 0;
 int fd = -1;
 if (argc < 4)
 {
  write(1, "too few arguments, command, remote and local ip expected\n", strlen("too few arguments, command, remote and local ip expected\n"));
  return 1;
 }
 if (!strcmp("ref", argv[1]))
  command = (((1U) << (((0 +8)+8)+14)) | (((0xFE)) << (0 +8)) | (((1)) << 0) | ((((sizeof(struct hwaddr_rfreq)))) << ((0 +8)+8)));
 else if (!strcmp("unref", argv[1]))
  command = (((1U) << (((0 +8)+8)+14)) | (((0xFE)) << (0 +8)) | (((2)) << 0) | ((((sizeof(struct hwaddr_rfreq)))) << ((0 +8)+8)));
 else
 {
  write(1, "unknown command", strlen("unknown command"));
  return 1;
 }
 if (inet_pton(2, argv[2], &request.remote) <= 0)
 {
  write(1, "cannot not parse destination ip address\n", strlen("cannot not parse destination ip address\n"));
  return 1;
 }
 if (inet_pton(2, argv[3], &request.local) <= 0)
 {
  write(1, "cannot not parse source ip address\n", strlen("cannot not parse source ip address\n"));
  return 1;
 }
 fd = open("/proc/hwaddr/cache", 01);
 if (fd == -1)
 {
  write(1, "cannot open /proc/hwaddr/cache\n", strlen("cannot open /proc/hwaddr/cache\n"));
  return 1;
 }
 if (ioctl(fd, command, &request))
 {
  write(1, "cannot ioctl /proc/hwaddr/cache\n", strlen("cannot ioctl /proc/hwaddr/cache\n"));
  return 1;
 }
 close(fd);
 return 0;
}

variable_types: argc int

variable_types:
argv
char **

variable_types: struct hwaddr_rfreq { struct in_addr { unsigned int s_addr; } remote; struct in_addr local; }

variable_types:
command
unsigned long

variable_types: fd int

user_defined_types: struct hwaddr_rfreq { struct in_addr remote; struct in_addr local; }


repo: OSLL/ioperf

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v3; // rbx
int v4; // edx
int v5; // ecx
int v6; // er8
int v7; // er9
int v8; // edx
int v9; // ecx
int v10; // er8
int v11; // er9
__int64 *v12; // rbx
__int64 v13; // rsi
int v14; // ebx
__int128 v16; // [rsp+0h] [rbp-A28h] BYREF
__int64 v17; // [rsp+10h] [rbp-A18h]
__int128 v18; // [rsp+20h] [rbp-A08h] BYREF
__int64 v19; // [rsp+30h] [rbp-9F8h]
__int64 v20[4]; // [rsp+40h] [rbp-9E8h] BYREF
__int64 v21[4]; // [rsp+60h] [rbp-9C8h] BYREF
__int64 v22[4]; // [rsp+80h] [rbp-9A8h] BYREF
char v23[2400]; // [rsp+A0h] [rbp-988h] BYREF
__int64 v24; // [rsp+A00h] [rbp-28h] BYREF

v3 = 0LL;
init(v23, argv, envp);
do
{
make_io_data(&v16, v3, 1LL, 1LL);
if ( (unsigned int)push_back((unsigned int)v23, v3, v4, v5, v6, v7, v16, v17) != 1 )
__assert_fail("push_back(pb, make_io_data(i,1,1)) == 1", "main.c", 0xEu, "main");
make_io_data(&v18, 99 - v3, 2LL, 2LL);
if ( (unsigned int)push_front((unsigned int)v23, 99 - (int)v3, v8, v9, v10, v11, v18, v19) != 1 )
__assert_fail("push_front(pb, make_io_data(99-i,2,2)) == 1", "main.c", 0xFu, "main");
++v3;
}
while ( v3 != 50 );
v12 = (__int64 *)v23;
printf("%d\n", v24);
do
{
v13 = *v12;
v12 += 3;
printf("%d ", v13);
}
while ( v12 != &v24 );
v14 = 0;
putchar(10);
do
{
while ( 1 )
{
pop_back(v20, v23);
printf("%d ", v20[0]);
if ( (v14 & 1) == 0 )
break;
++v14;
pop_back(v21, v23);
printf("%d ", v21[0]);
if ( v14 == 50 )
goto LABEL_11;
}
++v14;
pop_front(v22, v23);
printf("%d ", v22[0]);
}
while ( v14 != 50 );
LABEL_11:
putchar(10);
printf("%d\n", v24);
return 0;
}

original_code:
int main()
{
 buffer b;
 buffer * pb = &b;
 init(pb);
 int i = 0;
 for (; i != 50; ++i) {
  ((void) sizeof ((push_back(pb, make_io_data(i,1,1)) == 1) ? 1 : 0), __extension__ ({ if (push_back(pb, make_io_data(i,1,1)) == 1) ; else __assert_fail ("push_back(pb, make_io_data(i,1,1)) == 1", "main.c", 14, __extension__ __PRETTY_FUNCTION__); }));
  ((void) sizeof ((push_front(pb, make_io_data(99-i,2,2)) == 1) ? 1 : 0), __extension__ ({ if (push_front(pb, make_io_data(99-i,2,2)) == 1) ; else __assert_fail ("push_front(pb, make_io_data(99-i,2,2)) == 1", "main.c", 15, __extension__ __PRETTY_FUNCTION__); }));
 }
 printf("%d\n", b.size);
 i = 0;
 for (; i != 100; ++i) {
  printf("%d ", b.data[i].start);
 }
 printf("\n");
 i = 0;
 for (; i != 50; ++i) {
  printf("%d ", pop_back(pb).start);
  if (i%2)
   printf("%d ", pop_back(pb).start);
  else
   printf("%d ", pop_front(pb).start);
 }
 printf("\n");
 printf("%d\n", b.size);
 return 0;
}

canonical_original_code:
int main()
{
 struct buffer b;
 struct buffer *pb = &b;
 init(pb);
 int i = 0;
 for (; i != 50; ++i) {
  ((void) sizeof ((push_back(pb, make_io_data(i,1,1)) == 1) ? 1 : 0), __extension__ ({ if (push_back(pb, make_io_data(i,1,1)) == 1) ; else __assert_fail ("push_back(pb, make_io_data(i,1,1)) == 1", "main.c", 14, __extension__ __PRETTY_FUNCTION__); }));
  ((void) sizeof ((push_front(pb, make_io_data(99-i,2,2)) == 1) ? 1 : 0), __extension__ ({ if (push_front(pb, make_io_data(99-i,2,2)) == 1) ; else __assert_fail ("push_front(pb, make_io_data(99-i,2,2)) == 1", "main.c", 15, __extension__ __PRETTY_FUNCTION__); }));
 }
 printf("%d\n", b.size);
 i = 0;
 for (; i != 100; ++i) {
  printf("%d ", b.data[i].start);
 }
 printf("\n");
 i = 0;
 for (; i != 50; ++i) {
  printf("%d ", pop_back(pb).start);
  if (i%2)
   printf("%d ", pop_back(pb).start);
  else
   printf("%d ", pop_front(pb).start);
 }
 printf("\n");
 printf("%d\n", b.size);
 return 0;
}

variable_types: struct buffer { struct io_data { unsigned long start; unsigned long end; unsigned long id; } data[-1]; unsigned long size; int head; int tail; } *

variable_types: i int

user_defined_types: struct buffer { struct io_data data[-1]; unsigned long size; int head; int tail; }


init

decompiled_code:
__int64 __fastcall init(_QWORD *a1)
{
unsigned __int64 v2; // rdi
__int64 result; // rax

*a1 = 0LL;
v2 = (unsigned __int64)(a1 + 1);
result = 0LL;
*(_QWORD *)(v2 + 2384) = 0LL;
memset((void *)(v2 & 0xFFFFFFFFFFFFFFF8LL), 0, 8 * (((unsigned int)a1 - (v2 & 0xFFFFFFF8) + 2400) >> 3));
a1[300] = 0LL;
a1[301] = 99LL;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func8(_QWORD *a1)
{
unsigned __int64 v2; // rdi
__int64 result; // rax

*a1 = 0LL;
v2 = (unsigned __int64)(a1 + 1);
result = 0LL;
*(_QWORD *)(v2 + 2384) = 0LL;
memset((void *)(v2 & 0xFFFFFFFFFFFFFFF8LL), 0, 8 * (((unsigned int)a1 - (v2 & 0xFFFFFFF8) + 2400) >> 3));
a1[300] = 0LL;
a1[301] = 99LL;
return result;
}

original_code:
void init(buffer *d)
{
 d->size = 0;
 memset(d->data, 0, ((size_t)100) * sizeof(io_data));
 d->tail = 0;
 d->head = ((size_t)100) - 1;
}

canonical_original_code:
void init(struct buffer *d)
{
 d->size = 0;
 memset(d->data, 0, ((unsigned long)100) * sizeof(io_data));
 d->tail = 0;
 d->head = ((unsigned long)100) - 1;
}

user_defined_types: struct io_data { unsigned long start; unsigned long end; unsigned long id; }


original_code:
int push_back(buffer *d, io_data element)
{
 if (d->size >= ((size_t)100)) {
  return 0;
 }
 d->tail = mod(d->tail - 1, ((size_t)100));
 d->data[d->tail] = element;
 ++d->size;
 return 1;
}

canonical_original_code:
int push_back(struct buffer *d, struct io_data element)
{
 if (d->size >= ((unsigned long)100)) {
  return 0;
 }
 d->tail = mod(d->tail - 1, ((unsigned long)100));
 d->data[d->tail] = element;
 ++d->size;
 return 1;
}

variable_types:
element
struct io_data


original_code:
int push_front(buffer *d, io_data element)
{
 if (d->size >= ((size_t)100)) {
  return 0;
 }
 d->head = mod(d->head + 1, ((size_t)100));
 d->data[d->head] = element;
 ++d->size;
 return 1;
}

canonical_original_code:
int push_front(struct buffer *d, struct io_data element)
{
 if (d->size >= ((unsigned long)100)) {
  return 0;
 }
 d->head = mod(d->head + 1, ((unsigned long)100));
 d->data[d->head] = element;
 ++d->size;
 return 1;
}


front

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

result = 0LL;
if ( *(_QWORD *)(a1 + 2400) )
result = a1 + 24LL * *(int *)(a1 + 2408);
return result;
}

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

result = 0LL;
if ( *(_QWORD *)(a1 + 2400) )
result = a1 + 24LL * *(int *)(a1 + 2408);
return result;
}

original_code:
io_data * front(buffer *d)
{
 return (d->size == 0) ? ((void *)0) : &(d->data[d->head]);
}

canonical_original_code:
struct io_data *front(struct buffer *d)
{
 return (d->size == 0) ? ((void *)0) : &(d->data[d->head]);
}

variable_types: struct buffer { struct io_data data[-1]; unsigned long size; int head; int tail; } *

return_type: struct io_data { unsigned long start; unsigned long end; unsigned long id; } *


back

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

result = 0LL;
if ( *(_QWORD *)(a1 + 2400) )
result = a1 + 24LL * *(int *)(a1 + 2412);
return result;
}

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

result = 0LL;
if ( *(_QWORD *)(a1 + 2400) )
result = a1 + 24LL * *(int *)(a1 + 2412);
return result;
}

original_code:
io_data * back(buffer *d)
{
 return (d->size == 0) ? ((void *)0) : &(d->data[d->tail]);
}

canonical_original_code:
struct io_data *back(struct buffer *d)
{
 return (d->size == 0) ? ((void *)0) : &(d->data[d->tail]);
}


repo: OSLL/pmover

decompiled_code:
void test_fini(void)
{
char v0[4104]; // [rsp+0h] [rbp-1008h] BYREF

if ( getpid() == master_pid )
{
snprintf(v0, 0x1000uLL, "%s%s", outfile, ".inprogress");
rename(v0, outfile);
unlink(pidfile);
}
}

canonical_decompiled_code:
void func1(void)
{
char v0[4104]; // [rsp+0h] [rbp-1008h] BYREF

if ( getpid() == master_pid )
{
snprintf(v0, 0x1000uLL, "%s%s", outfile, ".inprogress");
rename(v0, outfile);
unlink(pidfile);
}
}

original_code:
static void test_fini(void)
{
 char path[4096];
 if (getpid() != master_pid)
  return;
 snprintf(path, sizeof(path), "%s%s", outfile, ".inprogress");
 rename(path, outfile);
 unlink(pidfile);
}

canonical_original_code:
static void test_fini()
{
 char path[4096];
 if (getpid() != master_pid)
  return;
 snprintf(path, sizeof(path), "%s%s", outfile, ".inprogress");
 rename(path, outfile);
 unlink(pidfile);
}

variable_types:
path
char [4096]


decompiled_code:
int redir_stdfds()
{
int v0; // eax
int v1; // ebp
int result; // eax
int *v3; // rax

v0 = open("/dev/null", 2);
if ( v0 < 0 )
{
v3 = _errno_location();
test_msg("ERR: %s:%d: Can't open /dev/null: %m\n (errno = %d)\n", "test.c", 83LL, (unsigned int)*v3);
exit(1);
}
v1 = v0;
result = dup2(v0, 0);
if ( v1 > 2 )
result = close(v1);
return result;
}

canonical_decompiled_code:
int func3()
{
int v0; // eax
int v1; // ebp
int result; // eax
int *v3; // rax

v0 = open("/dev/null", 2);
if ( v0 < 0 )
{
v3 = _errno_location();
test_msg("ERR: %s:%d: Can't open /dev/null: %m\n (errno = %d)\n", "test.c", 83LL, (unsigned int)*v3);
exit(1);
}
v1 = v0;
result = dup2(v0, 0);
if ( v1 > 2 )
result = close(v1);
return result;
}

original_code:
static void redir_stdfds()
{
 int nullfd;
 nullfd = open("/dev/null", 02);
 if (nullfd < 0) {
  test_msg("ERR: %s:%d: " "Can't open /dev/null: %m\n" " (errno = %d)\n", "test.c", 83, (*__errno_location ()));
  exit(1);
 }
 dup2(nullfd, 0);
 if (nullfd > 2)
  close(nullfd);
}

variable_types: nullfd int


decompiled_code:
__pid_t __fastcall test_fork_id(int a1)
{
int v1; // ebx
__pid_t result; // eax

v1 = a1;
result = fork();
if ( a1 < 0 )
v1 = ++proc_id_cur;
if ( !result )
proc_id = v1;
return result;
}

canonical_decompiled_code:
__pid_t __fastcall func4(int a1)
{
int v1; // ebx
__pid_t result; // eax

v1 = a1;
result = fork();
if ( a1 < 0 )
v1 = ++proc_id_cur;
if ( !result )
proc_id = v1;
return result;
}

original_code:
int test_fork_id(int id)
{
 pid_t pid = fork();
 if (id < 0)
  id = ++proc_id_cur;
 if (pid == 0)
  proc_id = id;
 return pid;
}

canonical_original_code:
int test_fork_id(int id)
{
 int pid = fork();
 if (id < 0)
  id = ++proc_id_cur;
 if (pid == 0)
  proc_id = id;
 return pid;
}

variable_types: id int

variable_types: pid int


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

if ( !access(outfile, 0) || *_errno_location() != 2 )
{
fprintf(stderr, "Output file %s appears to exist, aborting\n", outfile);
exit(1);
}
if ( atexit(test_fini) )
{
fwrite("Can't register exit function\n", 1uLL, 0x1DuLL, stderr);
exit(1);
}
result = test_log_init(outfile, ".inprogress");
if ( (_DWORD)result )
exit(1);
return result;
}

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

if ( !access(outfile, 0) || *_errno_location() != 2 )
{
fprintf(stderr, "Output file %s appears to exist, aborting\n", outfile);
exit(1);
}
if ( atexit(test_fini) )
{
fwrite("Can't register exit function\n", 1uLL, 0x1DuLL, stderr);
exit(1);
}
result = test_log_init(outfile, ".inprogress");
if ( (_DWORD)result )
exit(1);
return result;
}

original_code:
void setup_outfile()
{
 if (!access(outfile, 0) || (*__errno_location ()) != 2) {
  fprintf(stderr, "Output file %s appears to exist, aborting\n",
   outfile);
  exit(1);
 }
 if (atexit(test_fini)) {
  fprintf(stderr, "Can't register exit function\n");
  exit(1);
 }
 if (test_log_init(outfile, ".inprogress"))
  exit(1);
}


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

parseargs();
result = test_log_init(outfile, ".external");
if ( (_DWORD)result )
exit(1);
return result;
}

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

parseargs();
result = test_log_init(outfile, ".external");
if ( (_DWORD)result )
exit(1);
return result;
}

original_code:
void test_ext_init(int argc, char **argv)
{
 parseargs(argc, argv);
 if (test_log_init(outfile, ".external"))
  exit(1);
}


decompiled_code:
int test_daemon()
{
int v0; // eax
int result; // eax
int *v2; // rax

v0 = getppid();
if ( v0 <= 1 )
{
v2 = _errno_location();
test_msg("ERR: %s:%d: Test orphaned\n (errno = %d)\n", "test.c", 318LL, (unsigned int)*v2);
LABEL_5:
kill(0, 9);
exit(1);
}
result = kill(v0, 15);
if ( result )
goto LABEL_5;
return result;
}

canonical_decompiled_code:
int func7()
{
int v0; // eax
int result; // eax
int *v2; // rax

v0 = getppid();
if ( v0 <= 1 )
{
v2 = _errno_location();
test_msg("ERR: %s:%d: Test orphaned\n (errno = %d)\n", "test.c", 318LL, (unsigned int)*v2);
LABEL_5:
kill(0, 9);
exit(1);
}
result = kill(v0, 15);
if ( result )
goto LABEL_5;
return result;
}

original_code:
void test_daemon()
{
 pid_t ppid;
 ppid = getppid();
 if (ppid <= 1) {
  test_msg("ERR: %s:%d: " "Test orphaned\n" " (errno = %d)\n", "test.c", 318, (*__errno_location ()));
  goto out;
 }
 if (kill(ppid, 15))
  goto out;
 return;
out:
 kill(0, 9);
 exit(1);
}

canonical_original_code:
void test_daemon()
{
 int ppid;
 ppid = getppid();
 if (ppid <= 1) {
  test_msg("ERR: %s:%d: " "Test orphaned\n" " (errno = %d)\n", "test.c", 318, (*__errno_location ()));
  goto out;
 }
 if (kill(ppid, 15))
  goto out;
 return;
out:
 kill(0, 9);
 exit(1);
}

variable_types: ppid int


decompiled_code:
_BOOL8 test_go()
{
return sig_received == 0;
}

canonical_decompiled_code:
_BOOL8 func8()
{
return sig_received == 0;
}

original_code:
int test_go(void)
{
 return !sig_received;
}

canonical_original_code:
int test_go()
{
 return !sig_received;
}


decompiled_code:
int test_waitsig()
{
sigset_t v1; // [rsp+0h] [rbp-108h] BYREF
sigset_t oset; // [rsp+80h] [rbp-88h] BYREF

sigemptyset(&v1);
sigaddset(&v1, 15);
sigaddset(&v1, 17);
sigprocmask(0, &v1, &oset);
while ( !sig_received )
sigsuspend(&oset);
return sigprocmask(1, &v1, 0LL);
}

canonical_decompiled_code:
int func9()
{
sigset_t v1; // [rsp+0h] [rbp-108h] BYREF
sigset_t oset; // [rsp+80h] [rbp-88h] BYREF

sigemptyset(&v1);
sigaddset(&v1, 15);
sigaddset(&v1, 17);
sigprocmask(0, &v1, &oset);
while ( !sig_received )
sigsuspend(&oset);
return sigprocmask(1, &v1, 0LL);
}

original_code:
void test_waitsig(void)
{
 sigset_t mask, oldmask;
 sigemptyset(&mask);
 sigaddset(&mask, 15);
 sigaddset(&mask, 17);
 sigprocmask(0, &mask, &oldmask);
 while (!sig_received)
  sigsuspend (&oldmask);
 sigprocmask (1, &mask, ((void *)0));
}

canonical_original_code:
void test_waitsig()
{
 struct __sigset_t mask; struct __sigset_t oldmask;
 sigemptyset(&mask);
 sigaddset(&mask, 15);
 sigaddset(&mask, 17);
 sigprocmask(0, &mask, &oldmask);
 while (!sig_received)
  sigsuspend (&oldmask);
 sigprocmask (1, &mask, ((void *)0));
}

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


decompiled_code:
void __fastcall sig_hand(int a1)
{
sig_received = a1;
}

canonical_decompiled_code:
void __fastcall func0(int a1)
{
sig_received = a1;
}

original_code:
static void sig_hand(int signo)
{
 sig_received = signo;
}

variable_types: signo int


decompiled_code:
void do_stop()
{
stop = 1;
}

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

original_code:
static void do_stop(int sig)
{
 stop = 1;
}

variable_types: sig int


decompiled_code:
int prepare_buf()
{
_BYTE *v0; // rbx
char *v1; // rbp
int result; // eax

v0 = buf;
v1 = (char *)buf + 0x4000;
do
{
result = rand();
*v0++ = result;
}
while ( v0 != v1 );
return result;
}

canonical_decompiled_code:
int func1()
{
_BYTE *v0; // rbx
char *v1; // rbp
int result; // eax

v0 = buf;
v1 = (char *)buf + 0x4000;
do
{
result = rand();
*v0++ = result;
}
while ( v0 != v1 );
return result;
}

original_code:
static void prepare_buf(void)
{
 int i;
 for (i = 0; i < (16 * 1024); i++)
  buf[i] = rand();
}

canonical_original_code:
static void prepare_buf()
{
 int i;
 for (i = 0; i < (16 * 1024); i++)
  buf[i] = rand();
}


decompiled_code:
__int64 __fastcall fill_file(int fd)
{
int i; // ebx
int v2; // eax

if ( lseek(fd, 0LL, 0) == -1 )
return 4294967294LL;
for ( i = 0; i != 0x4000; i += v2 )
{
v2 = write(fd, (char *)buf + i, 0x4000 - i);
if ( v2 <= 0 )
return 0xFFFFFFFFLL;
}
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func2(int fd)
{
int i; // ebx
int v2; // eax

if ( lseek(fd, 0LL, 0) == -1 )
return 4294967294LL;
for ( i = 0; i != 0x4000; i += v2 )
{
v2 = write(fd, (char *)buf + i, 0x4000 - i);
if ( v2 <= 0 )
return 0xFFFFFFFFLL;
}
return 0LL;
}

original_code:
static int fill_file(int fd)
{
 int rv, wr;
 if (lseek(fd, 0, 0) == -1)
  return -2;
 wr = 0;
 while (1) {
  rv = write(fd, buf + wr, (16 * 1024) - wr);
  if (rv <= 0)
   return -1;
  wr += rv;
  if (wr == (16 * 1024))
   break;
 }
 return 0;
}

canonical_original_code:
static int fill_file(int fd)
{
 int rv; int wr;
 if (lseek(fd, 0, 0) == -1)
  return -2;
 wr = 0;
 while (1) {
  rv = write(fd, buf + wr, (16 * 1024) - wr);
  if (rv <= 0)
   return -1;
  wr += rv;
  if (wr == (16 * 1024))
   break;
 }
 return 0;
}

variable_types: rv int

variable_types: wr int


decompiled_code:
int __fastcall check_file(int fd)
{
int v1; // ebp
int result; // eax
int v3; // eax
int v4; // ebx
_BYTE v5[1048]; // [rsp+0h] [rbp-418h] BYREF

if ( lseek(fd, 0LL, 0) == -1 )
return -2;
v1 = 0;
while ( 1 )
{
v3 = read(fd, v5, 0x400uLL);
v4 = v3;
if ( v3 <= 0 )
return -1;
result = memcmp((char *)buf + v1, v5, v3);
if ( result )
break;
v1 += v4;
if ( v1 == 0x4000 )
return result;
}
return 1;
}

canonical_decompiled_code:
int __fastcall func3(int fd)
{
int v1; // ebp
int result; // eax
int v3; // eax
int v4; // ebx
_BYTE v5[1048]; // [rsp+0h] [rbp-418h] BYREF

if ( lseek(fd, 0LL, 0) == -1 )
return -2;
v1 = 0;
while ( 1 )
{
v3 = read(fd, v5, 0x400uLL);
v4 = v3;
if ( v3 <= 0 )
return -1;
result = memcmp((char *)buf + v1, v5, v3);
if ( result )
break;
v1 += v4;
if ( v1 == 0x4000 )
return result;
}
return 1;
}

original_code:
static int check_file(int fd)
{
 char rbuf[1024];
 int rv, rd;
 if (lseek(fd, 0, 0) == -1)
  return -2;
 rd = 0;
 while (1) {
  rv = read(fd, rbuf, 1024);
  if (rv <= 0)
   return -1;
  if (memcmp(buf + rd, rbuf, rv))
   return 1;
  rd += rv;
  if (rd == (16 * 1024))
   break;
 }
 return 0;
}

canonical_original_code:
static int check_file(int fd)
{
 char rbuf[1024];
 int rv; int rd;
 if (lseek(fd, 0, 0) == -1)
  return -2;
 rd = 0;
 while (1) {
  rv = read(fd, rbuf, 1024);
  if (rv <= 0)
   return -1;
  if (memcmp(buf + rd, rbuf, rv))
   return 1;
  rd += rv;
  if (rd == (16 * 1024))
   break;
 }
 return 0;
}

variable_types:
rbuf
char [1024]

variable_types: rd int


decompiled_code:
void __fastcall __noreturn chew_some_file(unsigned int a1)
{
int v1; // er12
int v2; // ebp
int v3; // eax
int v4; // eax
int v5; // ebp
int *v6; // rax
char s[10]; // [rsp+6h] [rbp-42h] BYREF
char file[56]; // [rsp+10h] [rbp-38h] BYREF

v1 = 2;
buf = mmap(0LL, 0x4000uLL, 3, 34, 0, 0LL);
if ( buf == (void *)-1LL )
goto LABEL_12;
sprintf(s, "chew%d", a1);
v2 = open(s, 194, 438LL);
if ( v2 == -1 )
{
v1 = 3;
}
else
{
while ( !stop )
{
prepare_buf();
v3 = fill_file(v2);
if ( v3 == -2 )
goto LABEL_11;
if ( v3 == -1 )
{
v1 = 4;
goto LABEL_12;
}
if ( fsync(v2) == -1 || fsync(v2) == -1 )
{
v1 = 6;
goto LABEL_12;
}
v4 = check_file(v2);
v1 = v4;
switch ( v4 )
{
case -1:
v1 = 5;
goto LABEL_12;
case 1:
sprintf(file, "standard_%s", s);
v5 = open(file, 577, 438LL);
if ( write(v5, buf, 0x4000uLL) != 0x4000 )
{
v6 = _errno_location();
test_msg("ERR: %s:%d: can't write %s: %m\n (errno = %d)\n", "file_read.c", 164LL, file, (unsigned int)*v6);
}
close(v5);
LABEL_12:
exit(v1);
case -2:
LABEL_11:
v1 = 7;
goto LABEL_12;
}
}
v1 = 0;
close(v2);
unlink(s);
}
munmap(buf, 0x4000uLL);
goto LABEL_12;
}

canonical_decompiled_code:
void __fastcall __noreturn func4(unsigned int a1)
{
int v1; // er12
int v2; // ebp
int v3; // eax
int v4; // eax
int v5; // ebp
int *v6; // rax
char s[10]; // [rsp+6h] [rbp-42h] BYREF
char file[56]; // [rsp+10h] [rbp-38h] BYREF

v1 = 2;
buf = mmap(0LL, 0x4000uLL, 3, 34, 0, 0LL);
if ( buf == (void *)-1LL )
goto LABEL_12;
sprintf(s, "chew%d", a1);
v2 = open(s, 194, 438LL);
if ( v2 == -1 )
{
v1 = 3;
}
else
{
while ( !stop )
{
func1();
v3 = func2(v2);
if ( v3 == -2 )
goto LABEL_11;
if ( v3 == -1 )
{
v1 = 4;
goto LABEL_12;
}
if ( fsync(v2) == -1 || fsync(v2) == -1 )
{
v1 = 6;
goto LABEL_12;
}
v4 = func3(v2);
v1 = v4;
switch ( v4 )
{
case -1:
v1 = 5;
goto LABEL_12;
case 1:
sprintf(file, "standard_%s", s);
v5 = open(file, 577, 438LL);
if ( write(v5, buf, 0x4000uLL) != 0x4000 )
{
v6 = _errno_location();
test_msg("ERR: %s:%d: can't write %s: %m\n (errno = %d)\n", "file_read.c", 164LL, file, (unsigned int)*v6);
}
close(v5);
LABEL_12:
exit(v1);
case -2:
LABEL_11:
v1 = 7;
goto LABEL_12;
}
}
v1 = 0;
close(v2);
unlink(s);
}
munmap(buf, 0x4000uLL);
goto LABEL_12;
}

original_code:
static void chew_some_file(int num)
{
 char filename[10];
 int fd, rv;
 buf = mmap(((void *)0), (16 * 1024), 0x1 | 0x2,
   0x02 | 0x20, 0, 0);
 rv = MMAP_FAILED;
 if (buf == ((void *) -1))
  goto out_exit;
 sprintf(filename, "chew%d", num);
 fd = open(filename, 0100 | 0200 | 02, 0666);
 rv = OPEN_FAILED;
 if (fd == -1)
  goto out_unmap;
 while (!stop) {
  prepare_buf();
  switch (fill_file(fd)) {
  case -1:
   rv = WRITE_FAILED;
   goto out_exit;
  case -2:
   rv = SEEK_FAILED;
   goto out_exit;
  }
  if (fsync(fd) == -1) {
   rv = FSYNC_FAILED;
   goto out_exit;
  }
  if (fsync(fd) == -1) {
   rv = FSYNC_FAILED;
   goto out_exit;
  }
  switch (check_file(fd)) {
  case -1:
   rv = READ_FAILED;
   goto out_exit;
  case -2:
   rv = SEEK_FAILED;
   goto out_exit;
  case 1:
   rv = FILE_CORRUPTED;
   int fd1;
   char str[32];
   sprintf(str, "standard_%s", filename);
   fd1 = open(str, 01 | 0100 | 01000, 0666);
   if (write(fd1, buf, (16 * 1024)) != (16 * 1024))
    test_msg("ERR: %s:%d: " "can't write %s: %m\n" " (errno = %d)\n", "file_read.c", 164, str, (*__errno_location ()));
   close(fd1);
   goto out_exit;
  }
 }
 rv = SUCCESS;
 close(fd);
 unlink(filename);
out_unmap:
 munmap(buf, (16 * 1024));
out_exit:
 exit(rv);
}

canonical_original_code:
static void chew_some_file(int num)
{
 char filename[10];
 int fd; int rv;
 buf = mmap(((void *)0), (16 * 1024), 0x1 | 0x2,
   0x02 | 0x20, 0, 0);
 rv = MMAP_FAILED;
 if (buf == ((void *) -1))
  goto out_exit;
 sprintf(filename, "chew%d", num);
 fd = open(filename, 0100 | 0200 | 02, 0666);
 rv = OPEN_FAILED;
 if (fd == -1)
  goto out_unmap;
 while (!stop) {
  prepare_buf();
  switch (fill_file(fd)) {
  case -1:
   rv = WRITE_FAILED;
   goto out_exit;
  case -2:
   rv = SEEK_FAILED;
   goto out_exit;
  }
  if (fsync(fd) == -1) {
   rv = FSYNC_FAILED;
   goto out_exit;
  }
  if (fsync(fd) == -1) {
   rv = FSYNC_FAILED;
   goto out_exit;
  }
  switch (check_file(fd)) {
  case -1:
   rv = READ_FAILED;
   goto out_exit;
  case -2:
   rv = SEEK_FAILED;
   goto out_exit;
  case 1:
   rv = FILE_CORRUPTED;
   int fd1;
   char str[32];
   sprintf(str, "standard_%s", filename);
   fd1 = open(str, 01 | 0100 | 01000, 0666);
   if (write(fd1, buf, (16 * 1024)) != (16 * 1024))
    test_msg("ERR: %s:%d: " "can't write %s: %m\n" " (errno = %d)\n", "file_read.c", 164, str, (*__errno_location ()));
   close(fd1);
   goto out_exit;
  }
 }
 rv = SUCCESS;
 close(fd);
 unlink(filename);
out_unmap:
 munmap(buf, (16 * 1024));
out_exit:
 exit(rv);
}

variable_types: num int

variable_types:
filename
char [10]

variable_types: fd int

variable_types:
str
char [32]


decompiled_code:
__int64 sys_gettid()
{
return syscall(186LL);
}

canonical_decompiled_code:
__int64 func0()
{
return syscall(186LL);
}

original_code:
static long sys_gettid(void)
{
 return syscall(186);
}

canonical_original_code:
static long sys_gettid()
{
 return syscall(186);
}


decompiled_code:
int __fastcall task_waiter_init(int *a1)
{
__int64 v1; // rdx
int result; // eax
int *v3; // rax

datagen(a1, 8LL, 0LL);
v1 = (0x100001000011LL * (unsigned __int128)*(unsigned __int64 *)a1) >> 64;
*(_QWORD *)a1 -= 0xFFFFF * ((((unsigned __int64)(*(_QWORD *)a1 - v1) >> 1) + v1) >> 19);
result = pipe(a1 + 2);
if ( result )
{
v3 = _errno_location();
test_msg("ERR: %s:%d: task_waiter_init failed: %m (errno = %d)\n", "lock.c", 26LL, (unsigned int)*v3);
exit(1);
}
return result;
}

canonical_decompiled_code:
int __fastcall func1(int *a1)
{
__int64 v1; // rdx
int result; // eax
int *v3; // rax

datagen(a1, 8LL, 0LL);
v1 = (0x100001000011LL * (unsigned __int128)*(unsigned __int64 *)a1) >> 64;
*(_QWORD *)a1 -= 0xFFFFF * ((((unsigned __int64)(*(_QWORD *)a1 - v1) >> 1) + v1) >> 19);
result = pipe(a1 + 2);
if ( result )
{
v3 = _errno_location();
test_msg("ERR: %s:%d: task_waiter_init failed: %m (errno = %d)\n", "lock.c", 26LL, (unsigned int)*v3);
exit(1);
}
return result;
}

original_code:
void task_waiter_init(task_waiter_t *t)
{
 datagen((void *)&t->seed, sizeof(t->seed), ((void *)0));
 t->seed = t->seed % 0x0fffff;
 if (pipe(t->pipes)) {
  test_msg("ERR: %s:%d: " "task_waiter_init failed: %m" " (errno = %d)\n", "lock.c", 26, (*__errno_location ()));
  exit(1);
 }
}

canonical_original_code:
void task_waiter_init(struct task_waiter_t *t)
{
 datagen((void *)&t->seed, sizeof(t->seed), ((void *)0));
 t->seed = t->seed % 0x0fffff;
 if (pipe(t->pipes)) {
  test_msg("ERR: %s:%d: " "task_waiter_init failed: %m" " (errno = %d)\n", "lock.c", 26, (*__errno_location ()));
  exit(1);
 }
}

variable_types: struct task_waiter_t { unsigned long seed; int pipes[2]; } *


decompiled_code:
int __fastcall task_waiter_fini(__int64 a1)
{
close(*(_DWORD *)(a1 + 8));
return close(*(_DWORD *)(a1 + 12));
}

canonical_decompiled_code:
int __fastcall func2(__int64 a1)
{
close(*(_DWORD *)(a1 + 8));
return close(*(_DWORD *)(a1 + 12));
}

original_code:
void task_waiter_fini(task_waiter_t *t)
{
 close(t->pipes[0]);
 close(t->pipes[1]);
}

canonical_original_code:
void task_waiter_fini(struct task_waiter_t *t)
{
 close(t->pipes[0]);
 close(t->pipes[1]);
}

user_defined_types: struct task_waiter_t { unsigned long seed; int pipes[2]; }


decompiled_code:
ssize_t __fastcall task_waiter_wait4(__int64 a1, int a2)
{
ssize_t result; // rax
int *v3; // rbx
int buf; // [rsp+0h] [rbp-3Ch] BYREF
struct timespec requested_time; // [rsp+4h] [rbp-38h] BYREF
struct timespec remaining; // [rsp+14h] [rbp-28h] BYREF

requested_time.tv_sec = 0LL;
requested_time.tv_nsec = 0xFFFFFLL;
remaining = 0LL;
while ( 1 )
{
result = read(*(_DWORD *)(a1 + 8), &buf, 4uLL);
if ( result != 4 )
{
LABEL_7:
v3 = _errno_location();
test_msg("ERR: %s:%d: task_waiter_wait4 failed: %m (errno = %d)\n", "lock.c", 72LL, (unsigned int)*v3);
exit(*v3);
}
if ( buf == a2 )
return result;
if ( write(*(_DWORD *)(a1 + 12), &buf, 4uLL) != 4 )
goto LABEL_7;
nanosleep(&requested_time, &remaining);
requested_time.tv_nsec += *(_QWORD *)a1;
}
}

canonical_decompiled_code:
ssize_t __fastcall func3(__int64 a1, int a2)
{
ssize_t result; // rax
int *v3; // rbx
int buf; // [rsp+0h] [rbp-3Ch] BYREF
struct timespec requested_time; // [rsp+4h] [rbp-38h] BYREF
struct timespec remaining; // [rsp+14h] [rbp-28h] BYREF

requested_time.tv_sec = 0LL;
requested_time.tv_nsec = 0xFFFFFLL;
remaining = 0LL;
while ( 1 )
{
result = read(*(_DWORD *)(a1 + 8), &buf, 4uLL);
if ( result != 4 )
{
LABEL_7:
v3 = _errno_location();
test_msg("ERR: %s:%d: task_waiter_wait4 failed: %m (errno = %d)\n", "lock.c", 72LL, (unsigned int)*v3);
exit(*v3);
}
if ( buf == a2 )
return result;
if ( write(*(_DWORD *)(a1 + 12), &buf, 4uLL) != 4 )
goto LABEL_7;
nanosleep(&requested_time, &remaining);
requested_time.tv_nsec += *(_QWORD *)a1;
}
}

original_code:
void task_waiter_wait4(task_waiter_t *t, unsigned int lockid)
{
 struct timespec req = { .tv_nsec = 0x0fffff, };
 struct timespec rem = { };
 unsigned int v;
 for (;;) {
  if (read(t->pipes[0], &v, sizeof(v)) != sizeof(v))
   goto err;
  if (v != lockid) {
   if (write(t->pipes[1], &v, sizeof(v)) != sizeof(v))
    goto err;
   nanosleep(&req, &rem);
   req.tv_nsec += t->seed;
  } else
   break;
 }
 return;
err:
 test_msg("ERR: %s:%d: " "task_waiter_wait4 failed: %m" " (errno = %d)\n", "lock.c", 72, (*__errno_location ()));
 exit((*__errno_location ()));
}

canonical_original_code:
void task_waiter_wait4(struct task_waiter_t *t, unsigned int lockid)
{
 struct timespec req = { .tv_nsec = 0x0fffff, };
 struct timespec rem = { };
 unsigned int v;
 for (;;) {
  if (read(t->pipes[0], &v, sizeof(v)) != sizeof(v))
   goto err;
  if (v != lockid) {
   if (write(t->pipes[1], &v, sizeof(v)) != sizeof(v))
    goto err;
   nanosleep(&req, &rem);
   req.tv_nsec += t->seed;
  } else
   break;
 }
 return;
err:
 test_msg("ERR: %s:%d: " "task_waiter_wait4 failed: %m" " (errno = %d)\n", "lock.c", 72, (*__errno_location ()));
 exit((*__errno_location ()));
}

variable_types:
lockid
unsigned int

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

variable_types:
v
unsigned int


decompiled_code:
ssize_t __fastcall task_waiter_complete(__int64 a1, int a2)
{
int v2; // edi
ssize_t result; // rax
int *v4; // rax
int buf[3]; // [rsp+Ch] [rbp-Ch] BYREF

v2 = *(_DWORD *)(a1 + 12);
buf[0] = a2;
result = write(v2, buf, 4uLL);
if ( result != 4 )
{
v4 = _errno_location();
test_msg("ERR: %s:%d: task_waiter_complete failed: %m (errno = %d)\n", "lock.c", 79LL, (unsigned int)*v4);
exit(1);
}
return result;
}

canonical_decompiled_code:
ssize_t __fastcall func4(__int64 a1, int a2)
{
int v2; // edi
ssize_t result; // rax
int *v4; // rax
int buf[3]; // [rsp+Ch] [rbp-Ch] BYREF

v2 = *(_DWORD *)(a1 + 12);
buf[0] = a2;
result = write(v2, buf, 4uLL);
if ( result != 4 )
{
v4 = _errno_location();
test_msg("ERR: %s:%d: task_waiter_complete failed: %m (errno = %d)\n", "lock.c", 79LL, (unsigned int)*v4);
exit(1);
}
return result;
}

original_code:
void task_waiter_complete(task_waiter_t *t, unsigned int lockid)
{
 if (write(t->pipes[1], &lockid, sizeof(lockid)) != sizeof(lockid)) {
  test_msg("ERR: %s:%d: " "task_waiter_complete failed: %m" " (errno = %d)\n", "lock.c", 79, (*__errno_location ()));
  exit(1);
 }
}

canonical_original_code:
void task_waiter_complete(struct task_waiter_t *t, unsigned int lockid)
{
 if (write(t->pipes[1], &lockid, sizeof(lockid)) != sizeof(lockid)) {
  test_msg("ERR: %s:%d: " "task_waiter_complete failed: %m" " (errno = %d)\n", "lock.c", 79, (*__errno_location ()));
  exit(1);
 }
}


decompiled_code:
ssize_t __fastcall task_waiter_complete_current(__int64 a1)
{
int v1; // eax

v1 = sys_gettid();
return task_waiter_complete(a1, v1);
}

canonical_decompiled_code:
ssize_t __fastcall func5(__int64 a1)
{
int v1; // eax

v1 = func0();
return func4(a1, v1);
}

original_code:
void task_waiter_complete_current(task_waiter_t *t)
{
 return task_waiter_complete(t, (int)sys_gettid());
}

canonical_original_code:
void task_waiter_complete_current(struct task_waiter_t *t)
{
 return task_waiter_complete(t, (int)sys_gettid());
}


decompiled_code:
__int64 __fastcall check_sem_by_key(key_t a1)
{
int v1; // eax
int v2; // ebp
__int64 result; // rax
int *v4; // rbp
int *v5; // rbp
struct sembuf v6; // [rsp+Eh] [rbp-1Ah] BYREF
__int64 v7; // [rsp+14h] [rbp-14h] BYREF
int v8; // [rsp+1Ch] [rbp-Ch]

v7 = 0LL;
v8 = 1;
*(_DWORD *)&v6.sem_num = -65536;
v6.sem_flg = 0;
v1 = semget(a1, 1, 511);
if ( v1 == -1 )
{
v4 = _errno_location();
test_msg("FAIL: %s:%d: Can't get sem (errno = %d)\n", "sem.c", 61LL, (unsigned int)*v4);
result = (unsigned int)-*v4;
}
else
{
v2 = v1;
if ( semctl(v1, 0, 12) < 0 )
{
v5 = _errno_location();
test_msg("FAIL: %s:%d: Failed to get sem value (errno = %d)\n", "sem.c", 67LL, (unsigned int)*v5);
result = (unsigned int)-*v5;
}
else
{
result = sem_test_constprop_0(v2, (struct sembuf *)&v7, &v6, 2);
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(key_t a1)
{
int v1; // eax
int v2; // ebp
__int64 result; // rax
int *v4; // rbp
int *v5; // rbp
struct sembuf v6; // [rsp+Eh] [rbp-1Ah] BYREF
__int64 v7; // [rsp+14h] [rbp-14h] BYREF
int v8; // [rsp+1Ch] [rbp-Ch]

v7 = 0LL;
v8 = 1;
*(_DWORD *)&v6.sem_num = -65536;
v6.sem_flg = 0;
v1 = semget(a1, 1, 511);
if ( v1 == -1 )
{
v4 = _errno_location();
test_msg("FAIL: %s:%d: Can't get sem (errno = %d)\n", "sem.c", 61LL, (unsigned int)*v4);
result = (unsigned int)-*v4;
}
else
{
v2 = v1;
if ( semctl(v1, 0, 12) < 0 )
{
v5 = _errno_location();
test_msg("FAIL: %s:%d: Failed to get sem value (errno = %d)\n", "sem.c", 67LL, (unsigned int)*v5);
result = (unsigned int)-*v5;
}
else
{
result = func0(v2, (struct sembuf *)&v7, &v6, 2);
}
}
return result;
}

original_code:
static int check_sem_by_key(int key)
{
 int id;
 struct sembuf lock[2] = {
  {
  .sem_num = 0,
  .sem_op = 0,
  .sem_flg = 0,
  },
  {
  .sem_num = 0,
  .sem_op = 1,
  .sem_flg = 0,
  },
 };
 struct sembuf unlock[1] = {
  {
  .sem_num = 0,
  .sem_op = -1,
  .sem_flg = 0,
  }
 };
 int val;
 id = semget(key, 1, 0777);
 if (id == -1) {
  test_msg("FAIL: %s:%d: " "Can't get sem" " (errno = %d)\n", "sem.c", 61, (*__errno_location ()));
  return -(*__errno_location ());
 }
 val = semctl(id, 0, 12);
 if (val < 0) {
  test_msg("FAIL: %s:%d: " "Failed to get sem value" " (errno = %d)\n", "sem.c", 67, (*__errno_location ()));
  return -(*__errno_location ());
 }
 return sem_test(id, lock, unlock,
   sizeof(lock)/sizeof(struct sembuf),
   sizeof(unlock)/sizeof(struct sembuf));
}

variable_types: key int

variable_types: id int

variable_types: struct sembuf { unsigned short sem_num; short sem_op; short sem_flg; } [2]

variable_types: struct sembuf { unsigned short sem_num; short sem_op; short sem_flg; } [1]

variable_types: val int


decompiled_code:
__int64 __fastcall check_sem_by_id(int semid, unsigned int a2)
{
int v2; // eax
unsigned int v3; // er12
__int64 result; // rax
int *v5; // rbx
int *v6; // rax
struct sembuf v7; // [rsp+4h] [rbp-24h] BYREF
struct sembuf v8; // [rsp+Ah] [rbp-1Eh] BYREF

v7.sem_num = 0;
v7.sem_op = a2;
v7.sem_flg = 0;
v8.sem_op = -2 * a2;
v8.sem_flg = 0;
v8.sem_num = 0;
v2 = semctl(semid, 0, 12);
if ( v2 < 0 )
{
v5 = _errno_location();
test_msg("FAIL: %s:%d: Failed to get sem value (errno = %d)\n", "sem.c", 96LL, (unsigned int)*v5);
result = (unsigned int)-*v5;
}
else
{
v3 = v2;
if ( a2 == v2 )
{
result = sem_test_constprop_0(semid, &v7, &v8, 1);
}
else
{
v6 = _errno_location();
test_msg(
"FAIL: %s:%d: Sem has wrong value: %d instead of %d\n (errno = %d)\n",
"sem.c",
100LL,
v3,
a2,
(unsigned int)*v6);
result = 4294967282LL;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(int semid, unsigned int a2)
{
int v2; // eax
unsigned int v3; // er12
__int64 result; // rax
int *v5; // rbx
int *v6; // rax
struct sembuf v7; // [rsp+4h] [rbp-24h] BYREF
struct sembuf v8; // [rsp+Ah] [rbp-1Eh] BYREF

v7.sem_num = 0;
v7.sem_op = a2;
v7.sem_flg = 0;
v8.sem_op = -2 * a2;
v8.sem_flg = 0;
v8.sem_num = 0;
v2 = semctl(semid, 0, 12);
if ( v2 < 0 )
{
v5 = _errno_location();
test_msg("FAIL: %s:%d: Failed to get sem value (errno = %d)\n", "sem.c", 96LL, (unsigned int)*v5);
result = (unsigned int)-*v5;
}
else
{
v3 = v2;
if ( a2 == v2 )
{
result = func0(semid, &v7, &v8, 1);
}
else
{
v6 = _errno_location();
test_msg(
"FAIL: %s:%d: Sem has wrong value: %d instead of %d\n (errno = %d)\n",
"sem.c",
100LL,
v3,
a2,
(unsigned int)*v6);
result = 4294967282LL;
}
}
return result;
}

original_code:
static int check_sem_by_id(int id, int val)
{
 int curr;
 struct sembuf lock[] = {
  {
  .sem_num = 0,
  .sem_op = val,
  .sem_flg = 0,
  },
 };
 struct sembuf unlock[] = {
  {
  .sem_num = 0,
  .sem_op = - val * 2,
  .sem_flg = 0,
  }
 };
 curr = semctl(id, 0, 12);
 if (curr < 0) {
  test_msg("FAIL: %s:%d: " "Failed to get sem value" " (errno = %d)\n", "sem.c", 96, (*__errno_location ()));
  return -(*__errno_location ());
 }
 if (curr != val) {
  test_msg("FAIL: %s:%d: " "Sem has wrong value: %d instead of %d\n" " (errno = %d)\n", "sem.c", 100, curr, val, (*__errno_location ()));
  return -14;
 }
 return sem_test(id, lock, unlock,
   sizeof(lock)/sizeof(struct sembuf),
   sizeof(unlock)/sizeof(struct sembuf));
}

variable_types: curr int

variable_types: struct sembuf { unsigned short sem_num; short sem_op; short sem_flg; } []


decompiled_code:
__int64 __fastcall test_fn(__int64 a1, const char **a2)
{
unsigned int v2; // er12
char v3; // r13
int v4; // eax
unsigned int v5; // er13
int v6; // ebp
int v7; // eax
unsigned int v8; // er12
int *v10; // rax
unsigned int *v11; // r13
int *v12; // rax

v2 = ftok(*a2, 89063453);
if ( v2 == -1 )
{
v12 = _errno_location();
test_msg("ERR: %s:%d: Can't make key (errno = %d)\n", "sem.c", 115LL, (unsigned int)*v12);
return v2;
}
v3 = lrand48();
v4 = semget(v2, 1, 2047);
v5 = v3 & 7;
v6 = v4;
if ( v4 == -1 )
{
v10 = _errno_location();
v2 = 1;
test_msg("ERR: %s:%d: Can't get sem (errno = %d)\n", "sem.c", 124LL, (unsigned int)*v10);
}
else
{
if ( semctl(v4, 0, 16, v5) == -1 )
{
v11 = (unsigned int *)_errno_location();
test_msg("ERR: %s:%d: Can't init sem (errno = %d)\n", "sem.c", 129LL, *v11);
}
else
{
test_daemon();
test_waitsig();
if ( (int)check_sem_by_id(v6, v5) < 0 )
{
v11 = (unsigned int *)_errno_location();
test_msg("FAIL: %s:%d: Check sem by id failed (errno = %d)\n", "sem.c", 139LL, *v11);
}
else if ( (int)check_sem_by_key(v2) < 0 )
{
v11 = (unsigned int *)_errno_location();
test_msg("FAIL: %s:%d: Check sem by key failed (errno = %d)\n", "sem.c", 144LL, *v11);
}
else
{
v7 = semctl(v6, 0, 12);
v8 = v7;
if ( v7 < 0 )
{
v11 = (unsigned int *)_errno_location();
test_msg("FAIL: %s:%d: Failed to get sem value (errno = %d)\n", "sem.c", 151LL, *v11);
}
else
{
if ( !v7 )
{
if ( semctl(v6, 1, 0) >= 0 )
{
test_msg("PASS\n");
return v8;
}
v2 = 1;
v11 = (unsigned int *)_errno_location();
goto LABEL_15;
}
v11 = (unsigned int *)_errno_location();
test_msg("FAIL: %s:%d: Non-zero sem value: %d (errno = %d)\n", "sem.c", 156LL, v8, *v11);
}
}
}
v2 = 1;
if ( semctl(v6, 1, 0) < 0 )
{
v2 = 2;
LABEL_15:
test_msg("FAIL: %s:%d: Destroy sem failed (errno = %d)\n", "sem.c", 163LL, *v11);
return v2;
}
}
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, const char **a2)
{
unsigned int v2; // er12
char v3; // r13
int v4; // eax
unsigned int v5; // er13
int v6; // ebp
int v7; // eax
unsigned int v8; // er12
int *v10; // rax
unsigned int *v11; // r13
int *v12; // rax

v2 = ftok(*a2, 89063453);
if ( v2 == -1 )
{
v12 = _errno_location();
test_msg("ERR: %s:%d: Can't make key (errno = %d)\n", "sem.c", 115LL, (unsigned int)*v12);
return v2;
}
v3 = lrand48();
v4 = semget(v2, 1, 2047);
v5 = v3 & 7;
v6 = v4;
if ( v4 == -1 )
{
v10 = _errno_location();
v2 = 1;
test_msg("ERR: %s:%d: Can't get sem (errno = %d)\n", "sem.c", 124LL, (unsigned int)*v10);
}
else
{
if ( semctl(v4, 0, 16, v5) == -1 )
{
v11 = (unsigned int *)_errno_location();
test_msg("ERR: %s:%d: Can't init sem (errno = %d)\n", "sem.c", 129LL, *v11);
}
else
{
test_daemon();
test_waitsig();
if ( (int)func2(v6, v5) < 0 )
{
v11 = (unsigned int *)_errno_location();
test_msg("FAIL: %s:%d: Check sem by id failed (errno = %d)\n", "sem.c", 139LL, *v11);
}
else if ( (int)func1(v2) < 0 )
{
v11 = (unsigned int *)_errno_location();
test_msg("FAIL: %s:%d: Check sem by key failed (errno = %d)\n", "sem.c", 144LL, *v11);
}
else
{
v7 = semctl(v6, 0, 12);
v8 = v7;
if ( v7 < 0 )
{
v11 = (unsigned int *)_errno_location();
test_msg("FAIL: %s:%d: Failed to get sem value (errno = %d)\n", "sem.c", 151LL, *v11);
}
else
{
if ( !v7 )
{
if ( semctl(v6, 1, 0) >= 0 )
{
test_msg("PASS\n");
return v8;
}
v2 = 1;
v11 = (unsigned int *)_errno_location();
goto LABEL_15;
}
v11 = (unsigned int *)_errno_location();
test_msg("FAIL: %s:%d: Non-zero sem value: %d (errno = %d)\n", "sem.c", 156LL, v8, *v11);
}
}
}
v2 = 1;
if ( semctl(v6, 1, 0) < 0 )
{
v2 = 2;
LABEL_15:
test_msg("FAIL: %s:%d: Destroy sem failed (errno = %d)\n", "sem.c", 163LL, *v11);
return v2;
}
}
return v2;
}

original_code:
static int test_fn(int argc, char **argv)
{
 int id, key, val;
 int ret, fail_count = 0;
 key = ftok(argv[0], 89063453);
 if (key == -1) {
  test_msg("ERR: %s:%d: " "Can't make key" " (errno = %d)\n", "sem.c", 115, (*__errno_location ()));
  return -1;
 }
 val = lrand48() & 0x7;
 id = semget(key, 1, 0777 | 01000 | 02000);
 if (id == -1) {
  fail_count++;
  test_msg("ERR: %s:%d: " "Can't get sem" " (errno = %d)\n", "sem.c", 124, (*__errno_location ()));
  goto out;
 }
 if (semctl(id, 0, 16, val) == -1) {
  fail_count++;
  test_msg("ERR: %s:%d: " "Can't init sem" " (errno = %d)\n", "sem.c", 129, (*__errno_location ()));
  goto out_destroy;
 }
 test_daemon();
 test_waitsig();
 ret = check_sem_by_id(id, val);
 if (ret < 0) {
  fail_count++;
  test_msg("FAIL: %s:%d: " "Check sem by id failed" " (errno = %d)\n", "sem.c", 139, (*__errno_location ()));
  goto out_destroy;
 }
 if (check_sem_by_key(key) < 0) {
  test_msg("FAIL: %s:%d: " "Check sem by key failed" " (errno = %d)\n", "sem.c", 144, (*__errno_location ()));
  fail_count++;
  goto out_destroy;
 }
 val = semctl(id, 0, 12);
 if (val < 0) {
  test_msg("FAIL: %s:%d: " "Failed to get sem value" " (errno = %d)\n", "sem.c", 151, (*__errno_location ()));
  fail_count++;
  goto out_destroy;
 }
 if (val != 0) {
  test_msg("FAIL: %s:%d: " "Non-zero sem value: %d" " (errno = %d)\n", "sem.c", 156, val, (*__errno_location ()));
  fail_count++;
 }
out_destroy:
 ret = semctl(id, 1, 0);
 if (ret < 0) {
  test_msg("FAIL: %s:%d: " "Destroy sem failed" " (errno = %d)\n", "sem.c", 163, (*__errno_location ()));
  fail_count++;
 }
out:
 if (fail_count == 0)
  test_msg("PASS\n");
 return fail_count;
}

canonical_original_code:
static int test_fn(int argc, char **argv)
{
 int id; int key; int val;
 int ret; int fail_count = 0;
 key = ftok(argv[0], 89063453);
 if (key == -1) {
  test_msg("ERR: %s:%d: " "Can't make key" " (errno = %d)\n", "sem.c", 115, (*__errno_location ()));
  return -1;
 }
 val = lrand48() & 0x7;
 id = semget(key, 1, 0777 | 01000 | 02000);
 if (id == -1) {
  fail_count++;
  test_msg("ERR: %s:%d: " "Can't get sem" " (errno = %d)\n", "sem.c", 124, (*__errno_location ()));
  goto out;
 }
 if (semctl(id, 0, 16, val) == -1) {
  fail_count++;
  test_msg("ERR: %s:%d: " "Can't init sem" " (errno = %d)\n", "sem.c", 129, (*__errno_location ()));
  goto out_destroy;
 }
 test_daemon();
 test_waitsig();
 ret = check_sem_by_id(id, val);
 if (ret < 0) {
  fail_count++;
  test_msg("FAIL: %s:%d: " "Check sem by id failed" " (errno = %d)\n", "sem.c", 139, (*__errno_location ()));
  goto out_destroy;
 }
 if (check_sem_by_key(key) < 0) {
  test_msg("FAIL: %s:%d: " "Check sem by key failed" " (errno = %d)\n", "sem.c", 144, (*__errno_location ()));
  fail_count++;
  goto out_destroy;
 }
 val = semctl(id, 0, 12);
 if (val < 0) {
  test_msg("FAIL: %s:%d: " "Failed to get sem value" " (errno = %d)\n", "sem.c", 151, (*__errno_location ()));
  fail_count++;
  goto out_destroy;
 }
 if (val != 0) {
  test_msg("FAIL: %s:%d: " "Non-zero sem value: %d" " (errno = %d)\n", "sem.c", 156, val, (*__errno_location ()));
  fail_count++;
 }
out_destroy:
 ret = semctl(id, 1, 0);
 if (ret < 0) {
  test_msg("FAIL: %s:%d: " "Destroy sem failed" " (errno = %d)\n", "sem.c", 163, (*__errno_location ()));
  fail_count++;
 }
out:
 if (fail_count == 0)
  test_msg("PASS\n");
 return fail_count;
}

variable_types: argc int

variable_types:
argv
char **

variable_types: ret int


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
test_init_ns(argc, argv, 0x8000000LL, test_fn);
return 0;
}

original_code:
int main(int argc, char **argv)
{
 test_init_ns(argc, argv, 0x08000000, test_fn);
 return 0;
}


decompiled_code:
__int64 chk_proc_sse()
{
int v1; // [rsp+0h] [rbp-10h] BYREF
int v2; // [rsp+4h] [rbp-Ch] BYREF
int v3; // [rsp+8h] [rbp-8h] BYREF
int v4; // [rsp+Ch] [rbp-4h] BYREF

cpuid_constprop_0(&v1, &v2, &v3, &v4);
return v4 & 0x2000000;
}

canonical_decompiled_code:
__int64 func3()
{
int v1; // [rsp+0h] [rbp-10h] BYREF
int v2; // [rsp+4h] [rbp-Ch] BYREF
int v3; // [rsp+8h] [rbp-8h] BYREF
int v4; // [rsp+Ch] [rbp-4h] BYREF

func0(&v1, &v2, &v3, &v4);
return v4 & 0x2000000;
}

original_code:
int chk_proc_sse(void)
{
 unsigned int eax, ebx, ecx, edx;
 cpuid(1, &eax, &ebx, &ecx, &edx);
 return edx & (1 << 25);
}

canonical_original_code:
int chk_proc_sse()
{
 unsigned int eax; unsigned int ebx; unsigned int ecx; unsigned int edx;
 cpuid(1, &eax, &ebx, &ecx, &edx);
 return edx & (1 << 25);
}

variable_types:
eax
unsigned int

variable_types:
ebx
unsigned int

variable_types:
ecx
unsigned int

variable_types:
edx
unsigned int


decompiled_code:
__int64 __fastcall parse_opt_bool(const char *a1, _DWORD *a2)
{
int v2; // er9
__int64 result; // rax

if ( !a1
|| (v2 = *(unsigned __int8 *)a1, v2 == 111) && a1[1] == 110 && !a1[2]
|| !strcmp(a1, "yes")
|| !strcmp(a1, "true") )
{
*a2 = 1;
result = 0LL;
}
else if ( !strcmp(a1, "off") || v2 == 110 && a1[1] == 111 && !a1[2] || !strcmp(a1, "false") )
{
*a2 = 0;
result = 0LL;
}
else
{
result = 4294967274LL;
}
return result;
}

original_code:
int parse_opt_bool(char *param, void *arg)
{
 if (param == ((void *)0) ||
     !strcmp(param, "on") ||
     !strcmp(param, "yes") ||
     !strcmp(param, "true")) {
  * (int *) arg = 1;
  return 0;
 }
 if (!strcmp(param, "off") ||
     !strcmp(param, "no") ||
     !strcmp(param, "false")) {
  * (int *) arg = 0;
  return 0;
 }
 return -22;
}

variable_types:
param
char *

variable_types:
arg
void *


prdoc

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

if ( test_doc )
result = fprintf(stderr, "%s\n", (const char *)test_doc);
if ( test_author )
result = fprintf(stderr, "Author: %s\n", (const char *)test_author);
return result;
}

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

if ( test_doc )
result = fprintf(stderr, "%s\n", (const char *)test_doc);
if ( test_author )
result = fprintf(stderr, "Author: %s\n", (const char *)test_author);
return result;
}

original_code:
static void prdoc(void)
{
 if (test_doc)
  fprintf(stderr, "%s\n", test_doc);
 if (test_author)
  fprintf(stderr, "Author: %s\n", test_author);
}

canonical_original_code:
static void prdoc()
{
 if (test_doc)
  fprintf(stderr, "%s\n", test_doc);
 if (test_author)
  fprintf(stderr, "Author: %s\n", test_author);
}


printopt

decompiled_code:
int __fastcall printopt(__int64 a1)
{
const char *v1; // rdx
const char *v2; // r9

v1 = (const char *)&unk_55B;
v2 = "]";
if ( *(_DWORD *)(a1 + 24) )
v2 = (const char *)&unk_55B;
if ( !*(_DWORD *)(a1 + 24) )
v1 = "[";
return fprintf(stderr, " %s--%s=%s%s\t%s\n", v1, *(_QWORD *)a1, *(_QWORD *)(a1 + 8), v2, *(_QWORD *)(a1 + 16));
}

canonical_decompiled_code:
int __fastcall func2(__int64 a1)
{
const char *v1; // rdx
const char *v2; // r9

v1 = (const char *)&unk_55B;
v2 = "]";
if ( *(_DWORD *)(a1 + 24) )
v2 = (const char *)&unk_55B;
if ( !*(_DWORD *)(a1 + 24) )
v1 = "[";
return fprintf(stderr, " %s--%s=%s%s\t%s\n", v1, *(_QWORD *)a1, *(_QWORD *)(a1 + 8), v2, *(_QWORD *)(a1 + 16));
}

original_code:
static void printopt(const struct long_opt *opt)
{
 const char *obracket = "", *cbracket = "";
 if (!opt->is_required) {
  obracket = "[";
  cbracket = "]";
 }
 fprintf(stderr, "  %s--%s=%s%s\t%s\n",
  obracket, opt->name, opt->type, cbracket, opt->doc);
}

canonical_original_code:
static void printopt(struct long_opt *opt)
{
 char *obracket = ""; char *cbracket = "";
 if (!opt->is_required) {
  obracket = "[";
  cbracket = "]";
 }
 fprintf(stderr, "  %s--%s=%s%s\t%s\n",
  obracket, opt->name, opt->type, cbracket, opt->doc);
}

variable_types: struct long_opt { char *name; char *type; char *doc; int is_required; int (*parse_opt)(char *arg, void *value); void *value; struct long_opt *next; } *

variable_types:
obracket
char *

variable_types:
cbracket
char *


helpexit

decompiled_code:
void __noreturn helpexit()
{
__int64 i; // rbx

fwrite("Usage:\n", 1uLL, 7uLL, stderr);
for ( i = opt_head; i; i = *(_QWORD *)(i + 48) )
printopt(i);
exit(1);
}

canonical_decompiled_code:
void __noreturn func3()
{
__int64 i; // rbx

fwrite("Usage:\n", 1uLL, 7uLL, stderr);
for ( i = opt_head; i; i = *(_QWORD *)(i + 48) )
func2(i);
exit(1);
}

original_code:
static void helpexit(void)
{
 struct long_opt *opt;
 fputs("Usage:\n", stderr);
 for (opt = opt_head; opt; opt = opt->next)
  printopt(opt);
 exit(1);
}

canonical_original_code:
static void helpexit()
{
 struct long_opt *opt;
 fputs("Usage:\n", stderr);
 for (opt = opt_head; opt; opt = opt->next)
  printopt(opt);
 exit(1);
}

user_defined_types: struct long_opt { char *name; char *type; char *doc; int is_required; int (*parse_opt)(char *arg, void *value); void *value; struct long_opt *next; }


decompiled_code:
__int64 __fastcall parse_opt_int(const char *a1, _DWORD *a2)
{
__int64 result; // rax
char *endptr; // [rsp+0h] [rbp-10h] BYREF

if ( !a1 || !*a1 )
return 4294967274LL;
*a2 = strtol(a1, &endptr, 0);
if ( *endptr )
result = 4294967274LL;
else
result = 0LL;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func5(const char *a1, _DWORD *a2)
{
__int64 result; // rax
char *endptr; // [rsp+0h] [rbp-10h] BYREF

if ( !a1 || !*a1 )
return 4294967274LL;
*a2 = strtol(a1, &endptr, 0);
if ( *endptr )
result = 4294967274LL;
else
result = 0LL;
return result;
}

original_code:
int parse_opt_int(char *param, void *arg)
{
 char *tail;
 if (param == ((void *)0) || param[0] == '\0')
  return -22;
 * (int *) arg = strtol(param, &tail, 0);
 if (tail[0] != '\0')
  return -22;
 return 0;
}

variable_types:
tail
char *


decompiled_code:
__int64 __fastcall parse_opt_uint(const char *a1, _DWORD *a2)
{
__int64 result; // rax
char *endptr; // [rsp+0h] [rbp-10h] BYREF

if ( !a1 || !*a1 )
return 4294967274LL;
*a2 = strtoul(a1, &endptr, 0);
if ( *endptr )
result = 4294967274LL;
else
result = 0LL;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func6(const char *a1, _DWORD *a2)
{
__int64 result; // rax
char *endptr; // [rsp+0h] [rbp-10h] BYREF

if ( !a1 || !*a1 )
return 4294967274LL;
*a2 = strtoul(a1, &endptr, 0);
if ( *endptr )
result = 4294967274LL;
else
result = 0LL;
return result;
}

original_code:
int parse_opt_uint(char *param, void *arg)
{
 char *tail;
 if (param == ((void *)0) || param[0] == '\0')
  return -22;
 * (unsigned int *) arg = strtoul(param, &tail, 0);
 if (tail[0] != '\0')
  return -22;
 return 0;
}


decompiled_code:
__int64 __fastcall parse_opt_long(const char *a1, __int64 *a2)
{
__int64 result; // rax
char *endptr; // [rsp+0h] [rbp-10h] BYREF

if ( !a1 || !*a1 )
return 4294967274LL;
*a2 = strtol(a1, &endptr, 0);
if ( *endptr )
result = 4294967274LL;
else
result = 0LL;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func7(const char *a1, __int64 *a2)
{
__int64 result; // rax
char *endptr; // [rsp+0h] [rbp-10h] BYREF

if ( !a1 || !*a1 )
return 4294967274LL;
*a2 = strtol(a1, &endptr, 0);
if ( *endptr )
result = 4294967274LL;
else
result = 0LL;
return result;
}

original_code:
int parse_opt_long(char *param, void *arg)
{
 char *tail;
 if (param == ((void *)0) || param[0] == '\0')
  return -22;
 * (long *) arg = strtol(param, &tail, 0);
 if (tail[0] != '\0')
  return -22;
 return 0;
}