original_code:
void
ldap_build_filter(
 char *filtbuf,
 ber_len_t buflen,
 const char *pattern,
 const char *prefix,
 const char *suffix,
 const char *attr,
 const char *value,
 char **valwords )
{
 const char *p;
 char *f;
 size_t slen;
 int i, wordcount, wordnum, endwordnum;
 if ( valwords == ((void *)0) ) {
     wordcount = 0;
 } else {
     for ( wordcount = 0; valwords[ wordcount ] != ((void *)0); ++wordcount ) {
  ;
     }
 }
 f = filtbuf;
 if ( prefix != ((void *)0) ) {
     strcpy( f, prefix );
     f += strlen( prefix );
 }
 for ( p = pattern; *p != '\0'; ++p ) {
     if ( *p == '%' ) {
  ++p;
  if ( *p == 'v' ) {
      if ( ( ((unsigned char) p[1]) >= '0' && ((unsigned char) p[1]) <= '9' )) {
   ++p;
   wordnum = *p - '1';
   if ( *(p+1) == '-' ) {
       ++p;
       if ( ( ((unsigned char) p[1]) >= '0' && ((unsigned char) p[1]) <= '9' )) {
    ++p;
    endwordnum = *p - '1';
    if ( endwordnum > wordcount - 1 ) {
        endwordnum = wordcount - 1;
    }
       } else {
    endwordnum = wordcount - 1;
       }
   } else {
       endwordnum = wordnum;
   }
   if ( wordcount > 0 ) {
       for ( i = wordnum; i <= endwordnum; ++i ) {
    if ( i > wordnum ) {
        *f++ = ' ';
    }
    slen = strlen( valwords[ i ] );
    memcpy((f), (valwords[ i ]), (slen));
    f += slen;
       }
   }
      } else if ( *(p+1) == '$' ) {
   ++p;
   if ( wordcount > 0 ) {
       wordnum = wordcount - 1;
       slen = strlen( valwords[ wordnum ] );
       memcpy((f), (valwords[ wordnum ]), (slen));
       f += slen;
   }
      } else if ( value != ((void *)0) ) {
   slen = strlen( value );
   memcpy((f), (value), (slen));
   f += slen;
      }
  } else if ( *p == 'a' && attr != ((void *)0) ) {
      slen = strlen( attr );
      memcpy((f), (attr), (slen));
      f += slen;
  } else {
      *f++ = *p;
  }
     } else {
  *f++ = *p;
     }
     if ( (size_t) (f - filtbuf) > buflen ) {
  --f;
  break;
     }
 }
 if ( suffix != ((void *)0) && ( (size_t) (f - filtbuf) < buflen ) )
 {
     strcpy( f, suffix );
 } else {
     *f = '\0';
 }
}

canonical_original_code:
void ldap_build_filter(char *filtbuf, unsigned long buflen, char *pattern, char *prefix, char *suffix, char *attr, char *value, char **valwords)
{
 char *p;
 char *f;
 unsigned long slen;
 int i; int wordcount; int wordnum; int endwordnum;
 if ( valwords == ((void *)0) ) {
     wordcount = 0;
 } else {
     for ( wordcount = 0; valwords[ wordcount ] != ((void *)0); ++wordcount ) {
  ;
     }
 }
 f = filtbuf;
 if ( prefix != ((void *)0) ) {
     strcpy( f, prefix );
     f += strlen( prefix );
 }
 for ( p = pattern; *p != '\0'; ++p ) {
     if ( *p == '%' ) {
  ++p;
  if ( *p == 'v' ) {
      if ( ( ((unsigned char) p[1]) >= '0' && ((unsigned char) p[1]) <= '9' )) {
   ++p;
   wordnum = *p - '1';
   if ( *(p+1) == '-' ) {
       ++p;
       if ( ( ((unsigned char) p[1]) >= '0' && ((unsigned char) p[1]) <= '9' )) {
    ++p;
    endwordnum = *p - '1';
    if ( endwordnum > wordcount - 1 ) {
        endwordnum = wordcount - 1;
    }
       } else {
    endwordnum = wordcount - 1;
       }
   } else {
       endwordnum = wordnum;
   }
   if ( wordcount > 0 ) {
       for ( i = wordnum; i <= endwordnum; ++i ) {
    if ( i > wordnum ) {
        *f++ = ' ';
    }
    slen = strlen( valwords[ i ] );
    memcpy((f), (valwords[ i ]), (slen));
    f += slen;
       }
   }
      } else if ( *(p+1) == '$' ) {
   ++p;
   if ( wordcount > 0 ) {
       wordnum = wordcount - 1;
       slen = strlen( valwords[ wordnum ] );
       memcpy((f), (valwords[ wordnum ]), (slen));
       f += slen;
   }
      } else if ( value != ((void *)0) ) {
   slen = strlen( value );
   memcpy((f), (value), (slen));
   f += slen;
      }
  } else if ( *p == 'a' && attr != ((void *)0) ) {
      slen = strlen( attr );
      memcpy((f), (attr), (slen));
      f += slen;
  } else {
      *f++ = *p;
  }
     } else {
  *f++ = *p;
     }
     if ( (unsigned long) (f - filtbuf) > buflen ) {
  --f;
  break;
     }
 }
 if ( suffix != ((void *)0) && ( (unsigned long) (f - filtbuf) < buflen ) )
 {
     strcpy( f, suffix );
 } else {
     *f = '\0';
 }
}

variable_types:
filtbuf
char *

variable_types:
buflen
unsigned long

variable_types:
pattern
char *

variable_types:
attr
char *

variable_types:
value
char *

variable_types:
valwords
char **

variable_types:
p
char *

variable_types:
f
char *

variable_types:
slen
unsigned long

variable_types: i int

variable_types: wordcount int

variable_types: wordnum int

variable_types: endwordnum int


original_code:
LDAPFiltInfo *
ldap_getnextfilter( LDAPFiltDesc *lfdp )
{
    LDAPFiltInfo *fip;
    fip = lfdp->lfd_curfip;
    if ( fip == ((void *)0) ) {
 return( ((void *)0) );
    }
    lfdp->lfd_curfip = fip->lfi_next;
    ldap_build_filter( lfdp->lfd_filter, 1024, fip->lfi_filter,
     lfdp->lfd_filtprefix, lfdp->lfd_filtsuffix, ((void *)0),
     lfdp->lfd_curval, lfdp->lfd_curvalwords );
    lfdp->lfd_retfi.lfi_filter = lfdp->lfd_filter;
    lfdp->lfd_retfi.lfi_desc = fip->lfi_desc;
    lfdp->lfd_retfi.lfi_scope = fip->lfi_scope;
    lfdp->lfd_retfi.lfi_isexact = fip->lfi_isexact;
    return( &lfdp->lfd_retfi );
}

canonical_original_code:
struct ldap_filt_info *ldap_getnextfilter(struct ldap_filt_desc *lfdp)
{
    struct ldap_filt_info *fip;
    fip = lfdp->lfd_curfip;
    if ( fip == ((void *)0) ) {
 return( ((void *)0) );
    }
    lfdp->lfd_curfip = fip->lfi_next;
    ldap_build_filter( lfdp->lfd_filter, 1024, fip->lfi_filter,
     lfdp->lfd_filtprefix, lfdp->lfd_filtsuffix, ((void *)0),
     lfdp->lfd_curval, lfdp->lfd_curvalwords );
    lfdp->lfd_retfi.lfi_filter = lfdp->lfd_filter;
    lfdp->lfd_retfi.lfi_desc = fip->lfi_desc;
    lfdp->lfd_retfi.lfi_scope = fip->lfi_scope;
    lfdp->lfd_retfi.lfi_isexact = fip->lfi_isexact;
    return( &lfdp->lfd_retfi );
}

variable_types: struct ldap_filt_desc { struct ldap_filt_list { char *lfl_tag; char *lfl_pattern; char *lfl_delims; struct ldap_filt_info *lfl_ilist; struct ldap_filt_list *lfl_next; } *lfd_filtlist; struct ldap_filt_info *lfd_curfip; struct ldap_filt_info lfd_retfi; char lfd_filter[1024]; char *lfd_curval; char *lfd_curvalcopy; char **lfd_curvalwords; char *lfd_filtprefix; char *lfd_filtsuffix; } *

variable_types: struct ldap_filt_info { char *lfi_filter; char *lfi_desc; int lfi_scope; int lfi_isexact; struct ldap_filt_info *lfi_next; } *

user_defined_types: struct ldap_filt_desc { struct ldap_filt_list *lfd_filtlist; struct ldap_filt_info *lfd_curfip; struct ldap_filt_info lfd_retfi; char lfd_filter[1024]; char *lfd_curval; char *lfd_curvalcopy; char **lfd_curvalwords; char *lfd_filtprefix; char *lfd_filtsuffix; }


decompiled_code:
size_t __fastcall next_line(_BYTE **a1, __int64 *a2, const char **a3)
{
__int64 v5; // rdx
_BYTE *v6; // rbp
_BYTE *v7; // rax
char v8; // cl
_BYTE *v9; // rsi
size_t result; // rax
size_t v11; // rbx
void *v12; // rdi
const char *v13; // rax

v5 = *a2;
v6 = *a1;
if ( *a2 > 0 )
goto LABEL_2;
v9 = *a1;
LABEL_8:
while ( 2 )
{
--v5;
v7 = v9 + 1;
if ( v5 <= 0 )
{
LABEL_17:
*a1 = v7;
result = 0LL;
*a2 = v5;
*a3 = 0LL;
}
else
{
if ( *v6 == 35 || v7 == v6 + 1 )
{
v6 = v9 + 1;
LABEL_2:
v7 = v6;
while ( 1 )
{
v8 = *v7;
v9 = v7++;
if ( v8 == 13 )
break;
if ( v8 == 10 )
{
if ( v5 != 1 )
{
if ( v9[1] != 13 )
goto LABEL_8;
goto LABEL_15;
}
LABEL_16:
v5 = 0LL;
goto LABEL_17;
}
if ( !--v5 )
{
v7 = v9 + 2;
v5 = -1LL;
goto LABEL_17;
}
}
if ( v5 != 1 )
{
if ( v9[1] != 10 )
continue;
LABEL_15:
--v5;
v9 = v7;
continue;
}
goto LABEL_16;
}
*a1 = v7;
*a2 = v5;
v11 = v7 - v6;
v12 = malloc(v7 - v6);
if ( v12 )
{
v13 = (const char *)memcpy(v12, v6, v11);
v13[v11 - 1] = 0;
*a3 = v13;
result = strlen(v13);
}
else
{
*a3 = 0LL;
result = 0xFFFFFFFFLL;
}
}
return result;
}
}

canonical_decompiled_code:
size_t __fastcall func0(_BYTE **a1, __int64 *a2, const char **a3)
{
__int64 v5; // rdx
_BYTE *v6; // rbp
_BYTE *v7; // rax
char v8; // cl
_BYTE *v9; // rsi
size_t result; // rax
size_t v11; // rbx
void *v12; // rdi
const char *v13; // rax

v5 = *a2;
v6 = *a1;
if ( *a2 > 0 )
goto LABEL_2;
v9 = *a1;
LABEL_8:
while ( 2 )
{
--v5;
v7 = v9 + 1;
if ( v5 <= 0 )
{
LABEL_17:
*a1 = v7;
result = 0LL;
*a2 = v5;
*a3 = 0LL;
}
else
{
if ( *v6 == 35 || v7 == v6 + 1 )
{
v6 = v9 + 1;
LABEL_2:
v7 = v6;
while ( 1 )
{
v8 = *v7;
v9 = v7++;
if ( v8 == 13 )
break;
if ( v8 == 10 )
{
if ( v5 != 1 )
{
if ( v9[1] != 13 )
goto LABEL_8;
goto LABEL_15;
}
LABEL_16:
v5 = 0LL;
goto LABEL_17;
}
if ( !--v5 )
{
v7 = v9 + 2;
v5 = -1LL;
goto LABEL_17;
}
}
if ( v5 != 1 )
{
if ( v9[1] != 10 )
continue;
LABEL_15:
--v5;
v9 = v7;
continue;
}
goto LABEL_16;
}
*a1 = v7;
*a2 = v5;
v11 = v7 - v6;
v12 = malloc(v7 - v6);
if ( v12 )
{
v13 = (const char *)memcpy(v12, v6, v11);
v13[v11 - 1] = 0;
*a3 = v13;
result = strlen(v13);
}
else
{
*a3 = 0LL;
result = 0xFFFFFFFFLL;
}
}
return result;
}
}

original_code:
static int
next_line( char **bufp, ber_len_t *blenp, char **linep )
{
    char *linestart, *line, *p;
    ber_slen_t plen;
    linestart = *bufp;
    p = *bufp;
    plen = *blenp;
    do {
 for ( linestart = p; plen > 0; ++p, --plen ) {
     if ( *p == '\r' ) {
  if ( plen > 1 && *(p+1) == '\n' ) {
      ++p;
      --plen;
  }
  break;
     }
     if ( *p == '\n' ) {
  if ( plen > 1 && *(p+1) == '\r' ) {
      ++p;
      --plen;
  }
  break;
     }
 }
 ++p;
 --plen;
    } while ( plen > 0 && ( *linestart == '#' || linestart + 1 == p ));
    *bufp = p;
    *blenp = plen;
    if ( plen <= 0 ) {
 *linep = ((void *)0);
 return( 0 );
    }
    if (( line = (malloc(p - linestart))) == ((void *)0) ) {
 *linep = ((void *)0);
 return( -1 );
    }
    memcpy((line), (linestart), (p - linestart));
    line[ p - linestart - 1 ] = '\0';
    *linep = line;
    return( strlen( line ));
}

canonical_original_code:
static int next_line(char **bufp, unsigned long *blenp, char **linep)
{
    char *linestart; char *line; char *p;
    long plen;
    linestart = *bufp;
    p = *bufp;
    plen = *blenp;
    do {
 for ( linestart = p; plen > 0; ++p, --plen ) {
     if ( *p == '\r' ) {
  if ( plen > 1 && *(p+1) == '\n' ) {
      ++p;
      --plen;
  }
  break;
     }
     if ( *p == '\n' ) {
  if ( plen > 1 && *(p+1) == '\r' ) {
      ++p;
      --plen;
  }
  break;
     }
 }
 ++p;
 --plen;
    } while ( plen > 0 && ( *linestart == '#' || linestart + 1 == p ));
    *bufp = p;
    *blenp = plen;
    if ( plen <= 0 ) {
 *linep = ((void *)0);
 return( 0 );
    }
    if (( line = (malloc(p - linestart))) == ((void *)0) ) {
 *linep = ((void *)0);
 return( -1 );
    }
    memcpy((line), (linestart), (p - linestart));
    line[ p - linestart - 1 ] = '\0';
    *linep = line;
    return( strlen( line ));
}

variable_types:
bufp
char **

variable_types:
blenp
unsigned long *

variable_types:
linep
char **

variable_types:
linestart
char *

variable_types:
line
char *

variable_types: plen long

return_type: int


decompiled_code:
char *__fastcall next_token(const char **a1)
{
const char *v1; // rax
char v3; // dl
char v4; // dl
int v5; // edi
const char *v6; // r9
char *v7; // rcx

v1 = *a1;
v3 = **a1;
if ( !v3 )
return 0LL;
if ( (unsigned __int8)(v3 - 9) <= 1u || v3 == 32 )
{
do
{
do
v4 = *++v1;
while ( (unsigned __int8)(v4 - 9) <= 1u );
}
while ( v4 == 32 );
if ( !v4 )
return 0LL;
v5 = 0;
if ( v4 != 34 )
goto LABEL_8;
goto LABEL_18;
}
if ( v3 == 34 )
{
LABEL_18:
++v1;
v5 = 1;
LABEL_8:
v3 = *v1;
v6 = v1;
v7 = (char *)v1;
if ( *v1 )
goto LABEL_11;
goto LABEL_16;
}
v6 = *a1;
v7 = (char *)*a1;
v5 = 0;
LABEL_11:
while ( (unsigned __int8)(v3 - 9) > 1u && v3 != 32 || v5 )
{
++v1;
if ( v3 == 34 )
{
v3 = *v1;
v5 ^= 1u;
if ( !*v1 )
goto LABEL_16;
}
else
{
*v7 = v3;
v3 = *v1;
++v7;
if ( !*v1 )
goto LABEL_16;
}
}
++v1;
LABEL_16:
*v7 = 0;
*a1 = v1;
if ( v6 != v7 + 1 )
return strdup(v6);
return 0LL;
}

canonical_decompiled_code:
char *__fastcall func1(const char **a1)
{
const char *v1; // rax
char v3; // dl
char v4; // dl
int v5; // edi
const char *v6; // r9
char *v7; // rcx

v1 = *a1;
v3 = **a1;
if ( !v3 )
return 0LL;
if ( (unsigned __int8)(v3 - 9) <= 1u || v3 == 32 )
{
do
{
do
v4 = *++v1;
while ( (unsigned __int8)(v4 - 9) <= 1u );
}
while ( v4 == 32 );
if ( !v4 )
return 0LL;
v5 = 0;
if ( v4 != 34 )
goto LABEL_8;
goto LABEL_18;
}
if ( v3 == 34 )
{
LABEL_18:
++v1;
v5 = 1;
LABEL_8:
v3 = *v1;
v6 = v1;
v7 = (char *)v1;
if ( *v1 )
goto LABEL_11;
goto LABEL_16;
}
v6 = *a1;
v7 = (char *)*a1;
v5 = 0;
LABEL_11:
while ( (unsigned __int8)(v3 - 9) > 1u && v3 != 32 || v5 )
{
++v1;
if ( v3 == 34 )
{
v3 = *v1;
v5 ^= 1u;
if ( !*v1 )
goto LABEL_16;
}
else
{
*v7 = v3;
v3 = *v1;
++v7;
if ( !*v1 )
goto LABEL_16;
}
}
++v1;
LABEL_16:
*v7 = 0;
*a1 = v1;
if ( v6 != v7 + 1 )
return strdup(v6);
return 0LL;
}

original_code:
static char *
next_token( char **sp )
{
    int in_quote = 0;
    char *p, *tokstart, *t;
    if ( **sp == '\0' ) {
 return( ((void *)0) );
    }
    p = *sp;
    while ( (((unsigned char) *p) == ' ' || ((unsigned char) *p) == '\t' || ((unsigned char) *p) == '\n')) {
 ++p;
    }
    if ( *p == '\0' ) {
 return( ((void *)0) );
    }
    if ( *p == '\"' ) {
 in_quote = 1;
 ++p;
    }
    t = tokstart = p;
    for ( ;; ) {
 if ( *p == '\0' || ( (((unsigned char) *p) == ' ' || ((unsigned char) *p) == '\t' || ((unsigned char) *p) == '\n') && !in_quote )) {
     if ( *p != '\0' ) {
  ++p;
     }
     *t++ = '\0';
     break;
 }
 if ( *p == '\"' ) {
     in_quote = !in_quote;
     ++p;
 } else {
     *t++ = *p++;
 }
    }
    *sp = p;
    if ( t == tokstart ) {
 return( ((void *)0) );
    }
    return( (strdup(tokstart)));
}

canonical_original_code:
static char *next_token(char **sp)
{
    int in_quote = 0;
    char *p; char *tokstart; char *t;
    if ( **sp == '\0' ) {
 return( ((void *)0) );
    }
    p = *sp;
    while ( (((unsigned char) *p) == ' ' || ((unsigned char) *p) == '\t' || ((unsigned char) *p) == '\n')) {
 ++p;
    }
    if ( *p == '\0' ) {
 return( ((void *)0) );
    }
    if ( *p == '\"' ) {
 in_quote = 1;
 ++p;
    }
    t = tokstart = p;
    for ( ;; ) {
 if ( *p == '\0' || ( (((unsigned char) *p) == ' ' || ((unsigned char) *p) == '\t' || ((unsigned char) *p) == '\n') && !in_quote )) {
     if ( *p != '\0' ) {
  ++p;
     }
     *t++ = '\0';
     break;
 }
 if ( *p == '\"' ) {
     in_quote = !in_quote;
     ++p;
 } else {
     *t++ = *p++;
 }
    }
    *sp = p;
    if ( t == tokstart ) {
 return( ((void *)0) );
    }
    return( (strdup(tokstart)));
}

variable_types:
sp
char **

variable_types:
tokstart
char *

variable_types:
t
char *

return_type: char *


decompiled_code:
__int64 __fastcall ldap_int_next_line_tokens(_BYTE **a1, __int64 *a2, const char ***a3)
{
unsigned int i; // er14
const char **v5; // rax
void *v6; // rdi
const char **v7; // rbp
__int64 v8; // rbx
char *v9; // r12
void *v10; // r12
const char *v12; // [rsp+0h] [rbp-38h] BYREF
void *ptr; // [rsp+8h] [rbp-30h] BYREF

*a3 = 0LL;
i = next_line(a1, a2, (const char **)&ptr);
if ( (int)i > 0 )
{
v5 = (const char **)calloc(1uLL, 8uLL);
v6 = ptr;
v7 = v5;
if ( v5 )
{
v12 = (const char *)ptr;
v8 = 0LL;
for ( i = 0; ; ++i )
{
v9 = next_token(&v12);
if ( !v9 )
break;
v7 = (const char **)realloc(v7, v8 * 8 + 16);
if ( !v7 )
{
v6 = ptr;
goto LABEL_12;
}
v7[v8] = v9;
v7[++v8] = 0LL;
}
v10 = ptr;
if ( i == 1 )
{
if ( !strcasecmp(*v7, "END") )
{
i = 0;
free(v7);
free(v10);
return i;
}
free(v10);
}
else
{
free(ptr);
if ( !i )
{
free(v7);
return i;
}
}
*a3 = v7;
}
else
{
LABEL_12:
free(v6);
i = -1;
}
}
return i;
}

canonical_decompiled_code:
__int64 __fastcall func2(_BYTE **a1, __int64 *a2, const char ***a3)
{
unsigned int i; // er14
const char **v5; // rax
void *v6; // rdi
const char **v7; // rbp
__int64 v8; // rbx
char *v9; // r12
void *v10; // r12
const char *v12; // [rsp+0h] [rbp-38h] BYREF
void *ptr; // [rsp+8h] [rbp-30h] BYREF

*a3 = 0LL;
i = func0(a1, a2, (const char **)&ptr);
if ( (int)i > 0 )
{
v5 = (const char **)calloc(1uLL, 8uLL);
v6 = ptr;
v7 = v5;
if ( v5 )
{
v12 = (const char *)ptr;
v8 = 0LL;
for ( i = 0; ; ++i )
{
v9 = func1(&v12);
if ( !v9 )
break;
v7 = (const char **)realloc(v7, v8 * 8 + 16);
if ( !v7 )
{
v6 = ptr;
goto LABEL_12;
}
v7[v8] = v9;
v7[++v8] = 0LL;
}
v10 = ptr;
if ( i == 1 )
{
if ( !strcasecmp(*v7, "END") )
{
i = 0;
free(v7);
free(v10);
return i;
}
free(v10);
}
else
{
free(ptr);
if ( !i )
{
free(v7);
return i;
}
}
*a3 = v7;
}
else
{
LABEL_12:
free(v6);
i = -1;
}
}
return i;
}

original_code:
int
ldap_int_next_line_tokens( char **bufp, ber_len_t *blenp, char ***toksp )
{
    char *p, *line, *token, **toks;
    int rc, tokcnt;
    *toksp = ((void *)0);
    if (( rc = next_line( bufp, blenp, &line )) <= 0 ) {
 return( rc );
    }
    if (( toks = (char **)(calloc((1),(sizeof( char * ))))) == ((void *)0) ) {
 (free(line));
 return( -1 );
    }
    tokcnt = 0;
    p = line;
    while (( token = next_token( &p )) != ((void *)0) ) {
 if (( toks = (char **)(realloc((toks),(( tokcnt + 2 ) * sizeof( char * ))))) == ((void *)0) ) {
     (free((char *)toks));
     (free(line));
     return( -1 );
 }
 toks[ tokcnt ] = token;
 toks[ ++tokcnt ] = ((void *)0);
    }
    if ( tokcnt == 1 && strcasecmp( toks[ 0 ], "END" ) == 0 ) {
 tokcnt = 0;
 (free(toks));
 toks = ((void *)0);
    }
    (free(line));
    if ( tokcnt == 0 ) {
 if ( toks != ((void *)0) ) {
     (free((char *)toks));
 }
    } else {
 *toksp = toks;
    }
    return( tokcnt );
}

canonical_original_code:
int ldap_int_next_line_tokens(char **bufp, unsigned long *blenp, char ***toksp)
{
    char *p; char *line; char *token; char **toks;
    int rc; int tokcnt;
    *toksp = ((void *)0);
    if (( rc = next_line( bufp, blenp, &line )) <= 0 ) {
 return( rc );
    }
    if (( toks = (char **)(calloc((1),(sizeof( char * ))))) == ((void *)0) ) {
 (free(line));
 return( -1 );
    }
    tokcnt = 0;
    p = line;
    while (( token = next_token( &p )) != ((void *)0) ) {
 if (( toks = (char **)(realloc((toks),(( tokcnt + 2 ) * sizeof( char * ))))) == ((void *)0) ) {
     (free((char *)toks));
     (free(line));
     return( -1 );
 }
 toks[ tokcnt ] = token;
 toks[ ++tokcnt ] = ((void *)0);
    }
    if ( tokcnt == 1 && strcasecmp( toks[ 0 ], "END" ) == 0 ) {
 tokcnt = 0;
 (free(toks));
 toks = ((void *)0);
    }
    (free(line));
    if ( tokcnt == 0 ) {
 if ( toks != ((void *)0) ) {
     (free((char *)toks));
 }
    } else {
 *toksp = toks;
    }
    return( tokcnt );
}

variable_types:
toksp
char ***

variable_types:
p
char *

variable_types:
token
char *

variable_types:
toks
char **

variable_types: rc int

variable_types: tokcnt int


decompiled_code:
// attributes: thunk
void ldap_memfree(void *ptr)
{
free(ptr);
}

canonical_decompiled_code:
void func0(void *ptr)
{
free(ptr);
}

original_code:
void
ldap_memfree( void *p )
{
 (free(p));
}

canonical_original_code:
void ldap_memfree(void *p)
{
 (free(p));
}

variable_types:
p
void *

return_type: void


decompiled_code:
// attributes: thunk
void __fastcall ldap_memvfree(void *ptr)
{
ldap_memfree(ptr);
}

canonical_decompiled_code:
void __fastcall func1(void *ptr)
{
func0(ptr);
}

original_code:
void
ldap_memvfree( void **v )
{
 (free(v));
}

canonical_original_code:
void ldap_memvfree(void **v)
{
 (free(v));
}

variable_types:
v
void **


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

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

original_code:
void *
ldap_memalloc( ber_len_t s )
{
 return (malloc(s));
}

canonical_original_code:
void *ldap_memalloc(unsigned long s)
{
 return (malloc(s));
}

variable_types:
s
unsigned long

return_type: void *


decompiled_code:
// attributes: thunk
void *ldap_memcalloc(size_t nmemb, size_t size)
{
return calloc(nmemb, size);
}

canonical_decompiled_code:
void *func3(size_t nmemb, size_t size)
{
return calloc(nmemb, size);
}

original_code:
void *
ldap_memcalloc( ber_len_t n, ber_len_t s )
{
 return (calloc((n),(s)));
}

canonical_original_code:
void *ldap_memcalloc(unsigned long n, unsigned long s)
{
 return (calloc((n),(s)));
}

variable_types:
n
unsigned long


decompiled_code:
// attributes: thunk
void *ldap_memrealloc(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:
void *
ldap_memrealloc( void* p, ber_len_t s )
{
 return (realloc((p),(s)));
}

canonical_original_code:
void *ldap_memrealloc(void *p, unsigned long s)
{
 return (realloc((p),(s)));
}


decompiled_code:
// attributes: thunk
char *ldap_strdup(const char *s)
{
return strdup(s);
}

canonical_decompiled_code:
char *func5(const char *s)
{
return strdup(s);
}

original_code:
char *
ldap_strdup( const char *p )
{
 return (strdup(p));
}

canonical_original_code:
char *ldap_strdup(char *p)
{
 return (strdup(p));
}


original_code:
void
ldap_getfilter_free( LDAPFiltDesc *lfdp )
{
    LDAPFiltList *flp, *nextflp;
    LDAPFiltInfo *fip, *nextfip;
    for ( flp = lfdp->lfd_filtlist; flp != ((void *)0); flp = nextflp ) {
 for ( fip = flp->lfl_ilist; fip != ((void *)0); fip = nextfip ) {
     nextfip = fip->lfi_next;
     (free(fip->lfi_filter));
     (free(fip->lfi_desc));
     (free(fip));
 }
 nextflp = flp->lfl_next;
 (free(flp->lfl_pattern));
 (free(flp->lfl_delims));
 (free(flp->lfl_tag));
 (free(flp));
    }
    if ( lfdp->lfd_curvalcopy != ((void *)0) ) {
 (free(lfdp->lfd_curvalcopy));
    }
    if ( lfdp->lfd_curvalwords != ((void *)0) ) {
 (free(lfdp->lfd_curvalwords));
    }
    if ( lfdp->lfd_filtprefix != ((void *)0) ) {
 (free(lfdp->lfd_filtprefix));
    }
    if ( lfdp->lfd_filtsuffix != ((void *)0) ) {
 (free(lfdp->lfd_filtsuffix));
    }
    (free(lfdp));
}

canonical_original_code:
void ldap_getfilter_free(struct ldap_filt_desc *lfdp)
{
    struct ldap_filt_list *flp; struct ldap_filt_list *nextflp;
    struct ldap_filt_info *fip; struct ldap_filt_info *nextfip;
    for ( flp = lfdp->lfd_filtlist; flp != ((void *)0); flp = nextflp ) {
 for ( fip = flp->lfl_ilist; fip != ((void *)0); fip = nextfip ) {
     nextfip = fip->lfi_next;
     (free(fip->lfi_filter));
     (free(fip->lfi_desc));
     (free(fip));
 }
 nextflp = flp->lfl_next;
 (free(flp->lfl_pattern));
 (free(flp->lfl_delims));
 (free(flp->lfl_tag));
 (free(flp));
    }
    if ( lfdp->lfd_curvalcopy != ((void *)0) ) {
 (free(lfdp->lfd_curvalcopy));
    }
    if ( lfdp->lfd_curvalwords != ((void *)0) ) {
 (free(lfdp->lfd_curvalwords));
    }
    if ( lfdp->lfd_filtprefix != ((void *)0) ) {
 (free(lfdp->lfd_filtprefix));
    }
    if ( lfdp->lfd_filtsuffix != ((void *)0) ) {
 (free(lfdp->lfd_filtsuffix));
    }
    (free(lfdp));
}

variable_types: struct ldap_filt_desc { struct ldap_filt_list { char *lfl_tag; char *lfl_pattern; char *lfl_delims; struct ldap_filt_info { char *lfi_filter; char *lfi_desc; int lfi_scope; int lfi_isexact; struct ldap_filt_info *lfi_next; } *lfl_ilist; struct ldap_filt_list *lfl_next; } *lfd_filtlist; struct ldap_filt_info *lfd_curfip; struct ldap_filt_info lfd_retfi; char lfd_filter[1024]; char *lfd_curval; char *lfd_curvalcopy; char **lfd_curvalwords; char *lfd_filtprefix; char *lfd_filtsuffix; } *

user_defined_types: struct ldap_filt_list { char *lfl_tag; char *lfl_pattern; char *lfl_delims; struct ldap_filt_info *lfl_ilist; struct ldap_filt_list *lfl_next; }


decompiled_code:
void __fastcall ldap_mods_free(void *ptr, int a2)
{
void *v2; // rbp
__int64 v3; // rax
_QWORD *i; // rbx
void *v5; // rdi
void *v6; // rdi

if ( ptr )
{
v2 = ptr;
v3 = *(_QWORD *)ptr;
for ( i = ptr; v3; ++i )
{
v6 = *(void **)(v3 + 16);
if ( *(char *)v3 < 0 )
{
if ( v6 )
ber_bvecfree();
}
else if ( v6 )
{
free(v6);
}
v5 = (void *)*i;
if ( *(_QWORD *)(*i + 8LL) )
{
free(*(void **)(*i + 8LL));
v5 = (void *)*i;
}
free(v5);
v3 = i[1];
}
if ( a2 )
free(v2);
}
}

canonical_decompiled_code:
void __fastcall func7(void *ptr, int a2)
{
void *v2; // rbp
__int64 v3; // rax
_QWORD *i; // rbx
void *v5; // rdi
void *v6; // rdi

if ( ptr )
{
v2 = ptr;
v3 = *(_QWORD *)ptr;
for ( i = ptr; v3; ++i )
{
v6 = *(void **)(v3 + 16);
if ( *(char *)v3 < 0 )
{
if ( v6 )
ber_bvecfree();
}
else if ( v6 )
{
free(v6);
}
v5 = (void *)*i;
if ( *(_QWORD *)(*i + 8LL) )
{
free(*(void **)(*i + 8LL));
v5 = (void *)*i;
}
free(v5);
v3 = i[1];
}
if ( a2 )
free(v2);
}
}

original_code:
void
ldap_mods_free( LDAPMod **mods, int freemods )
{
 int i;
 if ( mods == ((void *)0) )
  return;
 for ( i = 0; mods[i] != ((void *)0); i++ ) {
  if ( mods[i]->mod_op & (0x0080) ) {
   if( mods[i]->mod_vals.modv_bvals != ((void *)0) )
    ber_bvecfree( mods[i]->mod_vals.modv_bvals );
  } else if( mods[i]->mod_vals.modv_strvals != ((void *)0) ) {
   (free(mods[i]->mod_vals.modv_strvals));
  }
  if ( mods[i]->mod_type != ((void *)0) ) {
   (free(mods[i]->mod_type));
  }
  (free((char *) mods[i]));
 }
 if ( freemods ) {
  (free((char *) mods));
 }
}

canonical_original_code:
void ldap_mods_free(struct ldapmod **mods, int freemods)
{
 int i;
 if ( mods == ((void *)0) )
  return;
 for ( i = 0; mods[i] != ((void *)0); i++ ) {
  if ( mods[i]->mod_op & (0x0080) ) {
   if( mods[i]->mod_vals.modv_bvals != ((void *)0) )
    ber_bvecfree( mods[i]->mod_vals.modv_bvals );
  } else if( mods[i]->mod_vals.modv_strvals != ((void *)0) ) {
   (free(mods[i]->mod_vals.modv_strvals));
  }
  if ( mods[i]->mod_type != ((void *)0) ) {
   (free(mods[i]->mod_type));
  }
  (free((char *) mods[i]));
 }
 if ( freemods ) {
  (free((char *) mods));
 }
}

variable_types: struct ldapmod { int mod_op; char *mod_type; union mod_vals_u { char **modv_strvals; struct berval { unsigned long bv_len; char *bv_val; } **modv_bvals; } mod_vals; } **

variable_types: freemods int

variable_types: i int

user_defined_types: struct ldapmod { int mod_op; char *mod_type; union mod_vals_u mod_vals; }

user_defined_types: union mod_vals_u { char **modv_strvals; struct berval **modv_bvals; }


decompiled_code:
__int64 __fastcall int_strspn(char *a1, _BYTE *a2)
{
char v2; // cl
char v4; // si
unsigned int v5; // er8
char v6; // al
_BYTE *v7; // rdx

v2 = *a1;
if ( *a1 )
{
v4 = *a2;
v5 = 0;
v6 = v4;
while ( 1 )
{
if ( v6 != v2 )
{
if ( v4 == v2 || !v4 )
{
v6 = v4;
if ( !v4 )
return v5;
}
else
{
v7 = a2;
while ( 1 )
{
v6 = *++v7;
if ( v6 == v2 )
break;
if ( !v6 )
return v5;
}
if ( !v6 )
return v5;
}
}
v2 = *++a1;
++v5;
if ( !v2 )
return v5;
}
}
return 0;
}

canonical_decompiled_code:
__int64 __fastcall func0(char *a1, _BYTE *a2)
{
char v2; // cl
char v4; // si
unsigned int v5; // er8
char v6; // al
_BYTE *v7; // rdx

v2 = *a1;
if ( *a1 )
{
v4 = *a2;
v5 = 0;
v6 = v4;
while ( 1 )
{
if ( v6 != v2 )
{
if ( v4 == v2 || !v4 )
{
v6 = v4;
if ( !v4 )
return v5;
}
else
{
v7 = a2;
while ( 1 )
{
v6 = *++v7;
if ( v6 == v2 )
break;
if ( !v6 )
return v5;
}
if ( !v6 )
return v5;
}
}
v2 = *++a1;
++v5;
if ( !v2 )
return v5;
}
}
return 0;
}

original_code:
static int int_strspn( const char *str, const char *delim )
{
 int pos;
 const char *p=delim;
 for( pos=0; (*str) ; pos++,str++) {
  if (*str!=*p) {
   for( p=delim; (*p) ; p++ ) {
    if (*str==*p) {
     break;
    }
     }
  }
  if (*p=='\0') {
   return pos;
  }
 }
 return pos;
}

canonical_original_code:
static int int_strspn(char *str, char *delim)
{
 int pos;
 char *p = delim;
 for( pos=0; (*str) ; pos++,str++) {
  if (*str!=*p) {
   for( p=delim; (*p) ; p++ ) {
    if (*str==*p) {
     break;
    }
     }
  }
  if (*p=='\0') {
   return pos;
  }
 }
 return pos;
}

variable_types:
str
char *

variable_types:
delim
char *

variable_types: pos int


setproctitle

decompiled_code:
void __fastcall setproctitle(char *s, unsigned int a2)
{
const char **v2; // rbx
const char *v3; // r14
char *v4; // rbx
size_t v5; // rbp
size_t v6; // rax
char *v7; // rbp
int v8; // eax
unsigned __int64 v9; // r13
char *v10; // rbx
__int64 v11; // r12
__int64 v12; // r12
const char *v13; // rbp

v2 = (const char **)Argv;
if ( !endargv_0 )
{
v13 = *(const char **)(Argv + 8LL * Argc - 8);
endargv_0 = (__int64)&v13[strlen(v13)];
}
v3 = *v2;
v4 = strrchr(*v2, 47);
v5 = strlen(s);
if ( v4 )
{
v3 = v4 + 1;
v6 = strlen(v4);
}
else
{
v6 = strlen(v3);
}
v7 = (char *)calloc(v5 + v6 + 10, 1uLL);
sprintf(v7, "-%s: %s %d", v3, s, a2);
v8 = strlen(v7);
v9 = endargv_0;
v10 = *(char **)Argv;
v11 = endargv_0 - *(_QWORD *)Argv;
if ( v11 <= v8 )
{
v12 = (int)v11 - 1;
v7[(int)v12] = 0;
}
else
{
v12 = v8;
}
strcpy(v10, v7);
free(v7);
if ( v9 > (unsigned __int64)&v10[v12] )
memset(&v10[v12], 32, v9 - (_QWORD)&v10[v12]);
}

canonical_decompiled_code:
void __fastcall func0(char *s, unsigned int a2)
{
const char **v2; // rbx
const char *v3; // r14
char *v4; // rbx
size_t v5; // rbp
size_t v6; // rax
char *v7; // rbp
int v8; // eax
unsigned __int64 v9; // r13
char *v10; // rbx
__int64 v11; // r12
__int64 v12; // r12
const char *v13; // rbp

v2 = (const char **)Argv;
if ( !endargv_0 )
{
v13 = *(const char **)(Argv + 8LL * Argc - 8);
endargv_0 = (__int64)&v13[strlen(v13)];
}
v3 = *v2;
v4 = strrchr(*v2, 47);
v5 = strlen(s);
if ( v4 )
{
v3 = v4 + 1;
v6 = strlen(v4);
}
else
{
v6 = strlen(v3);
}
v7 = (char *)calloc(v5 + v6 + 10, 1uLL);
sprintf(v7, "-%s: %s %d", v3, s, a2);
v8 = strlen(v7);
v9 = endargv_0;
v10 = *(char **)Argv;
v11 = endargv_0 - *(_QWORD *)Argv;
if ( v11 <= v8 )
{
v12 = (int)v11 - 1;
v7[(int)v12] = 0;
}
else
{
v12 = v8;
}
strcpy(v10, v7);
free(v7);
if ( v9 > (unsigned __int64)&v10[v12] )
memset(&v10[v12], 32, v9 - (_QWORD)&v10[v12]);
}

original_code:
void setproctitle(char *host, int port)
{
 static char *endargv = (char *)0;
 char *s, *buf;
 int i;
 if ( endargv == (char *)0 ) {
  endargv = Argv[Argc-1] + strlen(Argv[Argc-1]);
 }
    s = (char *)strrchr(Argv[0], '/');
    buf = (char *)calloc(strlen(s ? s : Argv[0]) + strlen(host) + 10, sizeof(char));
    sprintf(buf, "-%s: %s %d", s ? s + 1 : Argv[0], host, port);
 i = strlen(buf);
 s = Argv[0];
 if (i > endargv - s - 1) {
  i = endargv - s - 1;
  buf[i] = '\0';
 }
 strcpy(s, buf);
    free(buf);
 s += i;
 while (s < endargv) *s++ = ' ';
}

canonical_original_code:
void setproctitle(char *host, int port)
{
 static char *endargv = (char *)0;
 char *s; char *buf;
 int i;
 if ( endargv == (char *)0 ) {
  endargv = Argv[Argc-1] + strlen(Argv[Argc-1]);
 }
    s = (char *)strrchr(Argv[0], '/');
    buf = (char *)calloc(strlen(s ? s : Argv[0]) + strlen(host) + 10, sizeof(char));
    sprintf(buf, "-%s: %s %d", s ? s + 1 : Argv[0], host, port);
 i = strlen(buf);
 s = Argv[0];
 if (i > endargv - s - 1) {
  i = endargv - s - 1;
  buf[i] = '\0';
 }
 strcpy(s, buf);
    free(buf);
 s += i;
 while (s < endargv) *s++ = ' ';
}

variable_types:
host
char *

variable_types: port int

variable_types:
endargv
char *

variable_types:
s
char *

variable_types:
buf
char *


gettid

repo: jonatanlinden/PR

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

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

original_code:
pid_t
gettid(void)
{
    return (pid_t) syscall(186);
}

canonical_original_code:
int gettid()
{
    return (int) syscall(186);
}


pin

decompiled_code:
int __fastcall pin(__pid_t pid, int a2)
{
int result; // eax
char *v3; // rax
cpu_set_t v4; // [rsp+0h] [rbp-88h] BYREF

memset(&v4, 0, sizeof(v4));
if ( (unsigned __int64)a2 <= 0x3FF )
v4.__bits[(unsigned __int64)a2 >> 6] |= 1LL << a2;
result = sched_setaffinity(pid, 0x80uLL, &v4);
if ( result )
{
v3 = strerror(result);
result = fputs(v3, stderr);
}
return result;
}

canonical_decompiled_code:
int __fastcall func1(__pid_t pid, int a2)
{
int result; // eax
char *v3; // rax
cpu_set_t v4; // [rsp+0h] [rbp-88h] BYREF

memset(&v4, 0, sizeof(v4));
if ( (unsigned __int64)a2 <= 0x3FF )
v4.__bits[(unsigned __int64)a2 >> 6] |= 1LL << a2;
result = sched_setaffinity(pid, 0x80uLL, &v4);
if ( result )
{
v3 = strerror(result);
result = fputs(v3, stderr);
}
return result;
}

original_code:
void
pin(pid_t t, int cpu)
{
    cpu_set_t cpuset;
    do __builtin_memset (&cpuset, '\0', sizeof (cpu_set_t)); while (0);
    (__extension__ ({ size_t __cpu = (cpu); __cpu / 8 < (sizeof (cpu_set_t)) ? (((__cpu_mask *) ((&cpuset)->__bits))[((__cpu) / (8 * sizeof (__cpu_mask)))] |= ((__cpu_mask) 1 << ((__cpu) % (8 * sizeof (__cpu_mask))))) : 0; }));
    do { int _c = (sched_setaffinity(t, sizeof(cpu_set_t), &cpuset)); if (_c != 0) { fprintf(stderr, "%s", strerror(_c)); } } while (0);
}

canonical_original_code:
void pin(int t, int cpu)
{
    struct cpu_set_t cpuset;
    do __builtin_memset (&cpuset, '\0', sizeof (cpu_set_t)); while (0);
    (__extension__ ({ unsigned long __cpu = (cpu); __cpu / 8 < (sizeof (cpu_set_t)) ? (((unsigned long *) ((&cpuset)->__bits))[((__cpu) / (8 * sizeof (__cpu_mask)))] |= ((unsigned long) 1 << ((__cpu) % (8 * sizeof (__cpu_mask))))) : 0; }));
    do { int _c = (sched_setaffinity(t, sizeof(cpu_set_t), &cpuset)); if (_c != 0) { fprintf(stderr, "%s", strerror(_c)); } } while (0);
}

variable_types: t int

variable_types: cpu int

variable_types: struct cpu_set_t { unsigned long __bits[-1]; }


gettime

decompiled_code:
int __fastcall gettime(struct timespec *tp)
{
int result; // eax

result = clock_gettime(1, tp);
if ( result < 0 )
result = fprintf(stderr, "E: %s: %d: %s\n", "common.c", 23LL, "clock_gettime(CLOCK_MONOTONIC, ts)");
return result;
}

canonical_decompiled_code:
int __fastcall func2(struct timespec *tp)
{
int result; // eax

result = clock_gettime(1, tp);
if ( result < 0 )
result = fprintf(stderr, "E: %s: %d: %s\n", "common.c", 23LL, "clock_gettime(CLOCK_MONOTONIC, ts)");
return result;
}

original_code:
void
gettime(struct timespec *ts)
{
    do { int _c = (clock_gettime(1, ts)); if (_c < 0) { fprintf(stderr, "E: %s: %d: %s\n", "common.c", 23, "clock_gettime(CLOCK_MONOTONIC, ts)"); } } while (0);
}

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


timediff

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

result = a3 - a1;
if ( a4 - a2 < 0 )
--result;
return result;
}

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

result = a3 - a1;
if ( a4 - a2 < 0 )
--result;
return result;
}

original_code:
struct timespec
timediff (struct timespec begin, struct timespec end)
{
    struct timespec tmp;
    if ((end.tv_nsec - begin.tv_nsec) < 0) {
 tmp.tv_sec = end.tv_sec - begin.tv_sec - 1;
 tmp.tv_nsec = 1000000000 + end.tv_nsec - begin.tv_nsec;
    } else {
 tmp.tv_sec = end.tv_sec - begin.tv_sec;
 tmp.tv_nsec = end.tv_nsec - begin.tv_nsec;
    }
    return tmp;
}

canonical_original_code:
struct timespec timediff(struct timespec begin, struct timespec end)
{
    struct timespec tmp;
    if ((end.tv_nsec - begin.tv_nsec) < 0) {
 tmp.tv_sec = end.tv_sec - begin.tv_sec - 1;
 tmp.tv_nsec = 1000000000 + end.tv_nsec - begin.tv_nsec;
    } else {
 tmp.tv_sec = end.tv_sec - begin.tv_sec;
 tmp.tv_nsec = end.tv_nsec - begin.tv_nsec;
    }
    return tmp;
}

variable_types:
begin
struct timespec

variable_types:
end
struct timespec

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


decompiled_code:
__int64 __fastcall rng_init(__int64 a1)
{
__int64 result; // rax
struct timespec v2; // [rsp+0h] [rbp-18h] BYREF

clock_gettime(0, &v2);
*(_DWORD *)a1 = v2.tv_nsec;
result = SHIDWORD(v2.tv_nsec);
*(_WORD *)(a1 + 4) = WORD2(v2.tv_nsec);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1)
{
__int64 result; // rax
struct timespec v2; // [rsp+0h] [rbp-18h] BYREF

clock_gettime(0, &v2);
*(_DWORD *)a1 = v2.tv_nsec;
result = SHIDWORD(v2.tv_nsec);
*(_WORD *)(a1 + 4) = WORD2(v2.tv_nsec);
return result;
}

original_code:
void
rng_init (unsigned short rng[3])
{
    struct timespec time;
    clock_gettime(0, &time);
    rng[0] = time.tv_nsec;
    rng[1] = time.tv_nsec >> 16;
    rng[2] = time.tv_nsec >> 32;
}

canonical_original_code:
void rng_init(unsigned short rng[3])
{
    struct timespec time;
    clock_gettime(0, &time);
    rng[0] = time.tv_nsec;
    rng[1] = time.tv_nsec >> 16;
    rng[2] = time.tv_nsec >> 32;
}

variable_types:
rng
unsigned short [3]

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


restructure

original_code:
static void
restructure(pq_t *pq)
{
    node_t *pred, *cur, *h;
    int i = 32 - 1;
    pred = pq->head;
    while (i > 0) {
        h = pq->head->next[i];
        __asm__ __volatile__ ("" : : : "memory");
        cur = pred->next[i];
        if (!(((uintptr_t)(h->next[0])) & 1)) {
            i--;
            continue;
        }
        while((((uintptr_t)(cur->next[0])) & 1)) {
            pred = cur;
            cur = pred->next[i];
        }
        ((void) (0));
        if (__sync_bool_compare_and_swap(&pq->head->next[i],h,cur))
            i--;
    }
}

canonical_original_code:
static void restructure(struct pq_t *pq)
{
    struct node_s *pred; struct node_s *cur; struct node_s *h;
    int i = 32 - 1;
    pred = pq->head;
    while (i > 0) {
        h = pq->head->next[i];
        __asm__ __volatile__ ("" : : : "memory");
        cur = pred->next[i];
        if (!(((unsigned long)(h->next[0])) & 1)) {
            i--;
            continue;
        }
        while((((unsigned long)(cur->next[0])) & 1)) {
            pred = cur;
            cur = pred->next[i];
        }
        ((void) (0));
        if (__sync_bool_compare_and_swap(&pq->head->next[i],h,cur))
            i--;
    }
}

variable_types: struct pq_t { int max_offset; int max_level; int nthreads; struct node_s { unsigned long k; int level; int inserting; void *v; struct node_s *next[1]; } *head; struct node_s *tail; char pad[128]; } *

variable_types: i int

user_defined_types: struct pq_t { int max_offset; int max_level; int nthreads; struct node_s *head; struct node_s *tail; char pad[128]; }


original_code:
static node_t *
alloc_node()
{
    node_t *n;
    unsigned int r = ptst->rand;
    ptst->rand = r * 1103515245 + 12345;
    r &= (1u << (32 - 1)) - 1;
    int level = __builtin_ctz(r) + 1;
    ((void) (0));
    n = gc_alloc(ptst, gc_id[level - 1]);
    n->level = level;
    n->inserting = 1;
    memset(n->next, 0, level * sizeof(node_t *));
    return n;
}

canonical_original_code:
static struct node_s *alloc_node()
{
    struct node_s *n;
    unsigned int r = ptst->rand;
    ptst->rand = r * 1103515245 + 12345;
    r &= (1u << (32 - 1)) - 1;
    int level = __builtin_ctz(r) + 1;
    ((void) (0));
    n = gc_alloc(ptst, gc_id[level - 1]);
    n->level = level;
    n->inserting = 1;
    memset(n->next, 0, level * sizeof(struct node_s *));
    return n;
}

variable_types: struct node_s { unsigned long k; int level; int inserting; void *v; struct node_s *next[1]; } *

variable_types:
r
unsigned int

variable_types: level int


decompiled_code:
__int64 __fastcall free_node(__int64 a1)
{
return gc_free(ptst, a1, (unsigned int)gc_id[*(_DWORD *)(a1 + 8) - 1]);
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1)
{
return gc_free(ptst, a1, (unsigned int)gc_id[*(_DWORD *)(a1 + 8) - 1]);
}

original_code:
static void
free_node(node_t *n)
{
    gc_free(ptst, (void *)n, gc_id[(n->level) - 1]);
}

canonical_original_code:
static void free_node(struct node_s *n)
{
    gc_free(ptst, (void *)n, gc_id[(n->level) - 1]);
}

user_defined_types: struct node_s { unsigned long k; int level; int inserting; void *v; struct node_s *next[1]; }


insert

original_code:
void
insert(pq_t *pq, pkey_t k, pval_t v)
{
    node_t *preds[32], *succs[32];
    node_t *new = ((void *)0), *del = ((void *)0);
    ((void) (0));
    critical_enter();
    new = alloc_node();
    new->k = k;
    new->v = v;
 retry:
    del = locate_preds(pq, k, preds, succs);
    if (succs[0]->k == k && !(((uintptr_t)(preds[0]->next[0])) & 1) && preds[0]->next[0] == succs[0]) {
        new->inserting = 0;
        free_node(new);
        goto out;
    }
    new->next[0] = succs[0];
    if (!__sync_bool_compare_and_swap(&preds[0]->next[0], succs[0], new)) {
        goto retry;
    }
    int i = 1;
    while ( i < new->level)
    {
        if ((((uintptr_t)(new->next[0])) & 1) ||
            (((uintptr_t)(succs[i]->next[0])) & 1) ||
            del == succs[i])
            goto success;
        new->next[i] = succs[i];
        if (!__sync_bool_compare_and_swap(&preds[i]->next[i], succs[i], new))
        {
            del = locate_preds(pq, k, preds, succs);
            if (succs[0] != new) goto success;
        } else {
            i++;
        }
    }
 success:
    if (new) {
        new->inserting = 0;
    }
 out:
    gc_exit(ptst);
}

canonical_original_code:
void insert(struct pq_t *pq, unsigned long k, void *v)
{
    struct node_s *preds[32]; struct node_s *succs[32];
    struct node_s *new = ((void *)0); struct node_s *del = ((void *)0);
    ((void) (0));
    critical_enter();
    new = alloc_node();
    new->k = k;
    new->v = v;
 retry:
    del = locate_preds(pq, k, preds, succs);
    if (succs[0]->k == k && !(((unsigned long)(preds[0]->next[0])) & 1) && preds[0]->next[0] == succs[0]) {
        new->inserting = 0;
        free_node(new);
        goto out;
    }
    new->next[0] = succs[0];
    if (!__sync_bool_compare_and_swap(&preds[0]->next[0], succs[0], new)) {
        goto retry;
    }
    int i = 1;
    while ( i < new->level)
    {
        if ((((unsigned long)(new->next[0])) & 1) ||
            (((unsigned long)(succs[i]->next[0])) & 1) ||
            del == succs[i])
            goto success;
        new->next[i] = succs[i];
        if (!__sync_bool_compare_and_swap(&preds[i]->next[i], succs[i], new))
        {
            del = locate_preds(pq, k, preds, succs);
            if (succs[0] != new) goto success;
        } else {
            i++;
        }
    }
 success:
    if (new) {
        new->inserting = 0;
    }
 out:
    gc_exit(ptst);
}

variable_types:
k
unsigned long

variable_types:
v
void *

variable_types: struct node_s { unsigned long k; int level; int inserting; void *v; struct node_s *next[1]; } *[32]


deletemin

decompiled_code:
__int64 __fastcall deletemin(__int64 a1)
{
__int64 v1; // rbp
unsigned __int64 v2; // rbx
unsigned __int64 v3; // rdx
__int64 v4; // r8
signed __int64 v5; // r11
__int64 v6; // rsi
signed __int64 v7; // rax
signed __int64 v8; // rcx
signed __int64 v9; // rtt
unsigned __int64 v10; // rax
unsigned __int64 v11; // rcx
__int64 v12; // r12
__int64 v14; // rdx
unsigned __int64 v15; // rbx
unsigned __int64 v16; // r11
unsigned __int64 v17; // rbp
__int64 v18; // rdi

v1 = a1;
v2 = 0LL;
critical_enter();
v3 = *(_QWORD *)(a1 + 16);
v4 = *(_QWORD *)(a1 + 24);
LODWORD(a1) = 0;
v5 = *(_QWORD *)(v3 + 24);
v6 = v5;
while ( 1 )
{
a1 = (unsigned int)(a1 + 1);
v11 = v6 & 0xFFFFFFFFFFFFFFFELL;
v10 = v6 & 0xFFFFFFFFFFFFFFFELL;
if ( (v6 & 0xFFFFFFFFFFFFFFFELL) == v4 )
{
v12 = 0LL;
goto LABEL_17;
}
if ( !v2 && *(_DWORD *)(v3 + 12) )
v2 = v3;
v6 &= 1u;
if ( !(_DWORD)v6 )
break;
if ( !v11 )
goto LABEL_12;
LABEL_7:
v6 = *(_QWORD *)(v10 + 24);
v3 = v10;
}
v7 = *(_QWORD *)(v3 + 24);
do
{
v8 = v7;
v6 = v7 | 1;
v9 = v7;
v7 = _InterlockedCompareExchange64((volatile signed __int64 *)(v3 + 24), v7 | 1, v7);
}
while ( v9 != v7 );
v3 = v8 & 0xFFFFFFFFFFFFFFFELL;
v10 = v8 & 0xFFFFFFFFFFFFFFFELL;
if ( (v8 & 0xFFFFFFFFFFFFFFFELL) == 0 )
LABEL_12:
deletemin_cold(a1, v6, v3);
if ( (v8 & 1) != 0 )
{
v4 = *(_QWORD *)(v1 + 24);
goto LABEL_7;
}
v12 = *(_QWORD *)(v3 + 16);
if ( !v2 )
v2 = v8 & 0xFFFFFFFFFFFFFFFELL;
if ( *(_DWORD *)v1 < (int)a1 )
{
v14 = *(_QWORD *)(v1 + 16);
if ( *(_QWORD *)(v14 + 24) == v5
&& v5 == _InterlockedCompareExchange64((volatile signed __int64 *)(v14 + 24), v2 | 1, v5) )
{
v15 = v2 & 0xFFFFFFFFFFFFFFFELL;
restructure(v1);
v17 = v16;
while ( v17 != v15 )
{
v18 = v17;
v17 = *(_QWORD *)(v17 + 24) & 0xFFFFFFFFFFFFFFFELL;
free_node(v18);
}
}
}
LABEL_17:
gc_exit(ptst, v6);
return v12;
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1)
{
__int64 v1; // rbp
unsigned __int64 v2; // rbx
unsigned __int64 v3; // rdx
__int64 v4; // r8
signed __int64 v5; // r11
__int64 v6; // rsi
signed __int64 v7; // rax
signed __int64 v8; // rcx
signed __int64 v9; // rtt
unsigned __int64 v10; // rax
unsigned __int64 v11; // rcx
__int64 v12; // r12
__int64 v14; // rdx
unsigned __int64 v15; // rbx
unsigned __int64 v16; // r11
unsigned __int64 v17; // rbp
__int64 v18; // rdi

v1 = a1;
v2 = 0LL;
critical_enter();
v3 = *(_QWORD *)(a1 + 16);
v4 = *(_QWORD *)(a1 + 24);
LODWORD(a1) = 0;
v5 = *(_QWORD *)(v3 + 24);
v6 = v5;
while ( 1 )
{
a1 = (unsigned int)(a1 + 1);
v11 = v6 & 0xFFFFFFFFFFFFFFFELL;
v10 = v6 & 0xFFFFFFFFFFFFFFFELL;
if ( (v6 & 0xFFFFFFFFFFFFFFFELL) == v4 )
{
v12 = 0LL;
goto LABEL_17;
}
if ( !v2 && *(_DWORD *)(v3 + 12) )
v2 = v3;
v6 &= 1u;
if ( !(_DWORD)v6 )
break;
if ( !v11 )
goto LABEL_12;
LABEL_7:
v6 = *(_QWORD *)(v10 + 24);
v3 = v10;
}
v7 = *(_QWORD *)(v3 + 24);
do
{
v8 = v7;
v6 = v7 | 1;
v9 = v7;
v7 = _InterlockedCompareExchange64((volatile signed __int64 *)(v3 + 24), v7 | 1, v7);
}
while ( v9 != v7 );
v3 = v8 & 0xFFFFFFFFFFFFFFFELL;
v10 = v8 & 0xFFFFFFFFFFFFFFFELL;
if ( (v8 & 0xFFFFFFFFFFFFFFFELL) == 0 )
LABEL_12:
func7(a1, v6, v3);
if ( (v8 & 1) != 0 )
{
v4 = *(_QWORD *)(v1 + 24);
goto LABEL_7;
}
v12 = *(_QWORD *)(v3 + 16);
if ( !v2 )
v2 = v8 & 0xFFFFFFFFFFFFFFFELL;
if ( *(_DWORD *)v1 < (int)a1 )
{
v14 = *(_QWORD *)(v1 + 16);
if ( *(_QWORD *)(v14 + 24) == v5
&& v5 == _InterlockedCompareExchange64((volatile signed __int64 *)(v14 + 24), v2 | 1, v5) )
{
v15 = v2 & 0xFFFFFFFFFFFFFFFELL;
func0(v1);
v17 = v16;
while ( v17 != v15 )
{
v18 = v17;
v17 = *(_QWORD *)(v17 + 24) & 0xFFFFFFFFFFFFFFFELL;
func2(v18);
}
}
}
LABEL_17:
gc_exit(ptst, v6);
return v12;
}

original_code:
pval_t
deletemin(pq_t *pq)
{
    pval_t v = ((void *)0);
    node_t *x, *nxt, *obs_head = ((void *)0), *newhead, *cur;
    int offset, lvl;
    newhead = ((void *)0);
    offset = lvl = 0;
    critical_enter();
    x = pq->head;
    obs_head = x->next[0];
    do {
        offset++;
        nxt = x->next[0];
        if (((void *)(((uintptr_t)(nxt)) & ~1)) == pq->tail) {
            goto out;
        }
        if (newhead == ((void *)0) && x->inserting) newhead = x;
        if ((((uintptr_t)(nxt)) & 1)) continue;
        nxt = __sync_fetch_and_or(&x->next[0], 1);
    }
    while ( (x = ((void *)(((uintptr_t)(nxt)) & ~1))) && (((uintptr_t)(nxt)) & 1) );
    ((void) (0));
    v = x->v;
    if (newhead == ((void *)0)) newhead = x;
    if (offset <= pq->max_offset) goto out;
    if (pq->head->next[0] != obs_head) goto out;
    if (__sync_bool_compare_and_swap(&pq->head->next[0], obs_head, ((void *)(((uintptr_t)(newhead)) | 1))))
    {
        restructure(pq);
        cur = ((void *)(((uintptr_t)(obs_head)) & ~1));
        while (cur != ((void *)(((uintptr_t)(newhead)) & ~1))) {
            nxt = ((void *)(((uintptr_t)(cur->next[0])) & ~1));
            ((void) (0));
            free_node(cur);
            cur = nxt;
        }
    }
 out:
    gc_exit(ptst);
    return v;
}

canonical_original_code:
void *deletemin(struct pq_t *pq)
{
    void *v = ((void *)0);
    struct node_s *x; struct node_s *nxt; struct node_s *obs_head = ((void *)0); struct node_s *newhead; struct node_s *cur;
    int offset; int lvl;
    newhead = ((void *)0);
    offset = lvl = 0;
    critical_enter();
    x = pq->head;
    obs_head = x->next[0];
    do {
        offset++;
        nxt = x->next[0];
        if (((void *)(((unsigned long)(nxt)) & ~1)) == pq->tail) {
            goto out;
        }
        if (newhead == ((void *)0) && x->inserting) newhead = x;
        if ((((unsigned long)(nxt)) & 1)) continue;
        nxt = __sync_fetch_and_or(&x->next[0], 1);
    }
    while ( (x = ((void *)(((unsigned long)(nxt)) & ~1))) && (((unsigned long)(nxt)) & 1) );
    ((void) (0));
    v = x->v;
    if (newhead == ((void *)0)) newhead = x;
    if (offset <= pq->max_offset) goto out;
    if (pq->head->next[0] != obs_head) goto out;
    if (__sync_bool_compare_and_swap(&pq->head->next[0], obs_head, ((void *)(((unsigned long)(newhead)) | 1))))
    {
        restructure(pq);
        cur = ((void *)(((unsigned long)(obs_head)) & ~1));
        while (cur != ((void *)(((unsigned long)(newhead)) & ~1))) {
            nxt = ((void *)(((unsigned long)(cur->next[0])) & ~1));
            ((void) (0));
            free_node(cur);
            cur = nxt;
        }
    }
 out:
    gc_exit(ptst);
    return v;
}

variable_types: offset int

variable_types: lvl int


decompiled_code:
void __fastcall pq_destroy(void *ptr)
{
_QWORD *v2; // rbp
__int64 v3; // rdi

v2 = (_QWORD *)*((_QWORD *)ptr + 2);
while ( *((_QWORD **)ptr + 3) != v2 )
{
v3 = (__int64)v2;
v2 = (_QWORD *)(v2[3] & 0xFFFFFFFFFFFFFFFELL);
free_node(v3);
}
free(v2);
free(*((void **)ptr + 2));
free(ptr);
}

canonical_decompiled_code:
void __fastcall func6(void *ptr)
{
_QWORD *v2; // rbp
__int64 v3; // rdi

v2 = (_QWORD *)*((_QWORD *)ptr + 2);
while ( *((_QWORD **)ptr + 3) != v2 )
{
v3 = (__int64)v2;
v2 = (_QWORD *)(v2[3] & 0xFFFFFFFFFFFFFFFELL);
func2(v3);
}
free(v2);
free(*((void **)ptr + 2));
free(ptr);
}

original_code:
void
pq_destroy(pq_t *pq)
{
    node_t *cur, *pred;
    cur = pq->head;
    while (cur != pq->tail) {
        pred = cur;
        cur = ((void *)(((uintptr_t)(pred->next[0])) & ~1));
        free_node(pred);
    }
    free(pq->tail);
    free(pq->head);
    free(pq);
}

canonical_original_code:
void pq_destroy(struct pq_t *pq)
{
    struct node_s *cur; struct node_s *pred;
    cur = pq->head;
    while (cur != pq->tail) {
        pred = cur;
        cur = ((void *)(((unsigned long)(pred->next[0])) & ~1));
        free_node(pred);
    }
    free(pq->tail);
    free(pq->head);
    free(pq);
}


decompiled_code:
void *__fastcall removemin_thread(void *a1)
{
int v1; // ebp
unsigned __int64 v2; // rbx
unsigned __int64 v3; // r8
unsigned __int64 v4; // rax

v1 = 30;
v2 = 0LL;
do
{
v3 = deletemin(pq);
v4 = v2;
v2 = v3;
if ( v3 <= v4 )
_assert_fail("v > ov", "unittests.c", 0xF3u, "removemin_thread");
--v1;
}
while ( v1 );
return 0LL;
}

canonical_decompiled_code:
void *__fastcall func0(void *a1)
{
int v1; // ebp
unsigned __int64 v2; // rbx
unsigned __int64 v3; // r8
unsigned __int64 v4; // rax

v1 = 30;
v2 = 0LL;
do
{
v3 = deletemin(pq);
v4 = v2;
v2 = v3;
if ( v3 <= v4 )
_assert_fail("v > ov", "unittests.c", 0xF3u, "removemin_thread");
--v1;
}
while ( v1 );
return 0LL;
}

original_code:
void *
removemin_thread(void *id)
{
    unsigned long v, ov = 0;
    for(int i = 0; i < 30; i++) {
 v = (unsigned long) deletemin(pq);
 ((v > ov) ? (void) (0) : __assert_fail ("v > ov", "unittests.c", 243, __extension__ __PRETTY_FUNCTION__));
 ov = v;
    }
    return ((void *)0);
}

canonical_original_code:
void *removemin_thread(void *id)
{
    unsigned long v; unsigned long ov = 0;
    for(int i = 0; i < 30; i++) {
 v = (unsigned long) deletemin(pq);
 ((v > ov) ? (void) (0) : __assert_fail ("v > ov", "unittests.c", 243, __extension__ __PRETTY_FUNCTION__));
 ov = v;
    }
    return ((void *)0);
}

variable_types:
id
void *

variable_types:
v
unsigned long

variable_types:
ov
unsigned long


decompiled_code:
int test_parallel_add()
{
__int64 v0; // rbx
void *v1; // rcx
pthread_t *v2; // rdi
__int64 v3; // rbx
pthread_t v4; // rdi
__int64 v5; // rbp
unsigned __int64 v6; // rbx
unsigned __int64 v7; // r8
unsigned __int64 v8; // rax

printf("test parallel add, %d threads\n", (unsigned int)nthreads);
if ( nthreads > 0 )
{
v0 = 0LL;
do
{
v1 = (void *)v0;
v2 = (pthread_t *)(ts + 8 * v0++);
pthread_create(v2, 0LL, add_thread, v1);
}
while ( nthreads > v0 );
if ( nthreads > 0 )
{
v3 = 0LL;
do
{
v4 = *(_QWORD *)(ts + 8 * v3++);
pthread_join(v4, 0LL);
}
while ( nthreads > v3 );
if ( nthreads > 0 )
{
v5 = 0LL;
v6 = 0LL;
do
{
v7 = deletemin(pq);
v8 = v6;
v6 = v7;
if ( v7 <= v8 )
_assert_fail("old < new", "unittests.c", 0x34u, "test_parallel_add");
++v5;
}
while ( 30 * nthreads > v5 );
}
}
}
return puts("OK.");
}

canonical_decompiled_code:
int func1()
{
__int64 v0; // rbx
void *v1; // rcx
pthread_t *v2; // rdi
__int64 v3; // rbx
pthread_t v4; // rdi
__int64 v5; // rbp
unsigned __int64 v6; // rbx
unsigned __int64 v7; // r8
unsigned __int64 v8; // rax

printf("test parallel add, %d threads\n", (unsigned int)nthreads);
if ( nthreads > 0 )
{
v0 = 0LL;
do
{
v1 = (void *)v0;
v2 = (pthread_t *)(ts + 8 * v0++);
pthread_create(v2, 0LL, add_thread, v1);
}
while ( nthreads > v0 );
if ( nthreads > 0 )
{
v3 = 0LL;
do
{
v4 = *(_QWORD *)(ts + 8 * v3++);
pthread_join(v4, 0LL);
}
while ( nthreads > v3 );
if ( nthreads > 0 )
{
v5 = 0LL;
v6 = 0LL;
do
{
v7 = deletemin(pq);
v8 = v6;
v6 = v7;
if ( v7 <= v8 )
_assert_fail("old < new", "unittests.c", 0x34u, "test_parallel_add");
++v5;
}
while ( 30 * nthreads > v5 );
}
}
}
return puts("OK.");
}

original_code:
void
test_parallel_add()
{
    printf("test parallel add, %d threads\n", nthreads);
    for (long i = 0; i < nthreads; i ++)
        pthread_create (&ts[i], ((void *)0), add_thread, (void *)i);
    for (long i = 0; i < nthreads; i ++)
 (void)pthread_join (ts[i], ((void *)0));
    unsigned long new, old = 0;
    for (long i = 0; i < nthreads * 30; i++) {
 new = (long)deletemin(pq);
 ((old < new) ? (void) (0) : __assert_fail ("old < new", "unittests.c", 52, __extension__ __PRETTY_FUNCTION__));
 old = new;
    }
    printf("OK.\n");
}

canonical_original_code:
void test_parallel_add()
{
    printf("test parallel add, %d threads\n", nthreads);
    for (long i = 0; i < nthreads; i ++)
        pthread_create (&ts[i], ((void *)0), add_thread, (void *)i);
    for (long i = 0; i < nthreads; i ++)
 (void)pthread_join (ts[i], ((void *)0));
    unsigned long new; unsigned long old = 0;
    for (long i = 0; i < nthreads * 30; i++) {
 new = (long)deletemin(pq);
 ((old < new) ? (void) (0) : __assert_fail ("old < new", "unittests.c", 52, __extension__ __PRETTY_FUNCTION__));
 old = new;
    }
    printf("OK.\n");
}

variable_types: i long

variable_types:
new
unsigned long

variable_types:
old
unsigned long


decompiled_code:
int test_parallel_del()
{
__int64 v0; // rbx
__int64 v1; // rcx
__int64 v2; // rbx
void *v3; // rcx
pthread_t *v4; // rdi
__int64 v5; // rbx
pthread_t v6; // rdi

printf("test parallel del, %d threads\n", (unsigned int)nthreads);
if ( nthreads > 0 )
{
v0 = 1LL;
do
{
insert(pq, v0, v0);
v1 = v0++;
}
while ( 30 * nthreads > v1 );
if ( nthreads > 0 )
{
v2 = 0LL;
do
{
v3 = (void *)v2;
v4 = (pthread_t *)(ts + 8 * v2++);
pthread_create(v4, 0LL, removemin_thread, v3);
}
while ( nthreads > v2 );
if ( nthreads > 0 )
{
v5 = 0LL;
do
{
v6 = *(_QWORD *)(ts + 8 * v5++);
pthread_join(v6, 0LL);
}
while ( nthreads > v5 );
}
}
}
return puts("OK.");
}

canonical_decompiled_code:
int func2()
{
__int64 v0; // rbx
__int64 v1; // rcx
__int64 v2; // rbx
void *v3; // rcx
pthread_t *v4; // rdi
__int64 v5; // rbx
pthread_t v6; // rdi

printf("test parallel del, %d threads\n", (unsigned int)nthreads);
if ( nthreads > 0 )
{
v0 = 1LL;
do
{
insert(pq, v0, v0);
v1 = v0++;
}
while ( 30 * nthreads > v1 );
if ( nthreads > 0 )
{
v2 = 0LL;
do
{
v3 = (void *)v2;
v4 = (pthread_t *)(ts + 8 * v2++);
pthread_create(v4, 0LL, removemin_thread, v3);
}
while ( nthreads > v2 );
if ( nthreads > 0 )
{
v5 = 0LL;
do
{
v6 = *(_QWORD *)(ts + 8 * v5++);
pthread_join(v6, 0LL);
}
while ( nthreads > v5 );
}
}
}
return puts("OK.");
}

original_code:
void
test_parallel_del()
{
    printf("test parallel del, %d threads\n", nthreads);
    for (long i = 0; i < nthreads * 30; i++)
 insert(pq, i+1, (pval_t)i+1);
    for (long i = 0; i < nthreads; i ++)
        pthread_create (&ts[i], ((void *)0), removemin_thread, (void *)i);
    for (long i = 0; i < nthreads; i ++)
 (void)pthread_join (ts[i], ((void *)0));
    printf("OK.\n");
}

canonical_original_code:
void test_parallel_del()
{
    printf("test parallel del, %d threads\n", nthreads);
    for (long i = 0; i < nthreads * 30; i++)
 insert(pq, i+1, (void *)i+1);
    for (long i = 0; i < nthreads; i ++)
        pthread_create (&ts[i], ((void *)0), removemin_thread, (void *)i);
    for (long i = 0; i < nthreads; i ++)
 (void)pthread_join (ts[i], ((void *)0));
    printf("OK.\n");
}


decompiled_code:
void *__fastcall add_thread(void *a1)
{
__int64 v1; // rbx
__int64 v2; // rdx
__int64 v3; // rsi

v1 = 30LL * (_QWORD)a1 + 1;
do
{
v2 = v1;
v3 = v1++;
insert(pq, v3, v2);
}
while ( v1 != 30LL * (_QWORD)a1 + 31 );
return 0LL;
}

canonical_decompiled_code:
void *__fastcall func3(void *a1)
{
__int64 v1; // rbx
__int64 v2; // rdx
__int64 v3; // rsi

v1 = 30LL * (_QWORD)a1 + 1;
do
{
v2 = v1;
v3 = v1++;
insert(pq, v3, v2);
}
while ( v1 != 30LL * (_QWORD)a1 + 31 );
return 0LL;
}

original_code:
void *
add_thread(void *id)
{
    long base = 30 * (long)id;
    for(int i = 0; i < 30; i++)
 insert(pq, base+i+1, (pval_t) base+i+1);
    return ((void *)0);
}

canonical_original_code:
void *add_thread(void *id)
{
    long base = 30 * (long)id;
    for(int i = 0; i < 30; i++)
 insert(pq, base+i+1, (void *) base+i+1);
    return ((void *)0);
}

variable_types: base long


decompiled_code:
void *__fastcall invariant_thread(void *a1)
{
unsigned __int16 *v1; // rbx
double v2; // xmm0_8
__int64 v3; // rbp
__int64 v4; // rax

v1 = (unsigned __int16 *)((char *)&rng + __readfsqword(0));
rng_init(v1);
while ( !abort_loop )
{
while ( 1 )
{
if ( halt )
{
_InterlockedAdd(&stop, 1u);
while ( halt )
_mm_lfence();
}
v2 = erand48(v1);
v3 = pq;
if ( v2 >= 0.5 )
break;
v4 = nrand48(v1);
insert(v3, v4 + 1, v4 + 1);
if ( abort_loop )
return 0LL;
}
deletemin(pq);
}
return 0LL;
}

canonical_decompiled_code:
void *__fastcall func4(void *a1)
{
unsigned __int16 *v1; // rbx
double v2; // xmm0_8
__int64 v3; // rbp
__int64 v4; // rax

v1 = (unsigned __int16 *)((char *)&rng + __readfsqword(0));
rng_init(v1);
while ( !abort_loop )
{
while ( 1 )
{
if ( halt )
{
_InterlockedAdd(&stop, 1u);
while ( halt )
_mm_lfence();
}
v2 = erand48(v1);
v3 = pq;
if ( v2 >= 0.5 )
break;
v4 = nrand48(v1);
insert(v3, v4 + 1, v4 + 1);
if ( abort_loop )
return 0LL;
}
deletemin(pq);
}
return 0LL;
}

original_code:
void *
invariant_thread(void *_args)
{
    unsigned long id = (unsigned long)_args;
    unsigned long elem;
    int cnt = 0;
    rng_init(rng);
    while(!abort_loop) {
 if (halt) {
     __sync_fetch_and_add(&stop, 1);
     while(halt)
  __asm__ __volatile__("lfence":::"memory");
 }
 if (erand48(rng) < 0.5) {
     elem = nrand48(rng);
     insert(pq, elem+1, (pval_t)elem + 1);
 } else {
     deletemin(pq);
 }
 cnt++;
    }
    return ((void *)0);
}

canonical_original_code:
void *invariant_thread(void *_args)
{
    unsigned long id = (unsigned long)_args;
    unsigned long elem;
    int cnt = 0;
    rng_init(rng);
    while(!abort_loop) {
 if (halt) {
     __sync_fetch_and_add(&stop, 1);
     while(halt)
  __asm__ __volatile__("lfence":::"memory");
 }
 if (erand48(rng) < 0.5) {
     elem = nrand48(rng);
     insert(pq, elem+1, (void *)elem + 1);
 } else {
     deletemin(pq);
 }
 cnt++;
    }
    return ((void *)0);
}

variable_types:
id
unsigned long

variable_types:
elem
unsigned long

variable_types: cnt int


decompiled_code:
unsigned __int64 __fastcall check_invariants(__int64 a1)
{
__int64 v1; // r9
__int64 v2; // rdx
__int64 v3; // rax
__int64 v4; // rcx
__int64 v5; // r10
unsigned __int64 v6; // rsi
int v7; // edx
unsigned __int64 v8; // r8
_QWORD *v9; // rax
__int64 v10; // rsi
unsigned __int64 result; // rax

v1 = *(_QWORD *)(a1 + 16);
v2 = *(_QWORD *)(v1 + 24);
if ( (v2 & 1) != 0 )
{
v3 = *(_QWORD *)(v1 + 24);
do
{
v3 = *(_QWORD *)((v3 & 0xFFFFFFFFFFFFFFFELL) + 24);
v2 = v3;
}
while ( (v3 & 1) != 0 );
}
v4 = *(_QWORD *)(v2 + 24);
v5 = *(_QWORD *)(a1 + 24);
if ( v5 != v4 )
{
v6 = *(_QWORD *)(v2 + 24) & 1LL;
if ( (v4 & 1) != 0 )
LABEL_14:
_assert_fail("!is_marked_ref(cur)", "unittests.c", 0x63u, "check_invariants");
while ( 1 )
{
v7 = *(_DWORD *)(v4 + 8);
v8 = v6;
v6 = *(_QWORD *)v4;
if ( v7 > 1 )
{
v9 = (_QWORD *)(v4 + 32);
do
{
if ( !*v9 )
break;
if ( *(_QWORD *)*v9 <= v6 )
_assert_fail("cur->k < cur->next[i]->k", "unittests.c", 0x67u, "check_invariants");
++v9;
}
while ( (_QWORD *)(v4 + 8LL * (unsigned int)(v7 - 2) + 40) != v9 );
}
if ( v8 >= v6 )
_assert_fail("cur->k > k", "unittests.c", 0x6Au, "check_invariants");
v4 = *(_QWORD *)(v4 + 24);
if ( v5 == v4 )
break;
if ( (v4 & 1) != 0 )
goto LABEL_14;
}
}
v10 = 31LL;
do
{
for ( result = *(_QWORD *)(v1 + 8 * v10 + 24) & 0xFFFFFFFFFFFFFFFELL;
result != v4;
result = *(_QWORD *)(result + 8 * ((int)v10 + 2LL) + 8) & 0xFFFFFFFFFFFFFFFELL )
{
;
}
--v10;
}
while ( v10 );
return result;
}

canonical_decompiled_code:
unsigned __int64 __fastcall func5(__int64 a1)
{
__int64 v1; // r9
__int64 v2; // rdx
__int64 v3; // rax
__int64 v4; // rcx
__int64 v5; // r10
unsigned __int64 v6; // rsi
int v7; // edx
unsigned __int64 v8; // r8
_QWORD *v9; // rax
__int64 v10; // rsi
unsigned __int64 result; // rax

v1 = *(_QWORD *)(a1 + 16);
v2 = *(_QWORD *)(v1 + 24);
if ( (v2 & 1) != 0 )
{
v3 = *(_QWORD *)(v1 + 24);
do
{
v3 = *(_QWORD *)((v3 & 0xFFFFFFFFFFFFFFFELL) + 24);
v2 = v3;
}
while ( (v3 & 1) != 0 );
}
v4 = *(_QWORD *)(v2 + 24);
v5 = *(_QWORD *)(a1 + 24);
if ( v5 != v4 )
{
v6 = *(_QWORD *)(v2 + 24) & 1LL;
if ( (v4 & 1) != 0 )
LABEL_14:
_assert_fail("!is_marked_ref(cur)", "unittests.c", 0x63u, "check_invariants");
while ( 1 )
{
v7 = *(_DWORD *)(v4 + 8);
v8 = v6;
v6 = *(_QWORD *)v4;
if ( v7 > 1 )
{
v9 = (_QWORD *)(v4 + 32);
do
{
if ( !*v9 )
break;
if ( *(_QWORD *)*v9 <= v6 )
_assert_fail("cur->k < cur->next[i]->k", "unittests.c", 0x67u, "check_invariants");
++v9;
}
while ( (_QWORD *)(v4 + 8LL * (unsigned int)(v7 - 2) + 40) != v9 );
}
if ( v8 >= v6 )
_assert_fail("cur->k > k", "unittests.c", 0x6Au, "check_invariants");
v4 = *(_QWORD *)(v4 + 24);
if ( v5 == v4 )
break;
if ( (v4 & 1) != 0 )
goto LABEL_14;
}
}
v10 = 31LL;
do
{
for ( result = *(_QWORD *)(v1 + 8 * v10 + 24) & 0xFFFFFFFFFFFFFFFELL;
result != v4;
result = *(_QWORD *)(result + 8 * ((int)v10 + 2LL) + 8) & 0xFFFFFFFFFFFFFFFELL )
{
;
}
--v10;
}
while ( v10 );
return result;
}

original_code:
void
check_invariants(pq_t *pq)
{
    node_t *cur, *pred;
    int cnt = 0;
    unsigned long long k = 0;
    int i = 0;
    cur = pq->head->next[0];
    while ((((uintptr_t)(cur)) & 1)) {
 pred = ((void *)(((uintptr_t)(cur)) & ~1));
 cur = pred->next[0];
 cnt++;
    }
    pred = cur;
    cur = pred->next[0];
    while (cur != pq->tail) {
 ((!(((uintptr_t)(cur)) & 1)) ? (void) (0) : __assert_fail ("!is_marked_ref(cur)", "unittests.c", 99, __extension__ __PRETTY_FUNCTION__));
 i = 1;
 while(i < cur->level && cur->next[i]) {
     ((cur->k < cur->next[i]->k) ? (void) (0) : __assert_fail ("cur->k < cur->next[i]->k", "unittests.c", 103, __extension__ __PRETTY_FUNCTION__));
     i++;
 }
 ((cur->k > k) ? (void) (0) : __assert_fail ("cur->k > k", "unittests.c", 106, __extension__ __PRETTY_FUNCTION__));
 k = cur->k;
 pred = cur;
 cur = pred->next[0];
 cnt++;
    }
    k = 0;
    for (int i = 31; i > 0; i--) {
 cur = ((void *)(((uintptr_t)(pq->head->next[i])) & ~1));
 while(cur != pq->tail) {
     cur = ((void *)(((uintptr_t)(cur->next[i])) & ~1));
 }
    }
}

canonical_original_code:
void check_invariants(struct pq_t *pq)
{
    struct node_s *cur; struct node_s *pred;
    int cnt = 0;
    unsigned long long k = 0;
    int i = 0;
    cur = pq->head->next[0];
    while ((((unsigned long)(cur)) & 1)) {
 pred = ((void *)(((unsigned long)(cur)) & ~1));
 cur = pred->next[0];
 cnt++;
    }
    pred = cur;
    cur = pred->next[0];
    while (cur != pq->tail) {
 ((!(((unsigned long)(cur)) & 1)) ? (void) (0) : __assert_fail ("!is_marked_ref(cur)", "unittests.c", 99, __extension__ __PRETTY_FUNCTION__));
 i = 1;
 while(i < cur->level && cur->next[i]) {
     ((cur->k < cur->next[i]->k) ? (void) (0) : __assert_fail ("cur->k < cur->next[i]->k", "unittests.c", 103, __extension__ __PRETTY_FUNCTION__));
     i++;
 }
 ((cur->k > k) ? (void) (0) : __assert_fail ("cur->k > k", "unittests.c", 106, __extension__ __PRETTY_FUNCTION__));
 k = cur->k;
 pred = cur;
 cur = pred->next[0];
 cnt++;
    }
    k = 0;
    for (int i = 31; i > 0; i--) {
 cur = ((void *)(((unsigned long)(pq->head->next[i])) & ~1));
 while(cur != pq->tail) {
     cur = ((void *)(((unsigned long)(cur->next[i])) & ~1));
 }
    }
}

variable_types: struct pq_t { int max_offset; int max_level; int nthreads; struct node_s { unsigned long k; int level; int inserting; void *v; struct node_s *next[1]; } *head; struct node_s *tail; char pad[128]; } *

variable_types:
k
unsigned long long

variable_types: i int


setup

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

init_gc_subsystem();
result = pq_init(a1);
pq = result;
return result;
}

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

init_gc_subsystem();
result = pq_init(a1);
pq = result;
return result;
}

original_code:
void
setup (int max_offset)
{
    _init_gc_subsystem();
    pq = pq_init(max_offset);
}

canonical_original_code:
void setup(int max_offset)
{
    _init_gc_subsystem();
    pq = pq_init(max_offset);
}


teardown

decompiled_code:
__int64 teardown()
{
pq_destroy(pq);
return destroy_gc_subsystem();
}

canonical_decompiled_code:
__int64 func8()
{
pq_destroy(pq);
return destroy_gc_subsystem();
}

original_code:
void
teardown ()
{
    pq_destroy(pq);
    _destroy_gc_subsystem();
}

canonical_original_code:
void teardown()
{
    pq_destroy(pq);
    _destroy_gc_subsystem();
}


main

canonical_name: main

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

nthreads = 8;
ts = (__int64)malloc(0x40uLL);
if ( !ts )
_assert_fail("ts", "unittests.c", 0xBAu, "main");
v3 = &tests;
if ( tests )
{
do
{
setup(0xAu);
((void (__fastcall *)(__int64, const char **))*v3++)(10LL, argv);
teardown();
}
while ( *v3 );
}
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 (__fastcall **v3)(); // rbx

nthreads = 8;
ts = (__int64)malloc(0x40uLL);
if ( !ts )
_assert_fail("ts", "unittests.c", 0xBAu, "main");
v3 = &tests;
if ( tests )
{
do
{
func7(0xAu);
((void (__fastcall *)(__int64, const char **))*v3++)(10LL, argv);
func8();
}
while ( *v3 );
}
return 0;
}

original_code:
int
main(int argc, char **argv)
{
    nthreads = 8;
    ts = malloc(nthreads * sizeof(pthread_t));
    ((ts) ? (void) (0) : __assert_fail ("ts", "unittests.c", 186, __extension__ __PRETTY_FUNCTION__));
    for(test_func_t *tf = tests; *tf; tf++) {
        setup(10);
        (*tf)();
        teardown();
    }
    return 0;
}

canonical_original_code:
int main(int argc, char **argv)
{
    nthreads = 8;
    ts = malloc(nthreads * sizeof(pthread_t));
    ((ts) ? (void) (0) : __assert_fail ("ts", "unittests.c", 186, __extension__ __PRETTY_FUNCTION__));
    for(void (**tf)() = tests; *tf; tf++) {
        setup(10);
        (*tf)();
        teardown();
    }
    return 0;
}

variable_types: argc int

variable_types:
argv
char **

variable_types:
tf
void (**)()


repo: jonathanhefner/sxc

original_code:
static void* map_iter(SxcMap* map, void* state, SxcValue* return_key, SxcValue* return_value) {
  while ((state = (map->binding->iter)(map->underlying, state, return_key, return_value))) {
    switch (return_key->type) {
      case sxc_cint:
      case sxc_sstring:
        return state;
      case sxc_cdouble:
        if (return_key->data.cdouble == (double)(int)(return_key->data.cdouble)) {
          sxc_value_set(return_key, sxc_cint, (int)(return_key->data.cdouble));
          return state;
        }
      default:
        break;
    }
  }
  return ((void *)0);
}

canonical_original_code:
static void *map_iter(struct _SxcMap *map, void *state, struct _SxcValue *return_key, struct _SxcValue *return_value) {
  while ((state = (map->binding->iter)(map->underlying, state, return_key, return_value))) {
    switch (return_key->type) {
      case sxc_cint:
      case sxc_sstring:
        return state;
      case sxc_cdouble:
        if (return_key->data.cdouble == (double)(int)(return_key->data.cdouble)) {
          sxc_value_set(return_key, sxc_cint, (int)(return_key->data.cdouble));
          return state;
        }
      default:
        break;
    }
  }
  return ((void *)0);
}

variable_types: struct _SxcMap { void *underlying; struct _SxcMapBinding { void (*intget)(void *underlying, int key, struct _SxcValue { struct _SxcContext { void *underlying; struct _SxcContextBinding { void (*get_arg)(void *underlying, int index, struct _SxcValue *return_value); void (*to_sstring)(char *data, int length, struct _SxcValue *return_value); void (*map_new)(void *map_type, struct _SxcValue *return_value); void *(*map_newtype)(struct _SxcContext *context, char *name, void (*initializer)(struct _SxcContext *context), struct _SxcLibMethod { char *name; int is_static; void (*func)(struct _SxcContext *context); } *methods, struct _SxcLibProperty { char *name; int is_static; void (*getter)(struct _SxcContext *context); void (*setter)(struct _SxcContext *context); } *properties); void (*to_sfunc)(void (*func)(struct _SxcContext *context), struct _SxcValue *return_value); } *binding; int argcount; struct _SxcValue return_value; int has_error; void *_jmpbuf; struct _SxcMemoryChunk { int free_space; struct _SxcMemoryChunk *next_chunk; int offset; char data; } _firstchunk; char _firstdata[-1]; } *context; enum _SxcDataType { sxc_null=0, sxc_cbool=1, sxc_cint=2, sxc_cdouble=3, sxc_string=4, sxc_map=5, sxc_func=6, sxc_sstring=7, sxc_smap=8, sxc_sfunc=9, sxc_cstring=10, sxc_cpointer=11, sxc_cfunc=12, sxc_cchars=13, sxc_cbools=14, sxc_cints=15, sxc_cdoubles=16, sxc_cstrings=17 } type; union _SxcData { _Bool cbool; int cint; double cdouble; void *_pointer_store; struct _SxcString { void *underlying; struct _SxcStringBinding { void (*to_cchars)(void *underlying, struct _SxcValue *return_value); int is_null_terminated; } *binding; struct _SxcContext *context; char *data; int length; } *string; struct _SxcMap *map; struct _SxcFunc { void *underlying; struct _SxcFunctionBinding { void (*invoke)(void *underlying, struct _SxcValue **args, int argcount, struct _SxcValue *return_value); } *binding; struct _SxcContext *context; } *func; struct { void *underlying; void *binding; } _binding_store; struct { void *underlying; struct _SxcStringBinding *binding; } sstring; struct { void *underlying; struct _SxcMapBinding *binding; } smap; struct { void *underlying; struct _SxcFunctionBinding *binding; } sfunc; char *cstring; void (*cfunc)(struct _SxcContext *context); void *cpointer; struct { void *array; int length; } _array_store; struct { char *array; int length; } cchars; struct { _Bool *array; int length; } cbools; struct { int *array; int length; } cints; struct { double *array; int length; } cdoubles; struct { char **array; int length; } cstrings; } data; } *return_value); void (*intset)(void *underlying, int key, struct _SxcValue *value); void (*strget)(void *underlying, char *key, struct _SxcValue *return_value); void (*strset)(void *underlying, char *key, struct _SxcValue *value); int (*length)(void *underlying); void *(*iter)(void *underlying, void *state, struct _SxcValue *return_key, struct _SxcValue *return_value); } *binding; struct _SxcContext *context; } *

variable_types:
state
void *

user_defined_types: struct _SxcMap { void *underlying; struct _SxcMapBinding *binding; struct _SxcContext *context; }

user_defined_types: struct _SxcMapBinding { void (*intget)(void *underlying, int key, struct _SxcValue *return_value); void (*intset)(void *underlying, int key, struct _SxcValue *value); void (*strget)(void *underlying, char *key, struct _SxcValue *return_value); void (*strset)(void *underlying, char *key, struct _SxcValue *value); int (*length)(void *underlying); void *(*iter)(void *underlying, void *state, struct _SxcValue *return_key, struct _SxcValue *return_value); }

user_defined_types: struct _SxcValue { struct _SxcContext *context; enum _SxcDataType type; union _SxcData data; }

user_defined_types: union _SxcData { _Bool cbool; int cint; double cdouble; void *_pointer_store; struct _SxcString *string; struct _SxcMap *map; struct _SxcFunc *func; struct { void *underlying; void *binding; } _binding_store; struct { void *underlying; struct _SxcStringBinding *binding; } sstring; struct { void *underlying; struct _SxcMapBinding *binding; } smap; struct { void *underlying; struct _SxcFunctionBinding *binding; } sfunc; char *cstring; void (*cfunc)(struct _SxcContext *context); void *cpointer; struct { void *array; int length; } _array_store; struct { char *array; int length; } cchars; struct { _Bool *array; int length; } cbools; struct { int *array; int length; } cints; struct { double *array; int length; } cdoubles; struct { char **array; int length; } cstrings; }

user_defined_types: struct _SxcContext { void *underlying; struct _SxcContextBinding *binding; int argcount; struct _SxcValue return_value; int has_error; void *_jmpbuf; struct _SxcMemoryChunk _firstchunk; char _firstdata[-1]; }

user_defined_types: struct _SxcString { void *underlying; struct _SxcStringBinding *binding; struct _SxcContext *context; char *data; int length; }

user_defined_types: struct _SxcFunc { void *underlying; struct _SxcFunctionBinding *binding; struct _SxcContext *context; }

user_defined_types: struct _SxcContextBinding { void (*get_arg)(void *underlying, int index, struct _SxcValue *return_value); void (*to_sstring)(char *data, int length, struct _SxcValue *return_value); void (*map_new)(void *map_type, struct _SxcValue *return_value); void *(*map_newtype)(struct _SxcContext *context, char *name, void (*initializer)(struct _SxcContext *context), struct _SxcLibMethod *methods, struct _SxcLibProperty *properties); void (*to_sfunc)(void (*func)(struct _SxcContext *context), struct _SxcValue *return_value); }


original_code:
SxcMap* sxc_map_new(SxcContext* context, void* map_type) {
  SxcValue value;
  SxcMap* map;
  value.context = context;
  (context->binding->map_new)(map_type, &value);
  sxc_value_get(&value, sxc_map, &map);
  return map;
}

canonical_original_code:
struct _SxcMap *sxc_map_new(struct _SxcContext *context, void *map_type) {
  struct _SxcValue value;
  struct _SxcMap *map;
  value.context = context;
  (context->binding->map_new)(map_type, &value);
  sxc_value_get(&value, sxc_map, &map);
  return map;
}

variable_types:
context
struct _SxcContext *

variable_types: struct _SxcValue { struct _SxcContext { void *underlying; struct _SxcContextBinding { void (*get_arg)(void *underlying, int index, struct _SxcValue *return_value); void (*to_sstring)(char *data, int length, struct _SxcValue *return_value); void (*map_new)(void *map_type, struct _SxcValue *return_value); void *(*map_newtype)(struct _SxcContext *context, char *name, void (*initializer)(struct _SxcContext *context), struct _SxcLibMethod { char *name; int is_static; void (*func)(struct _SxcContext *context); } *methods, struct _SxcLibProperty { char *name; int is_static; void (*getter)(struct _SxcContext *context); void (*setter)(struct _SxcContext *context); } *properties); void (*to_sfunc)(void (*func)(struct _SxcContext *context), struct _SxcValue *return_value); } *binding; int argcount; struct _SxcValue return_value; int has_error; void *_jmpbuf; struct _SxcMemoryChunk { int free_space; struct _SxcMemoryChunk *next_chunk; int offset; char data; } _firstchunk; char _firstdata[-1]; } *context; enum _SxcDataType { sxc_null=0, sxc_cbool=1, sxc_cint=2, sxc_cdouble=3, sxc_string=4, sxc_map=5, sxc_func=6, sxc_sstring=7, sxc_smap=8, sxc_sfunc=9, sxc_cstring=10, sxc_cpointer=11, sxc_cfunc=12, sxc_cchars=13, sxc_cbools=14, sxc_cints=15, sxc_cdoubles=16, sxc_cstrings=17 } type; union _SxcData { _Bool cbool; int cint; double cdouble; void *_pointer_store; struct _SxcString { void *underlying; struct _SxcStringBinding { void (*to_cchars)(void *underlying, struct _SxcValue *return_value); int is_null_terminated; } *binding; struct _SxcContext *context; char *data; int length; } *string; struct _SxcMap { void *underlying; struct _SxcMapBinding { void (*intget)(void *underlying, int key, struct _SxcValue *return_value); void (*intset)(void *underlying, int key, struct _SxcValue *value); void (*strget)(void *underlying, char *key, struct _SxcValue *return_value); void (*strset)(void *underlying, char *key, struct _SxcValue *value); int (*length)(void *underlying); void *(*iter)(void *underlying, void *state, struct _SxcValue *return_key, struct _SxcValue *return_value); } *binding; struct _SxcContext *context; } *map; struct _SxcFunc { void *underlying; struct _SxcFunctionBinding { void (*invoke)(void *underlying, struct _SxcValue **args, int argcount, struct _SxcValue *return_value); } *binding; struct _SxcContext *context; } *func; struct { void *underlying; void *binding; } _binding_store; struct { void *underlying; struct _SxcStringBinding *binding; } sstring; struct { void *underlying; struct _SxcMapBinding *binding; } smap; struct { void *underlying; struct _SxcFunctionBinding *binding; } sfunc; char *cstring; void (*cfunc)(struct _SxcContext *context); void *cpointer; struct { void *array; int length; } _array_store; struct { char *array; int length; } cchars; struct { _Bool *array; int length; } cbools; struct { int *array; int length; } cints; struct { double *array; int length; } cdoubles; struct { char **array; int length; } cstrings; } data; }

return_type: struct _SxcMap { void *underlying; struct _SxcMapBinding { void (*intget)(void *underlying, int key, struct _SxcValue { struct _SxcContext { void *underlying; struct _SxcContextBinding { void (*get_arg)(void *underlying, int index, struct _SxcValue *return_value); void (*to_sstring)(char *data, int length, struct _SxcValue *return_value); void (*map_new)(void *map_type, struct _SxcValue *return_value); void *(*map_newtype)(struct _SxcContext *context, char *name, void (*initializer)(struct _SxcContext *context), struct _SxcLibMethod { char *name; int is_static; void (*func)(struct _SxcContext *context); } *methods, struct _SxcLibProperty { char *name; int is_static; void (*getter)(struct _SxcContext *context); void (*setter)(struct _SxcContext *context); } *properties); void (*to_sfunc)(void (*func)(struct _SxcContext *context), struct _SxcValue *return_value); } *binding; int argcount; struct _SxcValue return_value; int has_error; void *_jmpbuf; struct _SxcMemoryChunk { int free_space; struct _SxcMemoryChunk *next_chunk; int offset; char data; } _firstchunk; char _firstdata[-1]; } *context; enum _SxcDataType { sxc_null=0, sxc_cbool=1, sxc_cint=2, sxc_cdouble=3, sxc_string=4, sxc_map=5, sxc_func=6, sxc_sstring=7, sxc_smap=8, sxc_sfunc=9, sxc_cstring=10, sxc_cpointer=11, sxc_cfunc=12, sxc_cchars=13, sxc_cbools=14, sxc_cints=15, sxc_cdoubles=16, sxc_cstrings=17 } type; union _SxcData { _Bool cbool; int cint; double cdouble; void *_pointer_store; struct _SxcString { void *underlying; struct _SxcStringBinding { void (*to_cchars)(void *underlying, struct _SxcValue *return_value); int is_null_terminated; } *binding; struct _SxcContext *context; char *data; int length; } *string; struct _SxcMap *map; struct _SxcFunc { void *underlying; struct _SxcFunctionBinding { void (*invoke)(void *underlying, struct _SxcValue **args, int argcount, struct _SxcValue *return_value); } *binding; struct _SxcContext *context; } *func; struct { void *underlying; void *binding; } _binding_store; struct { void *underlying; struct _SxcStringBinding *binding; } sstring; struct { void *underlying; struct _SxcMapBinding *binding; } smap; struct { void *underlying; struct _SxcFunctionBinding *binding; } sfunc; char *cstring; void (*cfunc)(struct _SxcContext *context); void *cpointer; struct { void *array; int length; } _array_store; struct { char *array; int length; } cchars; struct { _Bool *array; int length; } cbools; struct { int *array; int length; } cints; struct { double *array; int length; } cdoubles; struct { char **array; int length; } cstrings; } data; } *return_value); void (*intset)(void *underlying, int key, struct _SxcValue *value); void (*strget)(void *underlying, char *key, struct _SxcValue *return_value); void (*strset)(void *underlying, char *key, struct _SxcValue *value); int (*length)(void *underlying); void *(*iter)(void *underlying, void *state, struct _SxcValue *return_key, struct _SxcValue *return_value); } *binding; struct _SxcContext *context; } *


original_code:
void* sxc_map_newtype(SxcContext* context, const char* name, SxcLibFunc* initialzier,
                      const SxcLibMethod* methods, const SxcLibProperty* properties) {
  const SxcLibMethod no_methods[] = { {0} };
  const SxcLibProperty no_properties[] = { {0} };
  return (context->binding->map_newtype)(context, name, initialzier,
    methods == ((void *)0) ? no_methods : methods, properties == ((void *)0) ? no_properties : properties);
}

canonical_original_code:
void *sxc_map_newtype(struct _SxcContext *context, char *name, void (*initialzier)(struct _SxcContext *context), struct _SxcLibMethod *methods, struct _SxcLibProperty *properties) {
  struct _SxcLibMethod no_methods[] = { {0} };
  struct _SxcLibProperty no_properties[] = { {0} };
  return (context->binding->map_newtype)(context, name, initialzier,
    methods == ((void *)0) ? no_methods : methods, properties == ((void *)0) ? no_properties : properties);
}

variable_types: struct _SxcContext { void *underlying; struct _SxcContextBinding { void (*get_arg)(void *underlying, int index, struct _SxcValue { struct _SxcContext *context; enum _SxcDataType { sxc_null=0, sxc_cbool=1, sxc_cint=2, sxc_cdouble=3, sxc_string=4, sxc_map=5, sxc_func=6, sxc_sstring=7, sxc_smap=8, sxc_sfunc=9, sxc_cstring=10, sxc_cpointer=11, sxc_cfunc=12, sxc_cchars=13, sxc_cbools=14, sxc_cints=15, sxc_cdoubles=16, sxc_cstrings=17 } type; union _SxcData { _Bool cbool; int cint; double cdouble; void *_pointer_store; struct _SxcString { void *underlying; struct _SxcStringBinding { void (*to_cchars)(void *underlying, struct _SxcValue *return_value); int is_null_terminated; } *binding; struct _SxcContext *context; char *data; int length; } *string; struct _SxcMap { void *underlying; struct _SxcMapBinding { void (*intget)(void *underlying, int key, struct _SxcValue *return_value); void (*intset)(void *underlying, int key, struct _SxcValue *value); void (*strget)(void *underlying, char *key, struct _SxcValue *return_value); void (*strset)(void *underlying, char *key, struct _SxcValue *value); int (*length)(void *underlying); void *(*iter)(void *underlying, void *state, struct _SxcValue *return_key, struct _SxcValue *return_value); } *binding; struct _SxcContext *context; } *map; struct _SxcFunc { void *underlying; struct _SxcFunctionBinding { void (*invoke)(void *underlying, struct _SxcValue **args, int argcount, struct _SxcValue *return_value); } *binding; struct _SxcContext *context; } *func; struct { void *underlying; void *binding; } _binding_store; struct { void *underlying; struct _SxcStringBinding *binding; } sstring; struct { void *underlying; struct _SxcMapBinding *binding; } smap; struct { void *underlying; struct _SxcFunctionBinding *binding; } sfunc; char *cstring; void (*cfunc)(struct _SxcContext *context); void *cpointer; struct { void *array; int length; } _array_store; struct { char *array; int length; } cchars; struct { _Bool *array; int length; } cbools; struct { int *array; int length; } cints; struct { double *array; int length; } cdoubles; struct { char **array; int length; } cstrings; } data; } *return_value); void (*to_sstring)(char *data, int length, struct _SxcValue *return_value); void (*map_new)(void *map_type, struct _SxcValue *return_value); void *(*map_newtype)(struct _SxcContext *context, char *name, void (*initializer)(struct _SxcContext *context), struct _SxcLibMethod { char *name; int is_static; void (*func)(struct _SxcContext *context); } *methods, struct _SxcLibProperty { char *name; int is_static; void (*getter)(struct _SxcContext *context); void (*setter)(struct _SxcContext *context); } *properties); void (*to_sfunc)(void (*func)(struct _SxcContext *context), struct _SxcValue *return_value); } *binding; int argcount; struct _SxcValue return_value; int has_error; void *_jmpbuf; struct _SxcMemoryChunk { int free_space; struct _SxcMemoryChunk *next_chunk; int offset; char data; } _firstchunk; char _firstdata[-1]; } *

variable_types:
name
char *

variable_types:
initialzier
void (*)(struct _SxcContext *context)

variable_types:
methods
struct _SxcLibMethod *

variable_types:
properties
struct _SxcLibProperty *

variable_types: struct _SxcLibMethod { char *name; int is_static; void (*func)(struct _SxcContext { void *underlying; struct _SxcContextBinding { void (*get_arg)(void *underlying, int index, struct _SxcValue { struct _SxcContext *context; enum _SxcDataType { sxc_null=0, sxc_cbool=1, sxc_cint=2, sxc_cdouble=3, sxc_string=4, sxc_map=5, sxc_func=6, sxc_sstring=7, sxc_smap=8, sxc_sfunc=9, sxc_cstring=10, sxc_cpointer=11, sxc_cfunc=12, sxc_cchars=13, sxc_cbools=14, sxc_cints=15, sxc_cdoubles=16, sxc_cstrings=17 } type; union _SxcData { _Bool cbool; int cint; double cdouble; void *_pointer_store; struct _SxcString { void *underlying; struct _SxcStringBinding { void (*to_cchars)(void *underlying, struct _SxcValue *return_value); int is_null_terminated; } *binding; struct _SxcContext *context; char *data; int length; } *string; struct _SxcMap { void *underlying; struct _SxcMapBinding { void (*intget)(void *underlying, int key, struct _SxcValue *return_value); void (*intset)(void *underlying, int key, struct _SxcValue *value); void (*strget)(void *underlying, char *key, struct _SxcValue *return_value); void (*strset)(void *underlying, char *key, struct _SxcValue *value); int (*length)(void *underlying); void *(*iter)(void *underlying, void *state, struct _SxcValue *return_key, struct _SxcValue *return_value); } *binding; struct _SxcContext *context; } *map; struct _SxcFunc { void *underlying; struct _SxcFunctionBinding { void (*invoke)(void *underlying, struct _SxcValue **args, int argcount, struct _SxcValue *return_value); } *binding; struct _SxcContext *context; } *func; struct { void *underlying; void *binding; } _binding_store; struct { void *underlying; struct _SxcStringBinding *binding; } sstring; struct { void *underlying; struct _SxcMapBinding *binding; } smap; struct { void *underlying; struct _SxcFunctionBinding *binding; } sfunc; char *cstring; void (*cfunc)(struct _SxcContext *context); void *cpointer; struct { void *array; int length; } _array_store; struct { char *array; int length; } cchars; struct { _Bool *array; int length; } cbools; struct { int *array; int length; } cints; struct { double *array; int length; } cdoubles; struct { char **array; int length; } cstrings; } data; } *return_value); void (*to_sstring)(char *data, int length, struct _SxcValue *return_value); void (*map_new)(void *map_type, struct _SxcValue *return_value); void *(*map_newtype)(struct _SxcContext *context, char *name, void (*initializer)(struct _SxcContext *context), struct _SxcLibMethod *methods, struct _SxcLibProperty { char *name; int is_static; void (*getter)(struct _SxcContext *context); void (*setter)(struct _SxcContext *context); } *properties); void (*to_sfunc)(void (*func)(struct _SxcContext *context), struct _SxcValue *return_value); } *binding; int argcount; struct _SxcValue return_value; int has_error; void *_jmpbuf; struct _SxcMemoryChunk { int free_space; struct _SxcMemoryChunk *next_chunk; int offset; char data; } _firstchunk; char _firstdata[-1]; } *context); } []

variable_types: struct _SxcLibProperty { char *name; int is_static; void (*getter)(struct _SxcContext { void *underlying; struct _SxcContextBinding { void (*get_arg)(void *underlying, int index, struct _SxcValue { struct _SxcContext *context; enum _SxcDataType { sxc_null=0, sxc_cbool=1, sxc_cint=2, sxc_cdouble=3, sxc_string=4, sxc_map=5, sxc_func=6, sxc_sstring=7, sxc_smap=8, sxc_sfunc=9, sxc_cstring=10, sxc_cpointer=11, sxc_cfunc=12, sxc_cchars=13, sxc_cbools=14, sxc_cints=15, sxc_cdoubles=16, sxc_cstrings=17 } type; union _SxcData { _Bool cbool; int cint; double cdouble; void *_pointer_store; struct _SxcString { void *underlying; struct _SxcStringBinding { void (*to_cchars)(void *underlying, struct _SxcValue *return_value); int is_null_terminated; } *binding; struct _SxcContext *context; char *data; int length; } *string; struct _SxcMap { void *underlying; struct _SxcMapBinding { void (*intget)(void *underlying, int key, struct _SxcValue *return_value); void (*intset)(void *underlying, int key, struct _SxcValue *value); void (*strget)(void *underlying, char *key, struct _SxcValue *return_value); void (*strset)(void *underlying, char *key, struct _SxcValue *value); int (*length)(void *underlying); void *(*iter)(void *underlying, void *state, struct _SxcValue *return_key, struct _SxcValue *return_value); } *binding; struct _SxcContext *context; } *map; struct _SxcFunc { void *underlying; struct _SxcFunctionBinding { void (*invoke)(void *underlying, struct _SxcValue **args, int argcount, struct _SxcValue *return_value); } *binding; struct _SxcContext *context; } *func; struct { void *underlying; void *binding; } _binding_store; struct { void *underlying; struct _SxcStringBinding *binding; } sstring; struct { void *underlying; struct _SxcMapBinding *binding; } smap; struct { void *underlying; struct _SxcFunctionBinding *binding; } sfunc; char *cstring; void (*cfunc)(struct _SxcContext *context); void *cpointer; struct { void *array; int length; } _array_store; struct { char *array; int length; } cchars; struct { _Bool *array; int length; } cbools; struct { int *array; int length; } cints; struct { double *array; int length; } cdoubles; struct { char **array; int length; } cstrings; } data; } *return_value); void (*to_sstring)(char *data, int length, struct _SxcValue *return_value); void (*map_new)(void *map_type, struct _SxcValue *return_value); void *(*map_newtype)(struct _SxcContext *context, char *name, void (*initializer)(struct _SxcContext *context), struct _SxcLibMethod { char *name; int is_static; void (*func)(struct _SxcContext *context); } *methods, struct _SxcLibProperty *properties); void (*to_sfunc)(void (*func)(struct _SxcContext *context), struct _SxcValue *return_value); } *binding; int argcount; struct _SxcValue return_value; int has_error; void *_jmpbuf; struct _SxcMemoryChunk { int free_space; struct _SxcMemoryChunk *next_chunk; int offset; char data; } _firstchunk; char _firstdata[-1]; } *context); void (*setter)(struct _SxcContext *context); } []


decompiled_code:
__int64 sxc_map_intget(__int64 *a1, unsigned int a2, char a3, unsigned int a4, ...)
{
__int64 v7; // rdi
unsigned int v8; // er13
char *v10; // rbp
gcc_va_list va; // [rsp+8h] [rbp-120h] BYREF
__int64 v12[4]; // [rsp+20h] [rbp-108h] BYREF

v7 = *a1;
v12[0] = a1[2];
(*(void (__fastcall **)(__int64, _QWORD, __int64 *))a1[1])(v7, a2, v12);
if ( a4 == -1 )
sxc_value_cnormalize(v12);
va_start(va, a4);
v8 = sxc_value_getv(v12, a4, va);
if ( v8 != 1 && a3 )
{
v10 = (char *)sxc_alloc(a1[2], 31LL);
sprintf(v10, "element %d", a2);
sxc_typeerror(a1[2], v10, a4, v12);
}
return v8;
}

canonical_decompiled_code:
__int64 func3(__int64 *a1, unsigned int a2, char a3, unsigned int a4, ...)
{
__int64 v7; // rdi
unsigned int v8; // er13
char *v10; // rbp
gcc_va_list va; // [rsp+8h] [rbp-120h] BYREF
__int64 v12[4]; // [rsp+20h] [rbp-108h] BYREF

v7 = *a1;
v12[0] = a1[2];
(*(void (__fastcall **)(__int64, _QWORD, __int64 *))a1[1])(v7, a2, v12);
if ( a4 == -1 )
sxc_value_cnormalize(v12);
va_start(va, a4);
v8 = sxc_value_getv(v12, a4, va);
if ( v8 != 1 && a3 )
{
v10 = (char *)sxc_alloc(a1[2], 31LL);
sprintf(v10, "element %d", a2);
sxc_typeerror(a1[2], v10, a4, v12);
}
return v8;
}

original_code:
int sxc_map_intget(SxcMap* map, int key, _Bool is_required, SxcDataType type, ...) {
  va_list varg;
  int retval;
  SxcValue value;
  const char* value_name_format = "element %d";
  char* value_name;
  value.context = map->context;
  (map->binding->intget)(map->underlying, key, &value);
  if (type == (-1)) {
    sxc_value_cnormalize(&value);
  }
  __builtin_va_start(varg,type);
  retval = sxc_value_getv(&value, type, varg);
  __builtin_va_end(varg);
  if (is_required && retval != (1)) {
    value_name = sxc_alloc(map->context, sizeof(char) * (strlen(value_name_format) + 20 + 1));
    sprintf(value_name, value_name_format, key);
    sxc_typeerror(map->context, value_name, type, &value);
  }
  return retval;
}

canonical_original_code:
int sxc_map_intget(struct _SxcMap *map, int key, _Bool is_required, enum _SxcDataType type, ...) {
  __builtin_va_list varg;
  int retval;
  struct _SxcValue value;
  char *value_name_format = "element %d";
  char *value_name;
  value.context = map->context;
  (map->binding->intget)(map->underlying, key, &value);
  if (type == (-1)) {
    sxc_value_cnormalize(&value);
  }
  __builtin_va_start(varg,type);
  retval = sxc_value_getv(&value, type, varg);
  __builtin_va_end(varg);
  if (is_required && retval != (1)) {
    value_name = sxc_alloc(map->context, sizeof(char) * (strlen(value_name_format) + 20 + 1));
    sprintf(value_name, value_name_format, key);
    sxc_typeerror(map->context, value_name, type, &value);
  }
  return retval;
}

variable_types: key int

variable_types: enum _SxcDataType { sxc_null=0, sxc_cbool=1, sxc_cint=2, sxc_cdouble=3, sxc_string=4, sxc_map=5, sxc_func=6, sxc_sstring=7, sxc_smap=8, sxc_sfunc=9, sxc_cstring=10, sxc_cpointer=11, sxc_cfunc=12, sxc_cchars=13, sxc_cbools=14, sxc_cints=15, sxc_cdoubles=16, sxc_cstrings=17 }

variable_types: retval int

user_defined_types: struct _SxcMemoryChunk { int free_space; struct _SxcMemoryChunk *next_chunk; int offset; char data; }

user_defined_types: struct _SxcStringBinding { void (*to_cchars)(void *underlying, struct _SxcValue *return_value); int is_null_terminated; }

user_defined_types: struct _SxcFunctionBinding { void (*invoke)(void *underlying, struct _SxcValue **args, int argcount, struct _SxcValue *return_value); }

user_defined_types: struct _SxcLibMethod { char *name; int is_static; void (*func)(struct _SxcContext *context); }

user_defined_types: struct _SxcLibProperty { char *name; int is_static; void (*getter)(struct _SxcContext *context); void (*setter)(struct _SxcContext *context); }


decompiled_code:
__int64 sxc_map_intset(_QWORD *a1, unsigned int a2, unsigned int a3, ...)
{
gcc_va_list va; // [rsp+8h] [rbp-100h] BYREF
__int64 v5[4]; // [rsp+20h] [rbp-E8h] BYREF

va_start(va, a3);
v5[0] = a1[2];
sxc_value_setv(v5, a3, va);
sxc_value_snormalize(v5);
return (*(__int64 (__fastcall **)(_QWORD, _QWORD, __int64 *))(a1[1] + 8LL))(*a1, a2, v5);
}

canonical_decompiled_code:
__int64 func4(_QWORD *a1, unsigned int a2, unsigned int a3, ...)
{
gcc_va_list va; // [rsp+8h] [rbp-100h] BYREF
__int64 v5[4]; // [rsp+20h] [rbp-E8h] BYREF

va_start(va, a3);
v5[0] = a1[2];
sxc_value_setv(v5, a3, va);
sxc_value_snormalize(v5);
return (*(__int64 (__fastcall **)(_QWORD, _QWORD, __int64 *))(a1[1] + 8LL))(*a1, a2, v5);
}

original_code:
void sxc_map_intset(SxcMap* map, int key, SxcDataType type, ...) {
  va_list varg;
  SxcValue value;
  value.context = map->context;
  __builtin_va_start(varg,type);
  sxc_value_setv(&value, type, varg);
  __builtin_va_end(varg);
  sxc_value_snormalize(&value);
  (map->binding->intset)(map->underlying, key, &value);
}

canonical_original_code:
void sxc_map_intset(struct _SxcMap *map, int key, enum _SxcDataType type, ...) {
  __builtin_va_list varg;
  struct _SxcValue value;
  value.context = map->context;
  __builtin_va_start(varg,type);
  sxc_value_setv(&value, type, varg);
  __builtin_va_end(varg);
  sxc_value_snormalize(&value);
  (map->binding->intset)(map->underlying, key, &value);
}

user_defined_types: enum _SxcDataType { sxc_null=0, sxc_cbool=1, sxc_cint=2, sxc_cdouble=3, sxc_string=4, sxc_map=5, sxc_func=6, sxc_sstring=7, sxc_smap=8, sxc_sfunc=9, sxc_cstring=10, sxc_cpointer=11, sxc_cfunc=12, sxc_cchars=13, sxc_cbools=14, sxc_cints=15, sxc_cdoubles=16, sxc_cstrings=17 }


decompiled_code:
__int64 sxc_map_strget(__int64 *a1, const char *a2, char a3, unsigned int a4, ...)
{
__int64 v7; // rdi
unsigned int v8; // er13
int v10; // eax
char *v11; // rbp
gcc_va_list va; // [rsp+8h] [rbp-120h] BYREF
__int64 v13[4]; // [rsp+20h] [rbp-108h] BYREF

v7 = *a1;
v13[0] = a1[2];
(*(void (__fastcall **)(__int64, const char *, __int64 *))(a1[1] + 16))(v7, a2, v13);
if ( a4 == -1 )
sxc_value_cnormalize(v13);
va_start(va, a4);
v8 = sxc_value_getv(v13, a4, va);
if ( v8 != 1 && a3 )
{
v10 = strlen(a2);
v11 = (char *)sxc_alloc(a1[2], (unsigned int)(v10 + 13));
sprintf(v11, "element \"%s\"", a2);
sxc_typeerror(a1[2], v11, a4, v13);
}
return v8;
}

canonical_decompiled_code:
__int64 func5(__int64 *a1, const char *a2, char a3, unsigned int a4, ...)
{
__int64 v7; // rdi
unsigned int v8; // er13
int v10; // eax
char *v11; // rbp
gcc_va_list va; // [rsp+8h] [rbp-120h] BYREF
__int64 v13[4]; // [rsp+20h] [rbp-108h] BYREF

v7 = *a1;
v13[0] = a1[2];
(*(void (__fastcall **)(__int64, const char *, __int64 *))(a1[1] + 16))(v7, a2, v13);
if ( a4 == -1 )
sxc_value_cnormalize(v13);
va_start(va, a4);
v8 = sxc_value_getv(v13, a4, va);
if ( v8 != 1 && a3 )
{
v10 = strlen(a2);
v11 = (char *)sxc_alloc(a1[2], (unsigned int)(v10 + 13));
sprintf(v11, "element \"%s\"", a2);
sxc_typeerror(a1[2], v11, a4, v13);
}
return v8;
}

original_code:
int sxc_map_strget(SxcMap* map, const char* key, _Bool is_required, SxcDataType type, ...) {
  va_list varg;
  int retval;
  SxcValue value;
  const char* value_name_format = "element \"%s\"";
  char* value_name;
  value.context = map->context;
  (map->binding->strget)(map->underlying, key, &value);
  if (type == (-1)) {
    sxc_value_cnormalize(&value);
  }
  __builtin_va_start(varg,type);
  retval = sxc_value_getv(&value, type, varg);
  __builtin_va_end(varg);
  if (is_required && retval != (1)) {
    value_name = sxc_alloc(map->context, sizeof(char) * (strlen(value_name_format) + strlen(key) + 1));
    sprintf(value_name, value_name_format, key);
    sxc_typeerror(map->context, value_name, type, &value);
  }
  return retval;
}

canonical_original_code:
int sxc_map_strget(struct _SxcMap *map, char *key, _Bool is_required, enum _SxcDataType type, ...) {
  __builtin_va_list varg;
  int retval;
  struct _SxcValue value;
  char *value_name_format = "element \"%s\"";
  char *value_name;
  value.context = map->context;
  (map->binding->strget)(map->underlying, key, &value);
  if (type == (-1)) {
    sxc_value_cnormalize(&value);
  }
  __builtin_va_start(varg,type);
  retval = sxc_value_getv(&value, type, varg);
  __builtin_va_end(varg);
  if (is_required && retval != (1)) {
    value_name = sxc_alloc(map->context, sizeof(char) * (strlen(value_name_format) + strlen(key) + 1));
    sprintf(value_name, value_name_format, key);
    sxc_typeerror(map->context, value_name, type, &value);
  }
  return retval;
}

variable_types:
key
char *