decompiled_code:
__int64 __fastcall collection_init(void *a1)
{
_BYTE *v1; // rax
_BYTE *v2; // rdi
__int64 result; // rax

v1 = memset(a1, 0, 0x4628uLL);
v1[8988] = 1;
v2 = v1;
result = 0xFFFFFFFFLL;
*((_WORD *)v2 + 4495) = -1;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(void *a1)
{
_BYTE *v1; // rax
_BYTE *v2; // rdi
__int64 result; // rax

v1 = memset(a1, 0, 0x4628uLL);
v1[8988] = 1;
v2 = v1;
result = 0xFFFFFFFFLL;
*((_WORD *)v2 + 4495) = -1;
return result;
}

original_code:
void
collection_init(struct collection *cl)
{
 (void)memset(cl, 0, sizeof(*cl));
 cl->cl_symfollow = 1;
 cl->cl_umask = ((uint16_t)-1);
}

canonical_original_code:
void collection_init(struct collection *cl)
{
 (void)memset(cl, 0, sizeof(*cl));
 cl->cl_symfollow = 1;
 cl->cl_umask = ((unsigned short)-1);
}

variable_types: struct collection { struct collection *cl_next; char cl_name[-1]; char cl_release[-1]; char cl_prefix[4096]; unsigned long cl_prefixlen; char cl_comment[256]; int cl_errormode; _Bool cl_symfollow; unsigned short cl_umask; char cl_dist_name[-1]; char cl_scan_name[-1]; struct collection *cl_super; char cl_super_name[-1]; } *


repo: cvsync/cvsync

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

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

original_code:
void
collection_destroy(struct collection *cl)
{
 free(cl);
}

return_type: void

user_defined_types: struct collection { struct collection *cl_next; char cl_name[-1]; char cl_release[-1]; char cl_prefix[4096]; unsigned long cl_prefixlen; char cl_comment[256]; int cl_errormode; _Bool cl_symfollow; unsigned short cl_umask; char cl_dist_name[-1]; char cl_scan_name[-1]; struct collection *cl_super; char cl_super_name[-1]; }


decompiled_code:
__int64 __fastcall collection_set_default(__int64 a1, const char *a2)
{
size_t v2; // rax
__int64 result; // rax
char *v4; // rax

if ( !*(_BYTE *)(a1 + 8) )
strcpy((char *)(a1 + 8), "<unspecified>");
if ( !*(_BYTE *)(a1 + 264) )
*(_DWORD *)(a1 + 264) = 7562098;
if ( a2 )
{
v2 = strlen(a2);
*(_QWORD *)(a1 + 8712) = v2;
if ( v2 > 0xFFF )
{
v4 = strerror(36);
logmsg_err("collection %s/%s: prefix: %s", (const char *)(a1 + 8), (const char *)(a1 + 264), v4);
return 0LL;
}
memcpy((void *)(a1 + 520), a2, v2);
*(_BYTE *)(a1 + *(_QWORD *)(a1 + 8712) + 520) = 0;
}
if ( (unsigned int)cvsync_release_pton(a1 + 264) == 2 )
{
result = 1LL;
if ( *(_WORD *)(a1 + 8990) == 0xFFFF )
*(_WORD *)(a1 + 8990) = 18;
}
else
{
logmsg_err("%s: unknown release type", (const char *)(a1 + 264));
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, const char *a2)
{
size_t v2; // rax
__int64 result; // rax
char *v4; // rax

if ( !*(_BYTE *)(a1 + 8) )
strcpy((char *)(a1 + 8), "<unspecified>");
if ( !*(_BYTE *)(a1 + 264) )
*(_DWORD *)(a1 + 264) = 7562098;
if ( a2 )
{
v2 = strlen(a2);
*(_QWORD *)(a1 + 8712) = v2;
if ( v2 > 0xFFF )
{
v4 = strerror(36);
logmsg_err("collection %s/%s: prefix: %s", (const char *)(a1 + 8), (const char *)(a1 + 264), v4);
return 0LL;
}
memcpy((void *)(a1 + 520), a2, v2);
*(_BYTE *)(a1 + *(_QWORD *)(a1 + 8712) + 520) = 0;
}
if ( (unsigned int)cvsync_release_pton(a1 + 264) == 2 )
{
result = 1LL;
if ( *(_WORD *)(a1 + 8990) == 0xFFFF )
*(_WORD *)(a1 + 8990) = 18;
}
else
{
logmsg_err("%s: unknown release type", (const char *)(a1 + 264));
result = 0LL;
}
return result;
}

original_code:
_Bool
collection_set_default(struct collection *cl, const char *prefix)
{
 if (strlen(cl->cl_name) == 0) {
  snprintf(cl->cl_name, sizeof(cl->cl_name), "%s",
    "<unspecified>");
 }
 if (strlen(cl->cl_release) == 0)
  snprintf(cl->cl_release, sizeof(cl->cl_release), "%s", "rcs");
 if (prefix != ((void *)0)) {
  cl->cl_prefixlen = strlen(prefix);
  if (cl->cl_prefixlen >= sizeof(cl->cl_prefix)) {
   logmsg_err("collection %s/%s: prefix: %s", cl->cl_name,
       cl->cl_release, strerror(36));
   return (0);
  }
  (void)memcpy(cl->cl_prefix, prefix, cl->cl_prefixlen);
  cl->cl_prefix[cl->cl_prefixlen] = '\0';
 }
 switch (cvsync_release_pton(cl->cl_release)) {
 case CVSYNC_RELEASE_RCS:
  if (cl->cl_umask == ((uint16_t)-1))
   cl->cl_umask = ((0200 >> 3)|((0200 >> 3) >> 3));
  break;
 default:
  logmsg_err("%s: unknown release type", cl->cl_release);
  return (0);
 }
 return (1);
}

canonical_original_code:
_Bool collection_set_default(struct collection *cl, char *prefix)
{
 if (strlen(cl->cl_name) == 0) {
  snprintf(cl->cl_name, sizeof(cl->cl_name), "%s",
    "<unspecified>");
 }
 if (strlen(cl->cl_release) == 0)
  snprintf(cl->cl_release, sizeof(cl->cl_release), "%s", "rcs");
 if (prefix != ((void *)0)) {
  cl->cl_prefixlen = strlen(prefix);
  if (cl->cl_prefixlen >= sizeof(cl->cl_prefix)) {
   logmsg_err("collection %s/%s: prefix: %s", cl->cl_name,
       cl->cl_release, strerror(36));
   return (0);
  }
  (void)memcpy(cl->cl_prefix, prefix, cl->cl_prefixlen);
  cl->cl_prefix[cl->cl_prefixlen] = '\0';
 }
 switch (cvsync_release_pton(cl->cl_release)) {
 case CVSYNC_RELEASE_RCS:
  if (cl->cl_umask == ((unsigned short)-1))
   cl->cl_umask = ((0200 >> 3)|((0200 >> 3) >> 3));
  break;
 default:
  logmsg_err("%s: unknown release type", cl->cl_release);
  return (0);
 }
 return (1);
}

variable_types:
prefix
char *


decompiled_code:
_QWORD *list_init()
{
_QWORD *v0; // r12
char *v1; // rax
char *v2; // rdi
char *v3; // rsi
char *v4; // rdx
char *v5; // rcx
int *v7; // rax
char *v8; // rax
int *v9; // rax
char *v10; // rax
void *v11; // rdi

v0 = malloc(0x28uLL);
if ( v0 )
{
v1 = (char *)malloc(0x200uLL);
*v0 = v1;
v2 = v1;
if ( v1 )
{
v0[1] = 0LL;
v3 = v1 + 512;
v4 = 0LL;
v0[2] = 0LL;
v0[4] = 0LL;
do
{
v5 = v4;
*((_DWORD *)v1 + 6) = 0;
v4 = v1;
v1 += 32;
*((_QWORD *)v1 - 4) = v5;
}
while ( v1 != v3 );
v0[3] = v2 + 480;
}
else
{
v9 = _errno_location();
v10 = strerror(*v9);
logmsg_err(&unk_3FB, v10);
v11 = v0;
v0 = 0LL;
free(v11);
}
}
else
{
v7 = _errno_location();
v8 = strerror(*v7);
logmsg_err(&unk_3FB, v8);
}
return v0;
}

canonical_decompiled_code:
_QWORD *func0()
{
_QWORD *v0; // r12
char *v1; // rax
char *v2; // rdi
char *v3; // rsi
char *v4; // rdx
char *v5; // rcx
int *v7; // rax
char *v8; // rax
int *v9; // rax
char *v10; // rax
void *v11; // rdi

v0 = malloc(0x28uLL);
if ( v0 )
{
v1 = (char *)malloc(0x200uLL);
*v0 = v1;
v2 = v1;
if ( v1 )
{
v0[1] = 0LL;
v3 = v1 + 512;
v4 = 0LL;
v0[2] = 0LL;
v0[4] = 0LL;
do
{
v5 = v4;
*((_DWORD *)v1 + 6) = 0;
v4 = v1;
v1 += 32;
*((_QWORD *)v1 - 4) = v5;
}
while ( v1 != v3 );
v0[3] = v2 + 480;
}
else
{
v9 = _errno_location();
v10 = strerror(*v9);
logmsg_err(&unk_3FB, v10);
v11 = v0;
v0 = 0LL;
free(v11);
}
}
else
{
v7 = _errno_location();
v8 = strerror(*v7);
logmsg_err(&unk_3FB, v8);
}
return v0;
}

original_code:
struct list *
list_init(void)
{
 struct list *lp;
 size_t i;
 if ((lp = malloc(sizeof(*lp))) == ((void *)0)) {
  logmsg_err("%s", strerror((*__errno_location ())));
  return (((void *)0));
 }
 lp->l_entries = malloc((16) * sizeof(*lp->l_entries));
 if (lp->l_entries == ((void *)0)) {
  logmsg_err("%s", strerror((*__errno_location ())));
  free(lp);
  return (((void *)0));
 }
 lp->l_head = ((void *)0);
 lp->l_tail = ((void *)0);
 lp->l_freelist = ((void *)0);
 lp->l_destructor = ((void *)0);
 for (i = 0 ; i < (16) ; i++) {
  lp->l_entries[i].le_next = lp->l_freelist;
  lp->l_freelist = &lp->l_entries[i];
  lp->l_freelist->le_state = (0);
 }
 return (lp);
}

canonical_original_code:
struct list *list_init()
{
 struct list *lp;
 unsigned long i;
 if ((lp = malloc(sizeof(*lp))) == ((void *)0)) {
  logmsg_err("%s", strerror((*__errno_location ())));
  return (((void *)0));
 }
 lp->l_entries = malloc((16) * sizeof(*lp->l_entries));
 if (lp->l_entries == ((void *)0)) {
  logmsg_err("%s", strerror((*__errno_location ())));
  free(lp);
  return (((void *)0));
 }
 lp->l_head = ((void *)0);
 lp->l_tail = ((void *)0);
 lp->l_freelist = ((void *)0);
 lp->l_destructor = ((void *)0);
 for (i = 0 ; i < (16) ; i++) {
  lp->l_entries[i].le_next = lp->l_freelist;
  lp->l_freelist = &lp->l_entries[i];
  lp->l_freelist->le_state = (0);
 }
 return (lp);
}

variable_types: struct list { struct listent { struct listent *le_next; void *le_elm; int le_state; } *l_entries; void (*l_destructor)(void *); } *

variable_types:
i
unsigned long

user_defined_types: struct list { struct listent *l_entries; void (*l_destructor)(void *); }


decompiled_code:
void __fastcall list_destroy(void *ptr)
{
_QWORD *v2; // rbx
void (__fastcall *v3)(_QWORD); // rax
_QWORD *v4; // rbp
_QWORD *v5; // rbx
_DWORD *v6; // rdi

v2 = (_QWORD *)*((_QWORD *)ptr + 1);
while ( v2 )
{
while ( 1 )
{
v3 = (void (__fastcall *)(_QWORD))*((_QWORD *)ptr + 4);
v4 = v2;
v2 = (_QWORD *)*v2;
if ( v3 )
v3(v4[2]);
if ( *((_DWORD *)v4 + 6) != 1 )
break;
free(v4);
if ( !v2 )
goto LABEL_7;
}
}
LABEL_7:
v5 = (_QWORD *)*((_QWORD *)ptr + 3);
while ( v5 )
{
while ( 1 )
{
v6 = v5;
v5 = (_QWORD *)*v5;
if ( v6[6] != 1 )
break;
free(v6);
if ( !v5 )
goto LABEL_11;
}
}
LABEL_11:
free(*(void **)ptr);
free(ptr);
}

canonical_decompiled_code:
void __fastcall func1(void *ptr)
{
_QWORD *v2; // rbx
void (__fastcall *v3)(_QWORD); // rax
_QWORD *v4; // rbp
_QWORD *v5; // rbx
_DWORD *v6; // rdi

v2 = (_QWORD *)*((_QWORD *)ptr + 1);
while ( v2 )
{
while ( 1 )
{
v3 = (void (__fastcall *)(_QWORD))*((_QWORD *)ptr + 4);
v4 = v2;
v2 = (_QWORD *)*v2;
if ( v3 )
v3(v4[2]);
if ( *((_DWORD *)v4 + 6) != 1 )
break;
free(v4);
if ( !v2 )
goto LABEL_7;
}
}
LABEL_7:
v5 = (_QWORD *)*((_QWORD *)ptr + 3);
while ( v5 )
{
while ( 1 )
{
v6 = v5;
v5 = (_QWORD *)*v5;
if ( v6[6] != 1 )
break;
free(v6);
if ( !v5 )
goto LABEL_11;
}
}
LABEL_11:
free(*(void **)ptr);
free(ptr);
}

original_code:
void
list_destroy(struct list *lp)
{
 struct listent *lep, *next;
 lep = lp->l_head;
 while (lep != ((void *)0)) {
  next = lep->le_next;
  if (lp->l_destructor != ((void *)0))
   (*lp->l_destructor)(lep->le_elm);
  if (lep->le_state == (1))
   free(lep);
  lep = next;
 }
 lep = lp->l_freelist;
 while (lep != ((void *)0)) {
  next = lep->le_next;
  if (lep->le_state == (1))
   free(lep);
  lep = next;
 }
 free(lp->l_entries);
 free(lp);
}

canonical_original_code:
void list_destroy(struct list *lp)
{
 struct listent *lep; struct listent *next;
 lep = lp->l_head;
 while (lep != ((void *)0)) {
  next = lep->le_next;
  if (lp->l_destructor != ((void *)0))
   (*lp->l_destructor)(lep->le_elm);
  if (lep->le_state == (1))
   free(lep);
  lep = next;
 }
 lep = lp->l_freelist;
 while (lep != ((void *)0)) {
  next = lep->le_next;
  if (lep->le_state == (1))
   free(lep);
  lep = next;
 }
 free(lp->l_entries);
 free(lp);
}

variable_types: struct listent { struct listent *le_next; void *le_elm; int le_state; } *


decompiled_code:
__int64 __fastcall list_insert_head(_QWORD *a1, __int64 a2)
{
_DWORD *v2; // rax
__int64 v3; // rdx
int *v5; // rax
char *v6; // rax

v2 = (_DWORD *)a1[3];
if ( v2 )
{
a1[3] = *(_QWORD *)v2;
}
else
{
v2 = malloc(0x20uLL);
if ( !v2 )
{
v5 = _errno_location();
v6 = strerror(*v5);
logmsg_err(&unk_3FB, v6);
return 0LL;
}
v2[6] = 1;
}
v3 = a1[1];
*((_QWORD *)v2 + 1) = 0LL;
*((_QWORD *)v2 + 2) = a2;
*(_QWORD *)v2 = v3;
if ( v3 )
*(_QWORD *)(v3 + 8) = v2;
else
a1[2] = v2;
a1[1] = v2;
return 1LL;
}

original_code:
_Bool
list_insert_head(struct list *lp, void *elm)
{
 struct listent *lep;
 if (lp->l_freelist != ((void *)0)) {
  lep = lp->l_freelist;
  lp->l_freelist = lep->le_next;
 } else {
  if ((lep = malloc(sizeof(*lep))) == ((void *)0)) {
   logmsg_err("%s", strerror((*__errno_location ())));
   return (0);
  }
  lep->le_state = (1);
 }
 lep->le_next = lp->l_head;
 lep->le_priv = ((void *)0);
 lep->le_elm = elm;
 if (lp->l_head != ((void *)0))
  lp->l_head->le_priv = lep;
 else
  lp->l_tail = lep;
 lp->l_head = lep;
 return (1);
}

variable_types:
elm
void *

user_defined_types: struct listent { struct listent *le_next; void *le_elm; int le_state; }


decompiled_code:
__int64 __fastcall list_insert_tail(_QWORD *a1, __int64 a2)
{
_DWORD *v2; // rax
_QWORD *v3; // rdx
int *v5; // rax
char *v6; // rax

v2 = (_DWORD *)a1[3];
if ( v2 )
{
a1[3] = *(_QWORD *)v2;
}
else
{
v2 = malloc(0x20uLL);
if ( !v2 )
{
v5 = _errno_location();
v6 = strerror(*v5);
logmsg_err(&unk_3FB, v6);
return 0LL;
}
v2[6] = 1;
}
v3 = (_QWORD *)a1[2];
*(_QWORD *)v2 = 0LL;
*((_QWORD *)v2 + 2) = a2;
*((_QWORD *)v2 + 1) = v3;
if ( v3 )
*v3 = v2;
else
a1[1] = v2;
a1[2] = v2;
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func4(_QWORD *a1, __int64 a2)
{
_DWORD *v2; // rax
_QWORD *v3; // rdx
int *v5; // rax
char *v6; // rax

v2 = (_DWORD *)a1[3];
if ( v2 )
{
a1[3] = *(_QWORD *)v2;
}
else
{
v2 = malloc(0x20uLL);
if ( !v2 )
{
v5 = _errno_location();
v6 = strerror(*v5);
logmsg_err(&unk_3FB, v6);
return 0LL;
}
v2[6] = 1;
}
v3 = (_QWORD *)a1[2];
*(_QWORD *)v2 = 0LL;
*((_QWORD *)v2 + 2) = a2;
*((_QWORD *)v2 + 1) = v3;
if ( v3 )
*v3 = v2;
else
a1[1] = v2;
a1[2] = v2;
return 1LL;
}

original_code:
_Bool
list_insert_tail(struct list *lp, void *elm)
{
 struct listent *lep;
 if (lp->l_freelist != ((void *)0)) {
  lep = lp->l_freelist;
  lp->l_freelist = lep->le_next;
 } else {
  if ((lep = malloc(sizeof(*lep))) == ((void *)0)) {
   logmsg_err("%s", strerror((*__errno_location ())));
   return (0);
  }
  lep->le_state = (1);
 }
 lep->le_next = ((void *)0);
 lep->le_priv = lp->l_tail;
 lep->le_elm = elm;
 if (lp->l_tail != ((void *)0))
  lp->l_tail->le_next = lep;
 else
  lp->l_head = lep;
 lp->l_tail= lep;
 return (1);
}


original_code:
void *
list_remove_head(struct list *lp)
{
 struct listent *lep;
 void *elm;
 if (lp->l_head == ((void *)0))
  return (((void *)0));
 lep = lp->l_head;
 lp->l_head = lep->le_next;
 if (lp->l_head != ((void *)0))
  lp->l_head->le_priv = ((void *)0);
 else
  lp->l_tail = ((void *)0);
 elm = lep->le_elm;
 lep->le_next = lp->l_freelist;
 lep->le_priv = ((void *)0);
 lp->l_freelist = lep;
 return (elm);
}

canonical_original_code:
void *list_remove_head(struct list *lp)
{
 struct listent *lep;
 void *elm;
 if (lp->l_head == ((void *)0))
  return (((void *)0));
 lep = lp->l_head;
 lp->l_head = lep->le_next;
 if (lp->l_head != ((void *)0))
  lp->l_head->le_priv = ((void *)0);
 else
  lp->l_tail = ((void *)0);
 elm = lep->le_elm;
 lep->le_next = lp->l_freelist;
 lep->le_priv = ((void *)0);
 lp->l_freelist = lep;
 return (elm);
}

return_type: void *


original_code:
void *
list_remove_tail(struct list *lp)
{
 struct listent *lep;
 void *elm;
 if (lp->l_tail == ((void *)0))
  return (((void *)0));
 lep = lp->l_tail;
 lp->l_tail = lep->le_priv;
 if (lp->l_tail != ((void *)0))
  lp->l_tail->le_next = ((void *)0);
 else
  lp->l_head = ((void *)0);
 elm = lep->le_elm;
 lep->le_next = lp->l_freelist;
 lep->le_priv = ((void *)0);
 lp->l_freelist = lep;
 return (elm);
}

canonical_original_code:
void *list_remove_tail(struct list *lp)
{
 struct listent *lep;
 void *elm;
 if (lp->l_tail == ((void *)0))
  return (((void *)0));
 lep = lp->l_tail;
 lp->l_tail = lep->le_priv;
 if (lp->l_tail != ((void *)0))
  lp->l_tail->le_next = ((void *)0);
 else
  lp->l_head = ((void *)0);
 elm = lep->le_elm;
 lep->le_next = lp->l_freelist;
 lep->le_priv = ((void *)0);
 lp->l_freelist = lep;
 return (elm);
}


decompiled_code:
bool __fastcall list_isempty(__int64 a1)
{
return *(_QWORD *)(a1 + 8) == 0LL;
}

canonical_decompiled_code:
bool __fastcall func7(__int64 a1)
{
return *(_QWORD *)(a1 + 8) == 0LL;
}

original_code:
_Bool
list_isempty(struct list *lp)
{
 if (lp->l_head != ((void *)0))
  return (0);
 return (1);
}


decompiled_code:
__int64 __fastcall cvsup_init(char *s, char *a2)
{
char *v2; // rbp
char *v3; // rbx
size_t v4; // r12
size_t v5; // rax
int v6; // eax
__int64 result; // rax
__gid_t v8; // eax
struct group *v9; // rax
__uid_t v10; // eax
struct passwd *v11; // rax

v2 = s;
v3 = a2;
if ( !s )
{
v10 = getuid();
v11 = getpwuid(v10);
if ( !v11 )
goto LABEL_10;
v2 = v11->pw_name;
}
v4 = strlen(v2);
if ( a2 )
goto LABEL_3;
v8 = getgid();
v9 = getgrgid(v8);
if ( !v9 )
{
LABEL_10:
logmsg_err("Who am I?");
return 0LL;
}
v3 = v9->gr_name;
LABEL_3:
v5 = strlen(v3);
v6 = snprintf(cvsup_userinfo, 0x100uLL, "%lu#%.*s%lu#%.*s", v4, v4, v2, v5, v5, v3);
if ( (unsigned int)(v6 - 1) > 0xFE )
{
logmsg_err("Too long user/group name");
result = 0LL;
}
else
{
cvsup_userinfo_length = v6;
result = 1LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(char *s, char *a2)
{
char *v2; // rbp
char *v3; // rbx
size_t v4; // r12
size_t v5; // rax
int v6; // eax
__int64 result; // rax
__gid_t v8; // eax
struct group *v9; // rax
__uid_t v10; // eax
struct passwd *v11; // rax

v2 = s;
v3 = a2;
if ( !s )
{
v10 = getuid();
v11 = getpwuid(v10);
if ( !v11 )
goto LABEL_10;
v2 = v11->pw_name;
}
v4 = strlen(v2);
if ( a2 )
goto LABEL_3;
v8 = getgid();
v9 = getgrgid(v8);
if ( !v9 )
{
LABEL_10:
logmsg_err("Who am I?");
return 0LL;
}
v3 = v9->gr_name;
LABEL_3:
v5 = strlen(v3);
v6 = snprintf(cvsup_userinfo, 0x100uLL, "%lu#%.*s%lu#%.*s", v4, v4, v2, v5, v5, v3);
if ( (unsigned int)(v6 - 1) > 0xFE )
{
logmsg_err("Too long user/group name");
result = 0LL;
}
else
{
cvsup_userinfo_length = v6;
result = 1LL;
}
return result;
}

original_code:
_Bool
cvsup_init(const char *user, const char *group)
{
 struct group *gr;
 struct passwd *pw;
 size_t ulen, glen;
 int wn;
 if (user == ((void *)0)) {
  if ((pw = getpwuid(getuid())) == ((void *)0)) {
   logmsg_err("Who am I?");
   return (0);
  }
  user = pw->pw_name;
 }
 ulen = strlen(user);
 if (group == ((void *)0)) {
  if ((gr = getgrgid(getgid())) == ((void *)0)) {
   logmsg_err("Who am I?");
   return (0);
  }
  group = gr->gr_name;
 }
 glen = strlen(group);
 wn = snprintf(cvsup_userinfo, sizeof(cvsup_userinfo),
        "%lu#%.*s%lu#%.*s", (unsigned long)ulen, (int)ulen,
        user, (unsigned long)glen, (int)glen, group);
 if ((wn <= 0) || ((size_t)wn >= sizeof(cvsup_userinfo))) {
  logmsg_err("Too long user/group name");
  return (0);
 }
 cvsup_userinfo_length = wn;
 return (1);
}

canonical_original_code:
_Bool cvsup_init(char *user, char *group)
{
 struct group *gr;
 struct passwd *pw;
 unsigned long ulen; unsigned long glen;
 int wn;
 if (user == ((void *)0)) {
  if ((pw = getpwuid(getuid())) == ((void *)0)) {
   logmsg_err("Who am I?");
   return (0);
  }
  user = pw->pw_name;
 }
 ulen = strlen(user);
 if (group == ((void *)0)) {
  if ((gr = getgrgid(getgid())) == ((void *)0)) {
   logmsg_err("Who am I?");
   return (0);
  }
  group = gr->gr_name;
 }
 glen = strlen(group);
 wn = snprintf(cvsup_userinfo, sizeof(cvsup_userinfo),
        "%lu#%.*s%lu#%.*s", (unsigned long)ulen, (int)ulen,
        user, (unsigned long)glen, (int)glen, group);
 if ((wn <= 0) || ((unsigned long)wn >= sizeof(cvsup_userinfo))) {
  logmsg_err("Too long user/group name");
  return (0);
 }
 cvsup_userinfo_length = wn;
 return (1);
}

variable_types:
user
char *

variable_types:
group
char *

variable_types: struct group { char *gr_name; char *gr_passwd; unsigned int gr_gid; char **gr_mem; } *

variable_types: struct passwd { char *pw_name; char *pw_passwd; unsigned int pw_uid; unsigned int pw_gid; char *pw_gecos; char *pw_dir; char *pw_shell; } *

variable_types:
ulen
unsigned long

variable_types:
glen
unsigned long

variable_types: wn int


decompiled_code:
__int64 __fastcall cvsup_write_header(int fd, __int64 a2)
{
size_t v2; // rbx
ssize_t v3; // rax
unsigned int v4; // er8
int *v6; // rax
char *v7; // rax
char v8[280]; // [rsp+0h] [rbp-118h] BYREF

v2 = snprintf(v8, 0x100uLL, "F 5 %ld\n", a2);
v3 = write(fd, v8, v2);
if ( v3 == -1 )
{
v6 = _errno_location();
v7 = strerror(*v6);
logmsg_err("Header: %s", v7);
return 0;
}
v4 = 1;
if ( v2 == v3 )
return v4;
logmsg_err("Header: write error");
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func1(int fd, __int64 a2)
{
size_t v2; // rbx
ssize_t v3; // rax
unsigned int v4; // er8
int *v6; // rax
char *v7; // rax
char v8[280]; // [rsp+0h] [rbp-118h] BYREF

v2 = snprintf(v8, 0x100uLL, "F 5 %ld\n", a2);
v3 = write(fd, v8, v2);
if ( v3 == -1 )
{
v6 = _errno_location();
v7 = strerror(*v6);
logmsg_err("Header: %s", v7);
return 0;
}
v4 = 1;
if ( v2 == v3 )
return v4;
logmsg_err("Header: write error");
return 0LL;
}

original_code:
_Bool
cvsup_write_header(int fd, time_t mtime)
{
 char head[(256)];
 size_t len;
 ssize_t wrn;
 int wn;
 wn = snprintf(head, sizeof(head), "F 5 %ld\n", (long)mtime);
 if ((wn <= 0) || ((size_t)wn >= sizeof(head))) {
  logmsg_err("Header: %s", strerror(22));
  return (0);
 }
 len = (size_t)wn;
 if ((wrn = write(fd, head, len)) == -1) {
  logmsg_err("Header: %s", strerror((*__errno_location ())));
  return (0);
 }
 if ((size_t)wrn != len) {
  logmsg_err("Header: write error");
  return (0);
 }
 return (1);
}

canonical_original_code:
_Bool cvsup_write_header(int fd, long mtime)
{
 char head[-1];
 unsigned long len;
 long wrn;
 int wn;
 wn = snprintf(head, sizeof(head), "F 5 %ld\n", (long)mtime);
 if ((wn <= 0) || ((unsigned long)wn >= sizeof(head))) {
  logmsg_err("Header: %s", strerror(22));
  return (0);
 }
 len = (unsigned long)wn;
 if ((wrn = write(fd, head, len)) == -1) {
  logmsg_err("Header: %s", strerror((*__errno_location ())));
  return (0);
 }
 if ((unsigned long)wrn != len) {
  logmsg_err("Header: write error");
  return (0);
 }
 return (1);
}

variable_types: fd int

variable_types: mtime long

variable_types:
head
char [-1]

variable_types:
len
unsigned long

variable_types: wrn long


decompiled_code:
__int64 __fastcall cvsup_escape_name(__int64 a1, _BYTE *a2, unsigned __int64 a3)
{
char *v3; // rax
char *v5; // rdi
unsigned __int64 v6; // r8
char v7; // dl

v3 = *(char **)(a1 + 16);
if ( v3 < &v3[*(_QWORD *)(a1 + 24)] )
{
v5 = &v3[*(_QWORD *)(a1 + 24)];
v6 = 0LL;
while ( 1 )
{
while ( 1 )
{
v7 = *v3;
if ( *v3 != 32 )
break;
v6 += 2LL;
if ( v6 > a3 )
{
logmsg_err("No space to escape ' '");
return -1LL;
}
a2 += 2;
*((_WORD *)a2 - 1) = 24412;
LABEL_5:
if ( v5 == ++v3 )
return v6;
}
if ( v7 == 92 )
{
v6 += 2LL;
if ( v6 > a3 )
{
logmsg_err("No space to escape '\\'");
return -1LL;
}
a2 += 2;
*((_WORD *)a2 - 1) = 23644;
goto LABEL_5;
}
if ( a3 <= v6 )
{
logmsg_err("No space to put any characters");
return -1LL;
}
++v3;
*a2 = v7;
++v6;
++a2;
if ( v5 == v3 )
return v6;
}
}
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, _BYTE *a2, unsigned __int64 a3)
{
char *v3; // rax
char *v5; // rdi
unsigned __int64 v6; // r8
char v7; // dl

v3 = *(char **)(a1 + 16);
if ( v3 < &v3[*(_QWORD *)(a1 + 24)] )
{
v5 = &v3[*(_QWORD *)(a1 + 24)];
v6 = 0LL;
while ( 1 )
{
while ( 1 )
{
v7 = *v3;
if ( *v3 != 32 )
break;
v6 += 2LL;
if ( v6 > a3 )
{
logmsg_err("No space to escape ' '");
return -1LL;
}
a2 += 2;
*((_WORD *)a2 - 1) = 24412;
LABEL_5:
if ( v5 == ++v3 )
return v6;
}
if ( v7 == 92 )
{
v6 += 2LL;
if ( v6 > a3 )
{
logmsg_err("No space to escape '\\'");
return -1LL;
}
a2 += 2;
*((_WORD *)a2 - 1) = 23644;
goto LABEL_5;
}
if ( a3 <= v6 )
{
logmsg_err("No space to put any characters");
return -1LL;
}
++v3;
*a2 = v7;
++v6;
++a2;
if ( v5 == v3 )
return v6;
}
}
return 0LL;
}

original_code:
size_t
cvsup_escape_name(struct scanfile_attr *attr, void *buffer, size_t length)
{
 char *sp = attr->a_name, *bp = sp + attr->a_namelen, *p = buffer;
 size_t namelen = 0;
 while (sp < bp) {
  switch (*sp) {
  case '\\':
   if (namelen + 2 > length) {
    logmsg_err("No space to escape '\\'");
    return ((size_t)-1);
   }
   *p++ = '\\';
   *p++ = '\\';
   namelen += 2;
   break;
  case ' ':
   if (namelen + 2 > length) {
    logmsg_err("No space to escape ' '");
    return ((size_t)-1);
   }
   *p++ = '\\';
   *p++ = '_';
   namelen += 2;
   break;
  default:
   if (namelen >= length) {
    logmsg_err("No space to put any characters");
    return ((size_t)-1);
   }
   *p++ = *sp;
   namelen++;
   break;
  }
  sp++;
 }
 return (namelen);
}

canonical_original_code:
unsigned long cvsup_escape_name(struct scanfile_attr *attr, void *buffer, unsigned long length)
{
 char *sp = attr->a_name; char *bp = sp + attr->a_namelen; char *p = buffer;
 unsigned long namelen = 0;
 while (sp < bp) {
  switch (*sp) {
  case '\\':
   if (namelen + 2 > length) {
    logmsg_err("No space to escape '\\'");
    return ((unsigned long)-1);
   }
   *p++ = '\\';
   *p++ = '\\';
   namelen += 2;
   break;
  case ' ':
   if (namelen + 2 > length) {
    logmsg_err("No space to escape ' '");
    return ((unsigned long)-1);
   }
   *p++ = '\\';
   *p++ = '_';
   namelen += 2;
   break;
  default:
   if (namelen >= length) {
    logmsg_err("No space to put any characters");
    return ((unsigned long)-1);
   }
   *p++ = *sp;
   namelen++;
   break;
  }
  sp++;
 }
 return (namelen);
}

variable_types: struct scanfile_attr { unsigned long a_size; unsigned char a_type; void *a_name; unsigned long a_namelen; void *a_aux; unsigned long a_auxlen; } *

variable_types:
buffer
void *

variable_types:
length
unsigned long

variable_types:
sp
char *

variable_types:
bp
char *

variable_types:
p
char *

variable_types:
namelen
unsigned long

return_type: unsigned long


decompiled_code:
__int64 __fastcall cvsup_write_dirdown(int fd, __int64 a2)
{
unsigned int v2; // er12
__int64 v3; // rax
int v4; // eax
__int64 v5; // rbx
ssize_t v6; // rax
__int64 result; // rax
int *v8; // rax
char *v9; // rax
char v10[256]; // [rsp+0h] [rbp-218h] BYREF
char v11[280]; // [rsp+100h] [rbp-118h] BYREF

v2 = 0;
v3 = cvsup_escape_name(a2, v11, 0x100uLL);
if ( v3 == -1 )
return v2;
v4 = snprintf(v10, 0x100uLL, "D %.*s\n", v3, v11);
if ( (unsigned int)(v4 - 1) > 0xFE )
{
logmsg_err("Too long DirDown attribute");
result = 0LL;
}
else
{
v5 = v4;
v6 = write(fd, v10, v4);
if ( v6 == -1 )
{
v8 = _errno_location();
v9 = strerror(*v8);
logmsg_err("DirDown: %s", v9);
return v2;
}
v2 = 1;
if ( v5 == v6 )
return v2;
logmsg_err("DirDown: write error");
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(int fd, __int64 a2)
{
unsigned int v2; // er12
__int64 v3; // rax
int v4; // eax
__int64 v5; // rbx
ssize_t v6; // rax
__int64 result; // rax
int *v8; // rax
char *v9; // rax
char v10[256]; // [rsp+0h] [rbp-218h] BYREF
char v11[280]; // [rsp+100h] [rbp-118h] BYREF

v2 = 0;
v3 = func2(a2, v11, 0x100uLL);
if ( v3 == -1 )
return v2;
v4 = snprintf(v10, 0x100uLL, "D %.*s\n", v3, v11);
if ( (unsigned int)(v4 - 1) > 0xFE )
{
logmsg_err("Too long DirDown attribute");
result = 0LL;
}
else
{
v5 = v4;
v6 = write(fd, v10, v4);
if ( v6 == -1 )
{
v8 = _errno_location();
v9 = strerror(*v8);
logmsg_err("DirDown: %s", v9);
return v2;
}
v2 = 1;
if ( v5 == v6 )
return v2;
logmsg_err("DirDown: write error");
result = 0LL;
}
return result;
}

original_code:
_Bool
cvsup_write_dirdown(int fd, struct scanfile_attr *attr)
{
 char attrstr[(256)], name[(256)];
 size_t namelen, len;
 ssize_t wrn;
 int wn;
 if ((namelen = cvsup_escape_name(attr, name,
      sizeof(name))) == (size_t)-1) {
  return (0);
 }
 wn = snprintf(attrstr, sizeof(attrstr), "D %.*s\n",
        (int)namelen, name);
 if ((wn <= 0) || ((size_t)wn >= sizeof(attrstr))) {
  logmsg_err("Too long DirDown attribute");
  return (0);
 }
 len = (size_t)wn;
 if ((wrn = write(fd, attrstr, len)) == -1) {
  logmsg_err("DirDown: %s", strerror((*__errno_location ())));
  return (0);
 }
 if ((size_t)wrn != len) {
  logmsg_err("DirDown: write error");
  return (0);
 }
 return (1);
}

canonical_original_code:
_Bool cvsup_write_dirdown(int fd, struct scanfile_attr *attr)
{
 char attrstr[-1]; char name[-1];
 unsigned long namelen; unsigned long len;
 long wrn;
 int wn;
 if ((namelen = cvsup_escape_name(attr, name,
      sizeof(name))) == (unsigned long)-1) {
  return (0);
 }
 wn = snprintf(attrstr, sizeof(attrstr), "D %.*s\n",
        (int)namelen, name);
 if ((wn <= 0) || ((unsigned long)wn >= sizeof(attrstr))) {
  logmsg_err("Too long DirDown attribute");
  return (0);
 }
 len = (unsigned long)wn;
 if ((wrn = write(fd, attrstr, len)) == -1) {
  logmsg_err("DirDown: %s", strerror((*__errno_location ())));
  return (0);
 }
 if ((unsigned long)wrn != len) {
  logmsg_err("DirDown: write error");
  return (0);
 }
 return (1);
}

variable_types:
attrstr
char [-1]

variable_types:
name
char [-1]

user_defined_types: struct scanfile_attr { unsigned long a_size; unsigned char a_type; void *a_name; unsigned long a_namelen; void *a_aux; unsigned long a_auxlen; }


decompiled_code:
__int64 __fastcall cvsup_write_dirup(int fd, __int64 a2)
{
unsigned int v2; // eax
unsigned int v3; // er12
__int64 v5; // rbp
__int64 v6; // rax
int v7; // eax
__int64 v8; // rbp
ssize_t v9; // rax
int *v10; // rax
char *v11; // rax
char s[256]; // [rsp+0h] [rbp-2448h] BYREF
char v13[256]; // [rsp+100h] [rbp-2348h] BYREF
char v14[4384]; // [rsp+200h] [rbp-2248h] BYREF
unsigned __int16 v15; // [rsp+1320h] [rbp-1128h]

v2 = attr_rcs_decode_dir(*(_QWORD *)(a2 + 32), *(_QWORD *)(a2 + 40), v14);
if ( !(_BYTE)v2 )
return 0;
v3 = v2;
v5 = cvsup_escape_name(a2, v13, 0x100uLL);
if ( v5 == -1 )
return 0;
LODWORD(v6) = snprintf(s, 0x100uLL, "%o", v15);
v7 = snprintf(s, 0x100uLL, "U %.*s 3#1e11#2%.*s%d#%o1#0\n", v5, v13, cvsup_userinfo_length, cvsup_userinfo, v6, v15);
if ( (unsigned int)(v7 - 1) <= 0xFE )
{
v8 = v7;
v9 = write(fd, s, v7);
if ( v9 == -1 )
{
v10 = _errno_location();
v3 = 0;
v11 = strerror(*v10);
logmsg_err("DirDown: %s", v11);
return v3;
}
if ( v8 == v9 )
return v3;
logmsg_err("DirDown: write error");
return 0;
}
logmsg_err("Too long DirDown attribute");
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func4(int fd, __int64 a2)
{
unsigned int v2; // eax
unsigned int v3; // er12
__int64 v5; // rbp
__int64 v6; // rax
int v7; // eax
__int64 v8; // rbp
ssize_t v9; // rax
int *v10; // rax
char *v11; // rax
char s[256]; // [rsp+0h] [rbp-2448h] BYREF
char v13[256]; // [rsp+100h] [rbp-2348h] BYREF
char v14[4384]; // [rsp+200h] [rbp-2248h] BYREF
unsigned __int16 v15; // [rsp+1320h] [rbp-1128h]

v2 = attr_rcs_decode_dir(*(_QWORD *)(a2 + 32), *(_QWORD *)(a2 + 40), v14);
if ( !(_BYTE)v2 )
return 0;
v3 = v2;
v5 = func2(a2, v13, 0x100uLL);
if ( v5 == -1 )
return 0;
LODWORD(v6) = snprintf(s, 0x100uLL, "%o", v15);
v7 = snprintf(s, 0x100uLL, "U %.*s 3#1e11#2%.*s%d#%o1#0\n", v5, v13, cvsup_userinfo_length, cvsup_userinfo, v6, v15);
if ( (unsigned int)(v7 - 1) <= 0xFE )
{
v8 = v7;
v9 = write(fd, s, v7);
if ( v9 == -1 )
{
v10 = _errno_location();
v3 = 0;
v11 = strerror(*v10);
logmsg_err("DirDown: %s", v11);
return v3;
}
if ( v8 == v9 )
return v3;
logmsg_err("DirDown: write error");
return 0;
}
logmsg_err("Too long DirDown attribute");
return 0LL;
}

original_code:
_Bool
cvsup_write_dirup(int fd, struct scanfile_attr *attr)
{
 struct cvsync_attr cattr;
 char attrstr[(256)], name[(256)];
 size_t namelen, len;
 ssize_t wrn;
 int mlen, wn;
 if (!attr_rcs_decode_dir(attr->a_aux, attr->a_auxlen, &cattr))
  return (0);
 if ((namelen = cvsup_escape_name(attr, name,
      sizeof(name))) == (size_t)-1) {
  return (0);
 }
 mlen = snprintf(attrstr, sizeof(attrstr), "%o", cattr.ca_mode);
 wn = snprintf(attrstr, sizeof(attrstr),
        "U %.*s 3#1e11#2%.*s%d#%o1#0\n",
        (int)namelen, name, cvsup_userinfo_length,
        cvsup_userinfo, mlen, cattr.ca_mode);
 if ((wn <= 0) || ((size_t)wn >= sizeof(attrstr))) {
  logmsg_err("Too long DirDown attribute");
  return (0);
 }
 len = (size_t)wn;
 if ((wrn = write(fd, attrstr, len)) == -1) {
  logmsg_err("DirDown: %s", strerror((*__errno_location ())));
  return (0);
 }
 if ((size_t)wrn != len) {
  logmsg_err("DirDown: write error");
  return (0);
 }
 return (1);
}

canonical_original_code:
_Bool cvsup_write_dirup(int fd, struct scanfile_attr *attr)
{
 struct cvsync_attr cattr;
 char attrstr[-1]; char name[-1];
 unsigned long namelen; unsigned long len;
 long wrn;
 int mlen; int wn;
 if (!attr_rcs_decode_dir(attr->a_aux, attr->a_auxlen, &cattr))
  return (0);
 if ((namelen = cvsup_escape_name(attr, name,
      sizeof(name))) == (unsigned long)-1) {
  return (0);
 }
 mlen = snprintf(attrstr, sizeof(attrstr), "%o", cattr.ca_mode);
 wn = snprintf(attrstr, sizeof(attrstr),
        "U %.*s 3#1e11#2%.*s%d#%o1#0\n",
        (int)namelen, name, cvsup_userinfo_length,
        cvsup_userinfo, mlen, cattr.ca_mode);
 if ((wn <= 0) || ((unsigned long)wn >= sizeof(attrstr))) {
  logmsg_err("Too long DirDown attribute");
  return (0);
 }
 len = (unsigned long)wn;
 if ((wrn = write(fd, attrstr, len)) == -1) {
  logmsg_err("DirDown: %s", strerror((*__errno_location ())));
  return (0);
 }
 if ((unsigned long)wrn != len) {
  logmsg_err("DirDown: write error");
  return (0);
 }
 return (1);
}

variable_types: struct cvsync_attr { unsigned char ca_tag; unsigned char ca_type; unsigned char ca_name[-1]; unsigned long ca_namelen; long ca_mtime; unsigned long ca_size; unsigned short ca_mode; unsigned char ca_aux[-1]; unsigned long ca_auxlen; }

variable_types: mlen int


decompiled_code:
__int64 __fastcall cvsup_write_file(int fd, __int64 a2)
{
unsigned int v2; // eax
unsigned int v3; // er12
__int64 v5; // rbp
unsigned int v6; // ebx
__int64 v7; // r14
__int64 v8; // rax
int v9; // eax
__int64 v10; // rbp
ssize_t v11; // rax
int *v12; // rax
char *v13; // rax
char s[256]; // [rsp+0h] [rbp-2458h] BYREF
char v15[256]; // [rsp+100h] [rbp-2358h] BYREF
char v16[4368]; // [rsp+200h] [rbp-2258h] BYREF
__int64 v17; // [rsp+1310h] [rbp-1148h]
__int64 v18; // [rsp+1318h] [rbp-1140h]
unsigned __int16 v19; // [rsp+1320h] [rbp-1138h]

v2 = attr_rcs_decode_file(*(_QWORD *)(a2 + 32), *(_QWORD *)(a2 + 40), v16);
if ( !(_BYTE)v2 )
goto LABEL_2;
v3 = v2;
v5 = cvsup_escape_name(a2, v15, 0x100uLL);
if ( v5 == -1 )
goto LABEL_2;
v6 = snprintf(s, 0x100uLL, "%lld", v17);
v7 = (unsigned int)snprintf(s, 0x100uLL, "%llu", v18);
LODWORD(v8) = snprintf(s, 0x100uLL, "%o", v19);
v9 = snprintf(
s,
0x100uLL,
"V %.*s 3#1e71#1%d#%lld%d#%llu%.*s%d#%o1#0\n",
v5,
v15,
v6,
v17,
v7,
v18,
cvsup_userinfo_length,
cvsup_userinfo,
v8,
v19);
if ( (unsigned int)(v9 - 1) > 0xFE )
{
v3 = 0;
logmsg_err("Too long File attribute");
return v3;
}
v10 = v9;
v11 = write(fd, s, v9);
if ( v11 == -1 )
{
v12 = _errno_location();
v3 = 0;
v13 = strerror(*v12);
logmsg_err("File: %s", v13);
return v3;
}
if ( v10 != v11 )
{
logmsg_err("File: write error");
LABEL_2:
v3 = 0;
}
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func5(int fd, __int64 a2)
{
unsigned int v2; // eax
unsigned int v3; // er12
__int64 v5; // rbp
unsigned int v6; // ebx
__int64 v7; // r14
__int64 v8; // rax
int v9; // eax
__int64 v10; // rbp
ssize_t v11; // rax
int *v12; // rax
char *v13; // rax
char s[256]; // [rsp+0h] [rbp-2458h] BYREF
char v15[256]; // [rsp+100h] [rbp-2358h] BYREF
char v16[4368]; // [rsp+200h] [rbp-2258h] BYREF
__int64 v17; // [rsp+1310h] [rbp-1148h]
__int64 v18; // [rsp+1318h] [rbp-1140h]
unsigned __int16 v19; // [rsp+1320h] [rbp-1138h]

v2 = attr_rcs_decode_file(*(_QWORD *)(a2 + 32), *(_QWORD *)(a2 + 40), v16);
if ( !(_BYTE)v2 )
goto LABEL_2;
v3 = v2;
v5 = func2(a2, v15, 0x100uLL);
if ( v5 == -1 )
goto LABEL_2;
v6 = snprintf(s, 0x100uLL, "%lld", v17);
v7 = (unsigned int)snprintf(s, 0x100uLL, "%llu", v18);
LODWORD(v8) = snprintf(s, 0x100uLL, "%o", v19);
v9 = snprintf(
s,
0x100uLL,
"V %.*s 3#1e71#1%d#%lld%d#%llu%.*s%d#%o1#0\n",
v5,
v15,
v6,
v17,
v7,
v18,
cvsup_userinfo_length,
cvsup_userinfo,
v8,
v19);
if ( (unsigned int)(v9 - 1) > 0xFE )
{
v3 = 0;
logmsg_err("Too long File attribute");
return v3;
}
v10 = v9;
v11 = write(fd, s, v9);
if ( v11 == -1 )
{
v12 = _errno_location();
v3 = 0;
v13 = strerror(*v12);
logmsg_err("File: %s", v13);
return v3;
}
if ( v10 != v11 )
{
logmsg_err("File: write error");
LABEL_2:
v3 = 0;
}
return v3;
}

original_code:
_Bool
cvsup_write_file(int fd, struct scanfile_attr *attr)
{
 struct cvsync_attr cattr;
 char attrstr[(256)], name[(256)];
 size_t namelen, len;
 ssize_t wrn;
 int tlen, slen, mlen, wn;
 if (!attr_rcs_decode_file(attr->a_aux, attr->a_auxlen, &cattr))
  return (0);
 if ((namelen = cvsup_escape_name(attr, name,
      sizeof(name))) == (size_t)-1) {
  return (0);
 }
 tlen = snprintf(attrstr, sizeof(attrstr), "%lld",
   (long long)cattr.ca_mtime);
 slen = snprintf(attrstr, sizeof(attrstr), "%llu",
   (unsigned long long)cattr.ca_size);
 mlen = snprintf(attrstr, sizeof(attrstr), "%o", cattr.ca_mode);
 wn = snprintf(attrstr, sizeof(attrstr),
        "V %.*s 3#1e71#1%d#%lld%d#%llu%.*s%d#%o1#0\n",
        (int)namelen, name, tlen, (long long)cattr.ca_mtime,
        slen, (unsigned long long)cattr.ca_size,
        cvsup_userinfo_length, cvsup_userinfo,
        mlen, cattr.ca_mode);
 if ((wn <= 0) || ((size_t)wn >= sizeof(attrstr))) {
  logmsg_err("Too long File attribute");
  return (0);
 }
 len = (size_t)wn;
 if ((wrn = write(fd, attrstr, len)) == -1) {
  logmsg_err("File: %s", strerror((*__errno_location ())));
  return (0);
 }
 if ((size_t)wrn != len) {
  logmsg_err("File: write error");
  return (0);
 }
 return (1);
}

canonical_original_code:
_Bool cvsup_write_file(int fd, struct scanfile_attr *attr)
{
 struct cvsync_attr cattr;
 char attrstr[-1]; char name[-1];
 unsigned long namelen; unsigned long len;
 long wrn;
 int tlen; int slen; int mlen; int wn;
 if (!attr_rcs_decode_file(attr->a_aux, attr->a_auxlen, &cattr))
  return (0);
 if ((namelen = cvsup_escape_name(attr, name,
      sizeof(name))) == (unsigned long)-1) {
  return (0);
 }
 tlen = snprintf(attrstr, sizeof(attrstr), "%lld",
   (long long)cattr.ca_mtime);
 slen = snprintf(attrstr, sizeof(attrstr), "%llu",
   (unsigned long long)cattr.ca_size);
 mlen = snprintf(attrstr, sizeof(attrstr), "%o", cattr.ca_mode);
 wn = snprintf(attrstr, sizeof(attrstr),
        "V %.*s 3#1e71#1%d#%lld%d#%llu%.*s%d#%o1#0\n",
        (int)namelen, name, tlen, (long long)cattr.ca_mtime,
        slen, (unsigned long long)cattr.ca_size,
        cvsup_userinfo_length, cvsup_userinfo,
        mlen, cattr.ca_mode);
 if ((wn <= 0) || ((unsigned long)wn >= sizeof(attrstr))) {
  logmsg_err("Too long File attribute");
  return (0);
 }
 len = (unsigned long)wn;
 if ((wrn = write(fd, attrstr, len)) == -1) {
  logmsg_err("File: %s", strerror((*__errno_location ())));
  return (0);
 }
 if ((unsigned long)wrn != len) {
  logmsg_err("File: write error");
  return (0);
 }
 return (1);
}

variable_types: tlen int

variable_types: slen int

variable_types: wn int

user_defined_types: struct cvsync_attr { unsigned char ca_tag; unsigned char ca_type; unsigned char ca_name[-1]; unsigned long ca_namelen; long ca_mtime; unsigned long ca_size; unsigned short ca_mode; unsigned char ca_aux[-1]; unsigned long ca_auxlen; }


decompiled_code:
__int64 __fastcall cvsup_write_rcs(int fd, __int64 a2)
{
unsigned int v2; // eax
unsigned int v3; // er12
char v4; // bl
__int64 v5; // rbp
__int64 v6; // r14
__int64 v7; // rax
int v8; // eax
__int64 v9; // rbx
ssize_t v10; // rax
int *v12; // rax
char *v13; // rax
char s[256]; // [rsp+0h] [rbp-2458h] BYREF
char v15[256]; // [rsp+100h] [rbp-2358h] BYREF
char v16[4368]; // [rsp+200h] [rbp-2258h] BYREF
__int64 v17; // [rsp+1310h] [rbp-1148h]
unsigned __int16 v18; // [rsp+1320h] [rbp-1138h]

v2 = attr_rcs_decode_rcs(*(_QWORD *)(a2 + 32), *(_QWORD *)(a2 + 40), v16);
if ( !(_BYTE)v2 )
goto LABEL_9;
v3 = v2;
v4 = 86;
if ( *(_BYTE *)(a2 + 8) != 82 )
v4 = 118;
v5 = cvsup_escape_name(a2, v15, 0x100uLL);
if ( v5 == -1 )
goto LABEL_9;
v6 = (unsigned int)snprintf(s, 0x100uLL, "%lld", v17);
LODWORD(v7) = snprintf(s, 0x100uLL, "%o", v18);
v8 = snprintf(
s,
0x100uLL,
"%c %.*s 3#1e31#1%d#%lld%.*s%d#%o1#0\n",
(unsigned int)v4,
v5,
v15,
v6,
v17,
cvsup_userinfo_length,
cvsup_userinfo,
v7,
v18);
if ( (unsigned int)(v8 - 1) > 0xFE )
{
v3 = 0;
logmsg_err("Too long RCS attribute");
return v3;
}
v9 = v8;
v10 = write(fd, s, v8);
if ( v10 == -1 )
{
v12 = _errno_location();
v3 = 0;
v13 = strerror(*v12);
logmsg_err("RCS: %s", v13);
return v3;
}
if ( v9 != v10 )
{
logmsg_err("RCS: write error");
LABEL_9:
v3 = 0;
}
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func6(int fd, __int64 a2)
{
unsigned int v2; // eax
unsigned int v3; // er12
char v4; // bl
__int64 v5; // rbp
__int64 v6; // r14
__int64 v7; // rax
int v8; // eax
__int64 v9; // rbx
ssize_t v10; // rax
int *v12; // rax
char *v13; // rax
char s[256]; // [rsp+0h] [rbp-2458h] BYREF
char v15[256]; // [rsp+100h] [rbp-2358h] BYREF
char v16[4368]; // [rsp+200h] [rbp-2258h] BYREF
__int64 v17; // [rsp+1310h] [rbp-1148h]
unsigned __int16 v18; // [rsp+1320h] [rbp-1138h]

v2 = attr_rcs_decode_rcs(*(_QWORD *)(a2 + 32), *(_QWORD *)(a2 + 40), v16);
if ( !(_BYTE)v2 )
goto LABEL_9;
v3 = v2;
v4 = 86;
if ( *(_BYTE *)(a2 + 8) != 82 )
v4 = 118;
v5 = func2(a2, v15, 0x100uLL);
if ( v5 == -1 )
goto LABEL_9;
v6 = (unsigned int)snprintf(s, 0x100uLL, "%lld", v17);
LODWORD(v7) = snprintf(s, 0x100uLL, "%o", v18);
v8 = snprintf(
s,
0x100uLL,
"%c %.*s 3#1e31#1%d#%lld%.*s%d#%o1#0\n",
(unsigned int)v4,
v5,
v15,
v6,
v17,
cvsup_userinfo_length,
cvsup_userinfo,
v7,
v18);
if ( (unsigned int)(v8 - 1) > 0xFE )
{
v3 = 0;
logmsg_err("Too long RCS attribute");
return v3;
}
v9 = v8;
v10 = write(fd, s, v8);
if ( v10 == -1 )
{
v12 = _errno_location();
v3 = 0;
v13 = strerror(*v12);
logmsg_err("RCS: %s", v13);
return v3;
}
if ( v9 != v10 )
{
logmsg_err("RCS: write error");
LABEL_9:
v3 = 0;
}
return v3;
}

original_code:
_Bool
cvsup_write_rcs(int fd, struct scanfile_attr *attr)
{
 struct cvsync_attr cattr;
 char attrstr[(256)], name[(256)], c;
 size_t namelen, len;
 ssize_t wrn;
 int tlen, mlen, wn;
 if (!attr_rcs_decode_rcs(attr->a_aux, attr->a_auxlen, &cattr))
  return (0);
 if (attr->a_type == 'R')
  c = 'V';
 else
  c = 'v';
 if ((namelen = cvsup_escape_name(attr, name,
      sizeof(name))) == (size_t)-1) {
  return (0);
 }
 tlen = snprintf(attrstr, sizeof(attrstr), "%lld",
   (long long)cattr.ca_mtime);
 mlen = snprintf(attrstr, sizeof(attrstr), "%o", cattr.ca_mode);
 wn = snprintf(attrstr, sizeof(attrstr),
        "%c %.*s 3#1e31#1%d#%lld%.*s%d#%o1#0\n",
        c, (int)namelen, name, tlen, (long long)cattr.ca_mtime,
        cvsup_userinfo_length, cvsup_userinfo,
        mlen, cattr.ca_mode);
 if ((wn <= 0) || ((size_t)wn >= sizeof(attrstr))) {
  logmsg_err("Too long RCS attribute");
  return (0);
 }
 len = (size_t)wn;
 if ((wrn = write(fd, attrstr, len)) == -1) {
  logmsg_err("RCS: %s", strerror((*__errno_location ())));
  return (0);
 }
 if ((size_t)wrn != len) {
  logmsg_err("RCS: write error");
  return (0);
 }
 return (1);
}

canonical_original_code:
_Bool cvsup_write_rcs(int fd, struct scanfile_attr *attr)
{
 struct cvsync_attr cattr;
 char attrstr[-1]; char name[-1]; char c;
 unsigned long namelen; unsigned long len;
 long wrn;
 int tlen; int mlen; int wn;
 if (!attr_rcs_decode_rcs(attr->a_aux, attr->a_auxlen, &cattr))
  return (0);
 if (attr->a_type == 'R')
  c = 'V';
 else
  c = 'v';
 if ((namelen = cvsup_escape_name(attr, name,
      sizeof(name))) == (unsigned long)-1) {
  return (0);
 }
 tlen = snprintf(attrstr, sizeof(attrstr), "%lld",
   (long long)cattr.ca_mtime);
 mlen = snprintf(attrstr, sizeof(attrstr), "%o", cattr.ca_mode);
 wn = snprintf(attrstr, sizeof(attrstr),
        "%c %.*s 3#1e31#1%d#%lld%.*s%d#%o1#0\n",
        c, (int)namelen, name, tlen, (long long)cattr.ca_mtime,
        cvsup_userinfo_length, cvsup_userinfo,
        mlen, cattr.ca_mode);
 if ((wn <= 0) || ((unsigned long)wn >= sizeof(attrstr))) {
  logmsg_err("Too long RCS attribute");
  return (0);
 }
 len = (unsigned long)wn;
 if ((wrn = write(fd, attrstr, len)) == -1) {
  logmsg_err("RCS: %s", strerror((*__errno_location ())));
  return (0);
 }
 if ((unsigned long)wrn != len) {
  logmsg_err("RCS: write error");
  return (0);
 }
 return (1);
}

variable_types: fd int

variable_types: c char


decompiled_code:
__int64 __fastcall cvsup_write_symlink(int fd, __int64 a2)
{
unsigned int v2; // er12
__int64 v3; // rax
int v4; // eax
__int64 v5; // rbx
ssize_t v6; // rax
__int64 result; // rax
int *v8; // rax
char *v9; // rax
__int64 v10; // [rsp-8h] [rbp-220h]
char s[256]; // [rsp+0h] [rbp-218h] BYREF
char v12[280]; // [rsp+100h] [rbp-118h] BYREF

v2 = 0;
v3 = cvsup_escape_name(a2, v12, 0x100uLL);
if ( v3 == -1 )
return v2;
v4 = snprintf(
s,
0x100uLL,
"V %.*s 1#91#5%lu#%.*s\n",
v3,
v12,
*(_QWORD *)(a2 + 40),
*(_QWORD *)(a2 + 40),
*(const char **)(a2 + 32));
if ( (unsigned int)(v4 - 1) > 0xFE )
{
logmsg_err("Too long Symlink attribute", v10);
result = 0LL;
}
else
{
v5 = v4;
v6 = write(fd, s, v4);
if ( v6 == -1 )
{
v8 = _errno_location();
v9 = strerror(*v8);
logmsg_err("Symlink: %s", v9);
return v2;
}
v2 = 1;
if ( v5 == v6 )
return v2;
logmsg_err("Symlink: write error");
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func7(int fd, __int64 a2)
{
unsigned int v2; // er12
__int64 v3; // rax
int v4; // eax
__int64 v5; // rbx
ssize_t v6; // rax
__int64 result; // rax
int *v8; // rax
char *v9; // rax
__int64 v10; // [rsp-8h] [rbp-220h]
char s[256]; // [rsp+0h] [rbp-218h] BYREF
char v12[280]; // [rsp+100h] [rbp-118h] BYREF

v2 = 0;
v3 = func2(a2, v12, 0x100uLL);
if ( v3 == -1 )
return v2;
v4 = snprintf(
s,
0x100uLL,
"V %.*s 1#91#5%lu#%.*s\n",
v3,
v12,
*(_QWORD *)(a2 + 40),
*(_QWORD *)(a2 + 40),
*(const char **)(a2 + 32));
if ( (unsigned int)(v4 - 1) > 0xFE )
{
logmsg_err("Too long Symlink attribute", v10);
result = 0LL;
}
else
{
v5 = v4;
v6 = write(fd, s, v4);
if ( v6 == -1 )
{
v8 = _errno_location();
v9 = strerror(*v8);
logmsg_err("Symlink: %s", v9);
return v2;
}
v2 = 1;
if ( v5 == v6 )
return v2;
logmsg_err("Symlink: write error");
result = 0LL;
}
return result;
}

original_code:
_Bool
cvsup_write_symlink(int fd, struct scanfile_attr *attr)
{
 char attrstr[(256)], name[(256)];
 size_t namelen, len;
 ssize_t wrn;
 int wn;
 if ((namelen = cvsup_escape_name(attr, name,
      sizeof(name))) == (size_t)-1) {
  return (0);
 }
 wn = snprintf(attrstr, sizeof(attrstr), "V %.*s 1#91#5%lu#%.*s\n",
        (int)namelen, name, (unsigned long)attr->a_auxlen,
        (int)attr->a_auxlen, (char *)attr->a_aux);
 if ((wn <= 0) || ((size_t)wn >= sizeof(attrstr))) {
  logmsg_err("Too long Symlink attribute");
  return (0);
 }
 len = (size_t)wn;
 if ((wrn = write(fd, attrstr, len)) == -1) {
  logmsg_err("Symlink: %s", strerror((*__errno_location ())));
  return (0);
 }
 if ((size_t)wrn != len) {
  logmsg_err("Symlink: write error");
  return (0);
 }
 return (1);
}

canonical_original_code:
_Bool cvsup_write_symlink(int fd, struct scanfile_attr *attr)
{
 char attrstr[-1]; char name[-1];
 unsigned long namelen; unsigned long len;
 long wrn;
 int wn;
 if ((namelen = cvsup_escape_name(attr, name,
      sizeof(name))) == (unsigned long)-1) {
  return (0);
 }
 wn = snprintf(attrstr, sizeof(attrstr), "V %.*s 1#91#5%lu#%.*s\n",
        (int)namelen, name, (unsigned long)attr->a_auxlen,
        (int)attr->a_auxlen, (char *)attr->a_aux);
 if ((wn <= 0) || ((unsigned long)wn >= sizeof(attrstr))) {
  logmsg_err("Too long Symlink attribute");
  return (0);
 }
 len = (unsigned long)wn;
 if ((wrn = write(fd, attrstr, len)) == -1) {
  logmsg_err("Symlink: %s", strerror((*__errno_location ())));
  return (0);
 }
 if ((unsigned long)wrn != len) {
  logmsg_err("Symlink: write error");
  return (0);
 }
 return (1);
}

variable_types:
len
unsigned long

variable_types: wrn long


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

result = _cvsync_isinterrupted();
if ( !(_BYTE)result )
result = _cvsync_isterminated();
return result;
}

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

result = _cvsync_isinterrupted();
if ( !(_BYTE)result )
result = _cvsync_isterminated();
return result;
}

original_code:
_Bool
cvsync_isinterrupted(void)
{
 return (__cvsync_isinterrupted() || __cvsync_isterminated());
}

canonical_original_code:
_Bool cvsync_isinterrupted()
{
 return (__cvsync_isinterrupted() || __cvsync_isterminated());
}


decompiled_code:
__int64 cvsync_isterminated()
{
return 0LL;
}

canonical_decompiled_code:
__int64 func1()
{
return 0LL;
}

original_code:
_Bool
cvsync_isterminated(void)
{
 return (0);
}

canonical_original_code:
_Bool cvsync_isterminated()
{
 return (0);
}


decompiled_code:
void logmsg_close()
{
if ( !logmsg_syslog )
{
if ( !logmsg_file )
return;
LABEL_5:
fclose(logmsg_stdout);
logmsg_file = 0;
return;
}
closelog();
if ( logmsg_file )
goto LABEL_5;
}

canonical_decompiled_code:
void func0()
{
if ( !logmsg_syslog )
{
if ( !logmsg_file )
return;
LABEL_5:
fclose(logmsg_stdout);
logmsg_file = 0;
return;
}
closelog();
if ( logmsg_file )
goto LABEL_5;
}

original_code:
void
logmsg_close(void)
{
 if (logmsg_syslog)
  closelog();
 if (logmsg_file) {
  (void)fclose(logmsg_stdout);
  logmsg_file = 0;
 }
}

canonical_original_code:
void logmsg_close()
{
 if (logmsg_syslog)
  closelog();
 if (logmsg_file) {
  (void)fclose(logmsg_stdout);
  logmsg_file = 0;
 }
}


decompiled_code:
int logmsg_intr()
{
int result; // eax
int v1; // eax
struct tm *v2; // rax
size_t v3; // r12
int v4; // eax
time_t timer; // [rsp+8h] [rbp-150h] BYREF
struct tm tp; // [rsp+10h] [rbp-148h] BYREF
char s[264]; // [rsp+50h] [rbp-108h] BYREF

if ( !logmsg_stdout )
logmsg_stdout = stdout;
if ( !logmsg_stderr )
logmsg_stderr = stderr;
result = cvsync_isinterrupted();
if ( (_BYTE)result )
{
result = cvsync_isterminated();
if ( !(_BYTE)result && !logmsg_file && !logmsg_syslog )
{
pthread_mutex_lock(&mtx);
if ( !logmsg_interrupted )
{
if ( !(unsigned __int8)cvsync_isterminated() )
{
fflush(0LL);
if ( logmsg_file )
{
time(&timer);
v2 = localtime_r(&timer, &tp);
v3 = strftime(s, 0x100uLL, "[%Y/%m/%d %H:%M:%S] ", v2);
if ( v3 )
{
v4 = fileno(logmsg_stdout);
write(v4, s, v3);
}
}
else
{
s[0] = 0;
}
v1 = fileno(logmsg_stdout);
write(v1, "Interrupted\n", 0xCuLL);
}
logmsg_interrupted = 1;
}
result = pthread_mutex_unlock(&mtx);
}
}
return result;
}

canonical_decompiled_code:
int func1()
{
int result; // eax
int v1; // eax
struct tm *v2; // rax
size_t v3; // r12
int v4; // eax
time_t timer; // [rsp+8h] [rbp-150h] BYREF
struct tm tp; // [rsp+10h] [rbp-148h] BYREF
char s[264]; // [rsp+50h] [rbp-108h] BYREF

if ( !logmsg_stdout )
logmsg_stdout = stdout;
if ( !logmsg_stderr )
logmsg_stderr = stderr;
result = cvsync_isinterrupted();
if ( (_BYTE)result )
{
result = cvsync_isterminated();
if ( !(_BYTE)result && !logmsg_file && !logmsg_syslog )
{
pthread_mutex_lock(&mtx);
if ( !logmsg_interrupted )
{
if ( !(unsigned __int8)cvsync_isterminated() )
{
fflush(0LL);
if ( logmsg_file )
{
time(&timer);
v2 = localtime_r(&timer, &tp);
v3 = strftime(s, 0x100uLL, "[%Y/%m/%d %H:%M:%S] ", v2);
if ( v3 )
{
v4 = fileno(logmsg_stdout);
write(v4, s, v3);
}
}
else
{
s[0] = 0;
}
v1 = fileno(logmsg_stdout);
write(v1, "Interrupted\n", 0xCuLL);
}
logmsg_interrupted = 1;
}
result = pthread_mutex_unlock(&mtx);
}
}
return result;
}

original_code:
void
logmsg_intr(void)
{
 struct tm tm;
 time_t now;
 char timemsg[(256)];
 size_t wn;
 if (logmsg_stdout == ((void *)0))
  logmsg_stdout = stdout;
 if (logmsg_stderr == ((void *)0))
  logmsg_stderr = stderr;
 if (!cvsync_isinterrupted() || cvsync_isterminated())
  return;
 if (logmsg_file || logmsg_syslog)
  return;
 pthread_mutex_lock(&mtx);
 if (!logmsg_interrupted) {
  if (!cvsync_isterminated()) {
   (void)fflush(((void *)0));
   if (!logmsg_file) {
    timemsg[0] = '\0';
    wn = 0;
   } else {
    time(&now);
    wn = strftime(timemsg, sizeof(timemsg),
           "[%Y/%m/%d %H:%M:%S] ",
           localtime_r(&now, &tm));
   }
   if (wn > 0) {
    (void)write(fileno(logmsg_stdout), timemsg,
         wn);
   }
   (void)write(fileno(logmsg_stdout), "Interrupted\n",
        12);
  }
  logmsg_interrupted = 1;
 }
 pthread_mutex_unlock(&mtx);
}

canonical_original_code:
void logmsg_intr()
{
 struct tm tm;
 long now;
 char timemsg[-1];
 unsigned long wn;
 if (logmsg_stdout == ((void *)0))
  logmsg_stdout = stdout;
 if (logmsg_stderr == ((void *)0))
  logmsg_stderr = stderr;
 if (!cvsync_isinterrupted() || cvsync_isterminated())
  return;
 if (logmsg_file || logmsg_syslog)
  return;
 pthread_mutex_lock(&mtx);
 if (!logmsg_interrupted) {
  if (!cvsync_isterminated()) {
   (void)fflush(((void *)0));
   if (!logmsg_file) {
    timemsg[0] = '\0';
    wn = 0;
   } else {
    time(&now);
    wn = strftime(timemsg, sizeof(timemsg),
           "[%Y/%m/%d %H:%M:%S] ",
           localtime_r(&now, &tm));
   }
   if (wn > 0) {
    (void)write(fileno(logmsg_stdout), timemsg,
         wn);
   }
   (void)write(fileno(logmsg_stdout), "Interrupted\n",
        12);
  }
  logmsg_interrupted = 1;
 }
 pthread_mutex_unlock(&mtx);
}

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

variable_types: now long

variable_types:
timemsg
char [-1]

variable_types:
wn
unsigned long


logmsg

decompiled_code:
void logmsg(const char *a1, ...)
{
gcc_va_list va; // [rsp+8h] [rbp-D0h] BYREF

logmsg_intr();
if ( !logmsg_quiet )
{
va_start(va, a1);
_logmsg(6, logmsg_stdout, a1, va);
}
}

canonical_decompiled_code:
void func3(const char *a1, ...)
{
gcc_va_list va; // [rsp+8h] [rbp-D0h] BYREF

func1();
if ( !logmsg_quiet )
{
va_start(va, a1);
func2(6, logmsg_stdout, a1, va);
}
}

original_code:
void
logmsg(const char *message, ...)
{
 va_list ap;
 logmsg_intr();
 if (logmsg_quiet)
  return;
 __builtin_va_start(ap,message);
 __logmsg(6, logmsg_stdout, message, ap);
 __builtin_va_end(ap);
}

canonical_original_code:
void logmsg(char *message, ...)
{
 __builtin_va_list ap;
 logmsg_intr();
 if (logmsg_quiet)
  return;
 __builtin_va_start(ap,message);
 __logmsg(6, logmsg_stdout, message, ap);
 __builtin_va_end(ap);
}

variable_types:
message
char *


decompiled_code:
void logmsg_debug(int a1, const char *a2, ...)
{
gcc_va_list va; // [rsp+8h] [rbp-E0h] BYREF

logmsg_intr();
if ( logmsg_do_debug[a1] )
{
va_start(va, a2);
_logmsg(7, logmsg_stdout, a2, va);
}
}

canonical_decompiled_code:
void func4(int a1, const char *a2, ...)
{
gcc_va_list va; // [rsp+8h] [rbp-E0h] BYREF

func1();
if ( logmsg_do_debug[a1] )
{
va_start(va, a2);
func2(7, logmsg_stdout, a2, va);
}
}

original_code:
void
logmsg_debug(int priority, const char *message, ...)
{
 va_list ap;
 logmsg_intr();
 if (!logmsg_do_debug[priority])
  return;
 __builtin_va_start(ap,message);
 __logmsg(7, logmsg_stdout, message, ap);
 __builtin_va_end(ap);
}

canonical_original_code:
void logmsg_debug(int priority, char *message, ...)
{
 __builtin_va_list ap;
 logmsg_intr();
 if (!logmsg_do_debug[priority])
  return;
 __builtin_va_start(ap,message);
 __logmsg(7, logmsg_stdout, message, ap);
 __builtin_va_end(ap);
}

variable_types: priority int


decompiled_code:
void logmsg_err(const char *a1, ...)
{
gcc_va_list va; // [rsp+8h] [rbp-D0h] BYREF

va_start(va, a1);
logmsg_intr();
_logmsg(3, logmsg_stderr, a1, va);
}

canonical_decompiled_code:
void func5(const char *a1, ...)
{
gcc_va_list va; // [rsp+8h] [rbp-D0h] BYREF

va_start(va, a1);
func1();
func2(3, logmsg_stderr, a1, va);
}

original_code:
void
logmsg_err(const char *message, ...)
{
 va_list ap;
 logmsg_intr();
 __builtin_va_start(ap,message);
 __logmsg(3, logmsg_stderr, message, ap);
 __builtin_va_end(ap);
}

canonical_original_code:
void logmsg_err(char *message, ...)
{
 __builtin_va_list ap;
 logmsg_intr();
 __builtin_va_start(ap,message);
 __logmsg(3, logmsg_stderr, message, ap);
 __builtin_va_end(ap);
}


decompiled_code:
void logmsg_verbose(const char *a1, ...)
{
gcc_va_list va; // [rsp+8h] [rbp-D0h] BYREF

logmsg_intr();
if ( logmsg_detail )
{
if ( !logmsg_quiet )
{
va_start(va, a1);
_logmsg(6, logmsg_stdout, a1, va);
}
}
}

canonical_decompiled_code:
void func7(const char *a1, ...)
{
gcc_va_list va; // [rsp+8h] [rbp-D0h] BYREF

func1();
if ( logmsg_detail )
{
if ( !logmsg_quiet )
{
va_start(va, a1);
func2(6, logmsg_stdout, a1, va);
}
}
}

original_code:
void
logmsg_verbose(const char *message, ...)
{
 va_list ap;
 logmsg_intr();
 if (!logmsg_detail)
  return;
 if (logmsg_quiet)
  return;
 __builtin_va_start(ap,message);
 __logmsg(6, logmsg_stdout, message, ap);
 __builtin_va_end(ap);
}

canonical_original_code:
void logmsg_verbose(char *message, ...)
{
 __builtin_va_list ap;
 logmsg_intr();
 if (!logmsg_detail)
  return;
 if (logmsg_quiet)
  return;
 __builtin_va_start(ap,message);
 __logmsg(6, logmsg_stdout, message, ap);
 __builtin_va_end(ap);
}


mclosedir

decompiled_code:
void __fastcall mclosedir(void *ptr)
{
void *v2; // rdi

v2 = *(void **)ptr;
if ( v2 )
free(v2);
free(ptr);
}

canonical_decompiled_code:
void __fastcall func0(void *ptr)
{
void *v2; // rdi

v2 = *(void **)ptr;
if ( v2 )
free(v2);
free(ptr);
}

original_code:
void
mclosedir(struct mDIR *mdirp)
{
 if (mdirp->m_entries != ((void *)0))
  free(mdirp->m_entries);
 free(mdirp);
}

variable_types: struct mDIR { void *m_entries; unsigned long m_nentries; void *m_parent; unsigned long m_parent_pathlen; } *


malphasort

decompiled_code:
int __fastcall malphasort(_QWORD *a1, size_t *a2)
{
size_t v2; // rdx
size_t v3; // r8
int result; // eax

v2 = a1[32];
v3 = a2[32];
if ( v2 == v3 )
{
if ( v2 )
result = memcmp(a1, a2, v2);
else
result = 0;
}
else if ( v2 > v3 )
{
if ( v3 )
{
result = memcmp(a1, a2, a2[32]);
if ( !result )
result = 1;
}
else
{
result = -1;
}
}
else
{
result = 1;
if ( v2 )
{
result = memcmp(a1, a2, v2);
if ( !result )
result = -1;
}
}
return result;
}

canonical_decompiled_code:
int __fastcall func1(_QWORD *a1, size_t *a2)
{
size_t v2; // rdx
size_t v3; // r8
int result; // eax

v2 = a1[32];
v3 = a2[32];
if ( v2 == v3 )
{
if ( v2 )
result = memcmp(a1, a2, v2);
else
result = 0;
}
else if ( v2 > v3 )
{
if ( v3 )
{
result = memcmp(a1, a2, a2[32]);
if ( !result )
result = 1;
}
else
{
result = -1;
}
}
else
{
result = 1;
if ( v2 )
{
result = memcmp(a1, a2, v2);
if ( !result )
result = -1;
}
}
return result;
}

original_code:
int
malphasort(const void *p1, const void *p2)
{
 const struct mdirent *mdp1 = p1, *mdp2 = p2;
 int rv;
 if (mdp1->md_namelen == mdp2->md_namelen) {
  if (mdp1->md_namelen == 0)
   return (0);
  return (memcmp(mdp1->md_name, mdp2->md_name,
          mdp1->md_namelen));
 }
 if (mdp1->md_namelen > mdp2->md_namelen) {
  if (mdp2->md_namelen == 0)
   return (-1);
  rv = memcmp(mdp1->md_name, mdp2->md_name, mdp2->md_namelen);
  if (rv == 0)
   rv = 1;
 } else {
  if (mdp1->md_namelen == 0)
   return (1);
  rv = memcmp(mdp1->md_name, mdp2->md_name, mdp1->md_namelen);
  if (rv == 0)
   rv = -1;
 }
 return (rv);
}

canonical_original_code:
int malphasort(void *p1, void *p2)
{
 struct mdirent *mdp1 = p1; struct mdirent *mdp2 = p2;
 int rv;
 if (mdp1->md_namelen == mdp2->md_namelen) {
  if (mdp1->md_namelen == 0)
   return (0);
  return (memcmp(mdp1->md_name, mdp2->md_name,
          mdp1->md_namelen));
 }
 if (mdp1->md_namelen > mdp2->md_namelen) {
  if (mdp2->md_namelen == 0)
   return (-1);
  rv = memcmp(mdp1->md_name, mdp2->md_name, mdp2->md_namelen);
  if (rv == 0)
   rv = 1;
 } else {
  if (mdp1->md_namelen == 0)
   return (1);
  rv = memcmp(mdp1->md_name, mdp2->md_name, mdp1->md_namelen);
  if (rv == 0)
   rv = -1;
 }
 return (rv);
}

variable_types: struct mdirent { char md_name[-1]; unsigned long md_namelen; struct stat { unsigned long st_dev; unsigned long st_ino; unsigned long st_nlink; unsigned int st_mode; unsigned int st_uid; unsigned int st_gid; int __pad0; unsigned long st_rdev; long st_size; long st_blksize; long st_blocks; long st_atime; unsigned long st_atimensec; long st_mtime; unsigned long st_mtimensec; long st_ctime; unsigned long st_ctimensec; long __glibc_reserved[3]; } md_stat; _Bool md_dead; } *

variable_types: rv int

return_type: int

user_defined_types: struct mdirent { char md_name[-1]; unsigned long md_namelen; struct stat md_stat; _Bool md_dead; }


decompiled_code:
__int64 __fastcall hash_pton(char *s2, __int64 a2)
{
size_t v2; // rdx
const char *v4; // rdi
void **i; // rbx

v2 = 3LL;
v4 = (const char *)&unk_F7;
for ( i = &hashents; ; v2 = (size_t)i[1] )
{
if ( v2 == a2 && !strncasecmp(v4, s2, v2) )
return *((unsigned int *)i + 4);
v4 = (const char *)i[3];
i += 3;
if ( !v4 )
break;
}
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func0(char *s2, __int64 a2)
{
size_t v2; // rdx
const char *v4; // rdi
void **i; // rbx

v2 = 3LL;
v4 = (const char *)&unk_F7;
for ( i = &hashents; ; v2 = (size_t)i[1] )
{
if ( v2 == a2 && !strncasecmp(v4, s2, v2) )
return *((unsigned int *)i + 4);
v4 = (const char *)i[3];
i += 3;
if ( !v4 )
break;
}
return 0LL;
}

original_code:
int
hash_pton(const char *name, size_t namelen)
{
 const struct hashent *h;
 for (h = hashents ; h->name != ((void *)0) ; h++) {
  if ((h->namelen == namelen) &&
      (strncasecmp(h->name, name, namelen) == 0)) {
   return (h->type);
  }
 }
 return (HASH_UNSPEC);
}

canonical_original_code:
int hash_pton(char *name, unsigned long namelen)
{
 struct hashent *h;
 for (h = hashents ; h->name != ((void *)0) ; h++) {
  if ((h->namelen == namelen) &&
      (strncasecmp(h->name, name, namelen) == 0)) {
   return (h->type);
  }
 }
 return (HASH_UNSPEC);
}

variable_types:
name
char *

variable_types:
namelen
unsigned long

variable_types: struct hashent { char *name; unsigned long namelen; int type; } *


decompiled_code:
void *__fastcall hash_ntop(int a1, void *a2, unsigned __int64 a3)
{
int v4; // eax
void **v5; // rbx
const void *v6; // rsi
void *result; // rax

v4 = 1;
v5 = &hashents;
v6 = &unk_F7;
while ( v4 != a1 )
{
v6 = v5[3];
v5 += 3;
if ( !v6 )
return 0LL;
v4 = *((_DWORD *)v5 + 4);
}
result = 0LL;
if ( (unsigned __int64)v5[1] < a3 )
{
memcpy(a2, v6, (size_t)v5[1]);
result = v5[1];
}
return result;
}

canonical_decompiled_code:
void *__fastcall func1(int a1, void *a2, unsigned __int64 a3)
{
int v4; // eax
void **v5; // rbx
const void *v6; // rsi
void *result; // rax

v4 = 1;
v5 = &hashents;
v6 = &unk_F7;
while ( v4 != a1 )
{
v6 = v5[3];
v5 += 3;
if ( !v6 )
return 0LL;
v4 = *((_DWORD *)v5 + 4);
}
result = 0LL;
if ( (unsigned __int64)v5[1] < a3 )
{
memcpy(a2, v6, (size_t)v5[1]);
result = v5[1];
}
return result;
}

original_code:
size_t
hash_ntop(int type, void *buffer, size_t bufsize)
{
 const struct hashent *h;
 for (h = hashents ; h->name != ((void *)0) ; h++) {
  if (h->type == type) {
   if (h->namelen >= bufsize)
    break;
   (void)memcpy(buffer, h->name, h->namelen);
   return (h->namelen);
  }
 }
 return (0);
}

canonical_original_code:
unsigned long hash_ntop(int type, void *buffer, unsigned long bufsize)
{
 struct hashent *h;
 for (h = hashents ; h->name != ((void *)0) ; h++) {
  if (h->type == type) {
   if (h->namelen >= bufsize)
    break;
   (void)memcpy(buffer, h->name, h->namelen);
   return (h->namelen);
  }
 }
 return (0);
}

variable_types: type int

variable_types:
buffer
void *

variable_types:
bufsize
unsigned long

user_defined_types: struct hashent { char *name; unsigned long namelen; int type; }


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

if ( a1 == 1 )
{
*a2 = &MD5_args;
result = 1LL;
}
else if ( a1 == 2 )
{
*a2 = &SHA1_args;
result = 1LL;
}
else
{
result = 0LL;
}
return result;
}

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

if ( a1 == 1 )
{
*a2 = &MD5_args;
result = 1LL;
}
else if ( a1 == 2 )
{
*a2 = &SHA1_args;
result = 1LL;
}
else
{
result = 0LL;
}
return result;
}

original_code:
_Bool
hash_set(int type, const struct hash_args **args)
{
 switch (type) {
 case HASH_MD5:
  *args = &MD5_args;
  break;
 case HASH_SHA1:
  *args = &SHA1_args;
  break;
 default:
  return (0);
 }
 return (1);
}

canonical_original_code:
_Bool hash_set(int type, struct hash_args **args)
{
 switch (type) {
 case HASH_MD5:
  *args = &MD5_args;
  break;
 case HASH_SHA1:
  *args = &SHA1_args;
  break;
 default:
  return (0);
 }
 return (1);
}

variable_types: struct hash_args { _Bool (*init)(void **); void (*update)(void *, void *, unsigned long); void (*final)(void *, unsigned char *); void (*destroy)(void *); unsigned long length; } **


decompiled_code:
__int64 __fastcall mopendir_rcs_unlink(char *path, __int64 a2, unsigned __int64 a3, __int64 a4)
{
char *v6; // rcx
size_t v7; // r8
char *v8; // rax
unsigned __int64 v10; // rdi
char *v11; // rax
__int64 v12; // rax

v6 = &path[a2];
if ( *(_BYTE *)(a4 + 409) )
{
if ( a2 + 6 >= a3 )
goto LABEL_4;
*(_DWORD *)v6 = 1769239617;
v6 += 6;
*((_WORD *)v6 - 1) = 12131;
v7 = *(_QWORD *)(a4 + 256);
if ( v7 + a2 + 6 >= a3 )
goto LABEL_4;
}
else
{
v7 = *(_QWORD *)(a4 + 256);
if ( v7 + a2 >= a3 )
{
LABEL_4:
v8 = strerror(22);
logmsg_err("%s", v8);
return 0LL;
}
}
*((_BYTE *)memcpy(v6, (const void *)a4, v7) + *(_QWORD *)(a4 + 256)) = 0;
if ( unlink(path) != -1 || (LODWORD(v10) = *_errno_location(), (_DWORD)v10 == 2) )
{
if ( !*(_BYTE *)(a4 + 409) )
return 1LL;
path[a2 + 6] = 0;
if ( rmdir(path) != -1 )
return 1LL;
v10 = (unsigned int)*_errno_location();
if ( (unsigned int)v10 <= 0x27 )
{
v12 = 0x8000020004LL;
if ( _bittest64(&v12, v10) )
return 1LL;
}
}
v11 = strerror(v10);
logmsg_err("%s: %s", path, v11);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func0(char *path, __int64 a2, unsigned __int64 a3, __int64 a4)
{
char *v6; // rcx
size_t v7; // r8
char *v8; // rax
unsigned __int64 v10; // rdi
char *v11; // rax
__int64 v12; // rax

v6 = &path[a2];
if ( *(_BYTE *)(a4 + 409) )
{
if ( a2 + 6 >= a3 )
goto LABEL_4;
*(_DWORD *)v6 = 1769239617;
v6 += 6;
*((_WORD *)v6 - 1) = 12131;
v7 = *(_QWORD *)(a4 + 256);
if ( v7 + a2 + 6 >= a3 )
goto LABEL_4;
}
else
{
v7 = *(_QWORD *)(a4 + 256);
if ( v7 + a2 >= a3 )
{
LABEL_4:
v8 = strerror(22);
logmsg_err("%s", v8);
return 0LL;
}
}
*((_BYTE *)memcpy(v6, (const void *)a4, v7) + *(_QWORD *)(a4 + 256)) = 0;
if ( unlink(path) != -1 || (LODWORD(v10) = *_errno_location(), (_DWORD)v10 == 2) )
{
if ( !*(_BYTE *)(a4 + 409) )
return 1LL;
path[a2 + 6] = 0;
if ( rmdir(path) != -1 )
return 1LL;
v10 = (unsigned int)*_errno_location();
if ( (unsigned int)v10 <= 0x27 )
{
v12 = 0x8000020004LL;
if ( _bittest64(&v12, v10) )
return 1LL;
}
}
v11 = strerror(v10);
logmsg_err("%s: %s", path, v11);
return 0LL;
}

original_code:
_Bool
mopendir_rcs_unlink(char *path, size_t pathlen, size_t pathmax,
      struct mdirent_rcs *mdp)
{
 char *rpath = &path[pathlen];
 size_t rpathlen = pathlen;
 if (mdp->md_attic) {
  if (pathlen + 6 >= pathmax) {
   logmsg_err("%s", strerror(22));
   return (0);
  }
  (void)memcpy(rpath, "Attic/", 6);
  rpath += 6;
  rpathlen += 6;
 }
 if (rpathlen + mdp->md_namelen >= pathmax) {
  logmsg_err("%s", strerror(22));
  return (0);
 }
 (void)memcpy(rpath, mdp->md_name, mdp->md_namelen);
 rpath[mdp->md_namelen] = '\0';
 if (unlink(path) == -1) {
  if ((*__errno_location ()) != 2) {
   logmsg_err("%s: %s", path, strerror((*__errno_location ())));
   return (0);
  }
 }
 if (mdp->md_attic) {
  path[pathlen + 6] = '\0';
  if (rmdir(path) == -1) {
   if (((*__errno_location ()) != 2) && ((*__errno_location ()) != 17) &&
       ((*__errno_location ()) != 39)) {
    logmsg_err("%s: %s", path, strerror((*__errno_location ())));
    return (0);
   }
  }
 }
 return (1);
}

canonical_original_code:
_Bool mopendir_rcs_unlink(char *path, unsigned long pathlen, unsigned long pathmax, struct mdirent_rcs *mdp)
{
 char *rpath = &path[pathlen];
 unsigned long rpathlen = pathlen;
 if (mdp->md_attic) {
  if (pathlen + 6 >= pathmax) {
   logmsg_err("%s", strerror(22));
   return (0);
  }
  (void)memcpy(rpath, "Attic/", 6);
  rpath += 6;
  rpathlen += 6;
 }
 if (rpathlen + mdp->md_namelen >= pathmax) {
  logmsg_err("%s", strerror(22));
  return (0);
 }
 (void)memcpy(rpath, mdp->md_name, mdp->md_namelen);
 rpath[mdp->md_namelen] = '\0';
 if (unlink(path) == -1) {
  if ((*__errno_location ()) != 2) {
   logmsg_err("%s: %s", path, strerror((*__errno_location ())));
   return (0);
  }
 }
 if (mdp->md_attic) {
  path[pathlen + 6] = '\0';
  if (rmdir(path) == -1) {
   if (((*__errno_location ()) != 2) && ((*__errno_location ()) != 17) &&
       ((*__errno_location ()) != 39)) {
    logmsg_err("%s: %s", path, strerror((*__errno_location ())));
    return (0);
   }
  }
 }
 return (1);
}

variable_types:
path
char *

variable_types:
pathlen
unsigned long

variable_types:
pathmax
unsigned long

variable_types: struct mdirent_rcs { char md_name[-1]; unsigned long md_namelen; struct stat { unsigned long st_dev; unsigned long st_ino; unsigned long st_nlink; unsigned int st_mode; unsigned int st_uid; unsigned int st_gid; int __pad0; unsigned long st_rdev; long st_size; long st_blksize; long st_blocks; long st_atime; unsigned long st_atimensec; long st_mtime; unsigned long st_mtimensec; long st_ctime; unsigned long st_ctimensec; long __glibc_reserved[3]; } md_stat; _Bool md_dead; _Bool md_attic; } *

variable_types:
rpath
char *

variable_types:
rpathlen
unsigned long

user_defined_types: struct mdirent_rcs { char md_name[-1]; unsigned long md_namelen; struct stat md_stat; _Bool md_dead; _Bool md_attic; }


cvscan

original_code:
_Bool
cvscan(struct collection *cl)
{
 struct scanfile_create_args sca;
 struct mdirent_args mda;
 if (strlen(cl->cl_scan_name) == 0)
  return (1);
 if ((cl->cl_super != ((void *)0)) &&
     (strcmp(cl->cl_super->cl_scan_name, cl->cl_scan_name) == 0)) {
  return (1);
 }
 logmsg("Scanfile: name %s, release %s, prefix %s", cl->cl_name,
        cl->cl_release, cl->cl_prefix);
 mda.mda_errormode = cl->cl_errormode;
 mda.mda_symfollow = cl->cl_symfollow;
 mda.mda_remove = 0;
 sca.sca_name = cl->cl_scan_name;
 sca.sca_prefix = cl->cl_prefix;
 sca.sca_release = cl->cl_release;
 sca.sca_rprefix = cl->cl_rprefix;
 sca.sca_rprefixlen = cl->cl_rprefixlen;
 sca.sca_mode = 0400|0200|(0400 >> 3)|((0400 >> 3) >> 3);
 sca.sca_mdirent_args = &mda;
 sca.sca_umask = cl->cl_umask;
 if (!scanfile_create(&sca))
  return (0);
 logmsg("Finished successfully");
 return (1);
}

variable_types: struct collection { struct collection *cl_next; char cl_name[-1]; char cl_release[-1]; char cl_prefix[4096]; unsigned long cl_prefixlen; char cl_comment[256]; int cl_errormode; _Bool cl_symfollow; unsigned short cl_umask; char cl_dist_name[-1]; char cl_scan_name[-1]; struct collection *cl_super; char cl_super_name[-1]; } *

variable_types: struct scanfile_create_args { char *sca_name; char *sca_rprefix; unsigned long sca_rprefixlen; unsigned int sca_mode; struct mdirent_args { int mda_errormode; _Bool mda_symfollow; } *sca_mdirent_args; unsigned int sca_umask; }

user_defined_types: struct scanfile_create_args { char *sca_name; char *sca_rprefix; unsigned long sca_rprefixlen; unsigned int sca_mode; struct mdirent_args *sca_mdirent_args; unsigned int sca_umask; }


usage

decompiled_code:
void __noreturn usage()
{
logmsg_err(
"Usage: cvscan [-hqv] [-r <release>] -c <file> [<name>]\n"
" cvscan [-FLhlqv] [-r <release>] -f <file> <directory>");
exit(1);
}

canonical_decompiled_code:
void __noreturn func1()
{
logmsg_err(
"Usage: cvscan [-hqv] [-r <release>] -c <file> [<name>]\n"
" cvscan [-FLhlqv] [-r <release>] -f <file> <directory>");
exit(1);
}

original_code:
void
usage(void)
{
 logmsg_err("Usage: cvscan [-hqv] [-r <release>] -c <file> [<name>]\n"
     "       cvscan [-FLhlqv] [-r <release>] -f <file> "
     "<directory>");
 exit(1);
}

canonical_original_code:
void usage()
{
 logmsg_err("Usage: cvscan [-hqv] [-r <release>] -c <file> [<name>]\n"
     "       cvscan [-FLhlqv] [-r <release>] -f <file> "
     "<directory>");
 exit(1);
}


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
char *v3; // r13
char v4; // r12
int v5; // eax
char *v6; // r15
size_t v7; // rax
size_t v8; // r14
char *v9; // r15
size_t v10; // rax
size_t v11; // r14
__int64 v12; // r12
int v13; // ebx
const char **v14; // rbp
__int64 v15; // rax
__int64 v16; // r13
__int64 v17; // rax
_QWORD *v18; // r15
_QWORD *v19; // rbp
int v20; // er12
char v21; // al
_BYTE v23[264]; // [rsp+0h] [rbp-4668h] BYREF
char dest[8720]; // [rsp+108h] [rbp-4560h] BYREF
int v25; // [rsp+2318h] [rbp-2350h]
char v26; // [rsp+231Ch] [rbp-234Ch]
char v27[4680]; // [rsp+3420h] [rbp-1248h] BYREF

v3 = 0LL;
v4 = 0;
collection_init(v23, argv, envp);
while ( 1 )
{
v5 = _posix_getopt((unsigned int)argc, argv, "FLc:f:hlqr:v");
if ( v5 == -1 )
break;
switch ( v5 )
{
case 'F':
if ( !v26 )
goto LABEL_4;
v26 = 0;
break;
case 'L':
if ( v25 )
goto LABEL_4;
v25 = 2;
break;
case 'c':
if ( v3 )
goto LABEL_4;
v3 = optarg;
break;
case 'f':
if ( v27[0] )
goto LABEL_4;
v9 = optarg;
v10 = strlen(optarg);
v11 = v10;
if ( v10 > 0x10FF )
goto LABEL_4;
memcpy(v27, v9, v10);
v27[v11] = 0;
break;
case 'l':
if ( v25 )
goto LABEL_4;
v25 = 3;
break;
case 'q':
if ( v4 )
goto LABEL_4;
logmsg_quiet = 1;
v4 = 1;
break;
case 'r':
if ( dest[0] )
goto LABEL_4;
v6 = optarg;
v7 = strlen(optarg);
v8 = v7;
if ( v7 > 0xFF )
goto LABEL_4;
memcpy(dest, v6, v7);
dest[v8] = 0;
break;
case 'v':
if ( v4 )
goto LABEL_4;
logmsg_detail = 1;
v4 = 1;
break;
default:
goto LABEL_4;
}
}
v12 = optind;
if ( !v25 )
v25 = 1;
if ( (unsigned __int8)cvsync_init() )
{
v13 = argc - v12;
v14 = &argv[v12];
if ( v3 )
{
if ( (unsigned __int8)collection_set_default(v23, 0LL) )
{
v15 = config_load(v3);
v16 = v15;
if ( v15 )
{
if ( !v13 )
{
v18 = *(_QWORD **)(v15 + 22328);
LABEL_33:
v19 = v18;
v20 = 0;
while ( v19 )
{
v21 = cvscan((__int64)v19);
v19 = (_QWORD *)*v19;
if ( !v21 )
v20 = 1;
}
if ( v13 )
collection_destroy(v18);
config_destroy(v16);
LABEL_40:
exit(v20);
}
if ( v13 == 1 )
{
v17 = collection_lookup(*(_QWORD *)(v15 + 22328), *v14, dest);
v18 = (_QWORD *)v17;
if ( !v17 )
{
logmsg_err("Not such a collection: %s/%s", *v14, dest);
config_destroy(v16);
exit(1);
}
if ( !*(_BYTE *)(v17 + 13344) )
{
logmsg_err("Not specified the output file.");
collection_destroy(v18);
config_destroy(v16);
exit(1);
}
goto LABEL_33;
}
LABEL_4:
usage();
}
}
}
else
{
if ( v13 != 1 )
goto LABEL_4;
if ( (unsigned __int8)collection_set_default(v23, *v14) )
{
if ( v27[0] )
{
v20 = (unsigned __int8)cvscan((__int64)v23) == 0;
goto LABEL_40;
}
logmsg_err("Not specified the output file.");
}
}
}
exit(1);
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
char *v3; // r13
char v4; // r12
int v5; // eax
char *v6; // r15
size_t v7; // rax
size_t v8; // r14
char *v9; // r15
size_t v10; // rax
size_t v11; // r14
__int64 v12; // r12
int v13; // ebx
const char **v14; // rbp
__int64 v15; // rax
__int64 v16; // r13
__int64 v17; // rax
_QWORD *v18; // r15
_QWORD *v19; // rbp
int v20; // er12
char v21; // al
_BYTE v23[264]; // [rsp+0h] [rbp-4668h] BYREF
char dest[8720]; // [rsp+108h] [rbp-4560h] BYREF
int v25; // [rsp+2318h] [rbp-2350h]
char v26; // [rsp+231Ch] [rbp-234Ch]
char v27[4680]; // [rsp+3420h] [rbp-1248h] BYREF

v3 = 0LL;
v4 = 0;
collection_init(v23, argv, envp);
while ( 1 )
{
v5 = _posix_getopt((unsigned int)argc, argv, "FLc:f:hlqr:v");
if ( v5 == -1 )
break;
switch ( v5 )
{
case 'F':
if ( !v26 )
goto LABEL_4;
v26 = 0;
break;
case 'L':
if ( v25 )
goto LABEL_4;
v25 = 2;
break;
case 'c':
if ( v3 )
goto LABEL_4;
v3 = optarg;
break;
case 'f':
if ( v27[0] )
goto LABEL_4;
v9 = optarg;
v10 = strlen(optarg);
v11 = v10;
if ( v10 > 0x10FF )
goto LABEL_4;
memcpy(v27, v9, v10);
v27[v11] = 0;
break;
case 'l':
if ( v25 )
goto LABEL_4;
v25 = 3;
break;
case 'q':
if ( v4 )
goto LABEL_4;
logmsg_quiet = 1;
v4 = 1;
break;
case 'r':
if ( dest[0] )
goto LABEL_4;
v6 = optarg;
v7 = strlen(optarg);
v8 = v7;
if ( v7 > 0xFF )
goto LABEL_4;
memcpy(dest, v6, v7);
dest[v8] = 0;
break;
case 'v':
if ( v4 )
goto LABEL_4;
logmsg_detail = 1;
v4 = 1;
break;
default:
goto LABEL_4;
}
}
v12 = optind;
if ( !v25 )
v25 = 1;
if ( (unsigned __int8)cvsync_init() )
{
v13 = argc - v12;
v14 = &argv[v12];
if ( v3 )
{
if ( (unsigned __int8)collection_set_default(v23, 0LL) )
{
v15 = config_load(v3);
v16 = v15;
if ( v15 )
{
if ( !v13 )
{
v18 = *(_QWORD **)(v15 + 22328);
LABEL_33:
v19 = v18;
v20 = 0;
while ( v19 )
{
v21 = func0((__int64)v19);
v19 = (_QWORD *)*v19;
if ( !v21 )
v20 = 1;
}
if ( v13 )
collection_destroy(v18);
config_destroy(v16);
LABEL_40:
exit(v20);
}
if ( v13 == 1 )
{
v17 = collection_lookup(*(_QWORD *)(v15 + 22328), *v14, dest);
v18 = (_QWORD *)v17;
if ( !v17 )
{
logmsg_err("Not such a collection: %s/%s", *v14, dest);
config_destroy(v16);
exit(1);
}
if ( !*(_BYTE *)(v17 + 13344) )
{
logmsg_err("Not specified the output file.");
collection_destroy(v18);
config_destroy(v16);
exit(1);
}
goto LABEL_33;
}
LABEL_4:
func1();
}
}
}
else
{
if ( v13 != 1 )
goto LABEL_4;
if ( (unsigned __int8)collection_set_default(v23, *v14) )
{
if ( v27[0] )
{
v20 = (unsigned __int8)func0((__int64)v23) == 0;
goto LABEL_40;
}
logmsg_err("Not specified the output file.");
}
}
}
exit(1);
}

original_code:
int
main(int argc, char *argv[])
{
 const char *cfname = ((void *)0);
 struct collection *cls = ((void *)0), *cl, base_cl;
 struct config *cf;
 size_t len;
 int ch, status = 0;
 _Bool log_flag = 0;
 cl = &base_cl;
 collection_init(cl);
 while ((ch = getopt(argc, argv, "FLc:f:hlqr:v")) != -1) {
  switch (ch) {
  case 'F':
   if (!cl->cl_symfollow) {
    usage();
   }
   cl->cl_symfollow = 0;
   break;
  case 'L':
   if (cl->cl_errormode != CVSYNC_ERRORMODE_UNSPEC) {
    usage();
   }
   cl->cl_errormode = CVSYNC_ERRORMODE_FIXUP;
   break;
  case 'c':
   if (cfname != ((void *)0)) {
    usage();
   }
   cfname = optarg;
   break;
  case 'f':
   if (strlen(cl->cl_scan_name) != 0) {
    usage();
   }
   len = strlen(optarg);
   if (len >= sizeof(cl->cl_scan_name)) {
    usage();
   }
   (void)memcpy(cl->cl_scan_name, optarg, len);
   cl->cl_scan_name[len] = '\0';
   break;
  case 'h':
   usage();
  case 'l':
   if (cl->cl_errormode != CVSYNC_ERRORMODE_UNSPEC) {
    usage();
   }
   cl->cl_errormode = CVSYNC_ERRORMODE_IGNORE;
   break;
  case 'q':
   if (log_flag) {
    usage();
   }
   logmsg_quiet = 1;
   log_flag = 1;
   break;
  case 'r':
   if (strlen(cl->cl_release) != 0) {
    usage();
   }
   len = strlen(optarg);
   if (len >= sizeof(cl->cl_release)) {
    usage();
   }
   (void)memcpy(cl->cl_release, optarg, len);
   cl->cl_release[len] = '\0';
   break;
  case 'v':
   if (log_flag) {
    usage();
   }
   logmsg_detail = 1;
   log_flag = 1;
   break;
  default:
   usage();
  }
 }
 argc -= optind;
 argv += optind;
 if (cl->cl_errormode == CVSYNC_ERRORMODE_UNSPEC)
  cl->cl_errormode = CVSYNC_ERRORMODE_ABORT;
 if (!cvsync_init())
  exit(1);
 if (cfname == ((void *)0)) {
  if (argc != 1) {
   usage();
  }
  if (!collection_set_default(cl, argv[0]))
   exit(1);
  if (strlen(cl->cl_scan_name) == 0) {
   logmsg_err("Not specified the output file.");
   exit(1);
  }
  if (!cvscan(cl))
   status = 1;
 } else {
  if (!collection_set_default(cl, ((void *)0)))
   exit(1);
  if ((cf = config_load(cfname)) == ((void *)0))
   exit(1);
  switch (argc) {
  case 0:
   cls = cf->cf_collections;
   break;
  case 1:
   cls = collection_lookup(cf->cf_collections, argv[0],
            base_cl.cl_release);
   if (cls == ((void *)0)) {
    logmsg_err("Not such a collection: %s/%s",
        argv[0], base_cl.cl_release);
    config_destroy(cf);
    exit(1);
   }
   if (strlen(cls->cl_scan_name) == 0) {
    logmsg_err("Not specified the output file.");
    collection_destroy(cls);
    config_destroy(cf);
    exit(1);
   }
   break;
  default:
   usage();
  }
  for (cl = cls ; cl != ((void *)0) ; cl = cl->cl_next) {
   if (!cvscan(cl))
    status = 1;
  }
  if (argc != 0)
   collection_destroy(cls);
  config_destroy(cf);
 }
 exit(status);
}

canonical_original_code:
int main(int argc, char *argv[])
{
 char *cfname = ((void *)0);
 struct collection *cls = ((void *)0); struct collection *cl; struct collection base_cl;
 struct config *cf;
 unsigned long len;
 int ch; int status = 0;
 _Bool log_flag = 0;
 cl = &base_cl;
 collection_init(cl);
 while ((ch = getopt(argc, argv, "FLc:f:hlqr:v")) != -1) {
  switch (ch) {
  case 'F':
   if (!cl->cl_symfollow) {
    usage();
   }
   cl->cl_symfollow = 0;
   break;
  case 'L':
   if (cl->cl_errormode != CVSYNC_ERRORMODE_UNSPEC) {
    usage();
   }
   cl->cl_errormode = CVSYNC_ERRORMODE_FIXUP;
   break;
  case 'c':
   if (cfname != ((void *)0)) {
    usage();
   }
   cfname = optarg;
   break;
  case 'f':
   if (strlen(cl->cl_scan_name) != 0) {
    usage();
   }
   len = strlen(optarg);
   if (len >= sizeof(cl->cl_scan_name)) {
    usage();
   }
   (void)memcpy(cl->cl_scan_name, optarg, len);
   cl->cl_scan_name[len] = '\0';
   break;
  case 'h':
   usage();
  case 'l':
   if (cl->cl_errormode != CVSYNC_ERRORMODE_UNSPEC) {
    usage();
   }
   cl->cl_errormode = CVSYNC_ERRORMODE_IGNORE;
   break;
  case 'q':
   if (log_flag) {
    usage();
   }
   logmsg_quiet = 1;
   log_flag = 1;
   break;
  case 'r':
   if (strlen(cl->cl_release) != 0) {
    usage();
   }
   len = strlen(optarg);
   if (len >= sizeof(cl->cl_release)) {
    usage();
   }
   (void)memcpy(cl->cl_release, optarg, len);
   cl->cl_release[len] = '\0';
   break;
  case 'v':
   if (log_flag) {
    usage();
   }
   logmsg_detail = 1;
   log_flag = 1;
   break;
  default:
   usage();
  }
 }
 argc -= optind;
 argv += optind;
 if (cl->cl_errormode == CVSYNC_ERRORMODE_UNSPEC)
  cl->cl_errormode = CVSYNC_ERRORMODE_ABORT;
 if (!cvsync_init())
  exit(1);
 if (cfname == ((void *)0)) {
  if (argc != 1) {
   usage();
  }
  if (!collection_set_default(cl, argv[0]))
   exit(1);
  if (strlen(cl->cl_scan_name) == 0) {
   logmsg_err("Not specified the output file.");
   exit(1);
  }
  if (!cvscan(cl))
   status = 1;
 } else {
  if (!collection_set_default(cl, ((void *)0)))
   exit(1);
  if ((cf = config_load(cfname)) == ((void *)0))
   exit(1);
  switch (argc) {
  case 0:
   cls = cf->cf_collections;
   break;
  case 1:
   cls = collection_lookup(cf->cf_collections, argv[0],
            base_cl.cl_release);
   if (cls == ((void *)0)) {
    logmsg_err("Not such a collection: %s/%s",
        argv[0], base_cl.cl_release);
    config_destroy(cf);
    exit(1);
   }
   if (strlen(cls->cl_scan_name) == 0) {
    logmsg_err("Not specified the output file.");
    collection_destroy(cls);
    config_destroy(cf);
    exit(1);
   }
   break;
  default:
   usage();
  }
  for (cl = cls ; cl != ((void *)0) ; cl = cl->cl_next) {
   if (!cvscan(cl))
    status = 1;
  }
  if (argc != 0)
   collection_destroy(cls);
  config_destroy(cf);
 }
 exit(status);
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types:
cfname
char *

variable_types: struct config { char cf_addr[-1]; char cf_serv[-1]; unsigned long cf_maxclients; char cf_base[4096]; char cf_access_name[-1]; char cf_halt_name[-1]; char cf_pid_name[-1]; int cf_hash; struct collection { struct collection *cl_next; char cl_name[-1]; char cl_release[-1]; char cl_prefix[4096]; unsigned long cl_prefixlen; char cl_comment[256]; int cl_errormode; _Bool cl_symfollow; unsigned short cl_umask; char cl_dist_name[-1]; char cl_scan_name[-1]; struct collection *cl_super; char cl_super_name[-1]; } *cf_collections; struct config_include { struct config_include *ci_next; char ci_name[-1]; long ci_mtime; } *cf_includes; int cf_refcnt; } *

variable_types:
len
unsigned long

variable_types: ch int

variable_types: status int

user_defined_types: struct config { char cf_addr[-1]; char cf_serv[-1]; unsigned long cf_maxclients; char cf_base[4096]; char cf_access_name[-1]; char cf_halt_name[-1]; char cf_pid_name[-1]; int cf_hash; struct collection *cf_collections; struct config_include *cf_includes; int cf_refcnt; }


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

v3 = open("/dev/ich2", 2, envp);
if ( v3 >= 0 )
{
v4 = mmap(0LL, 0x2000uLL, 3, 1, v3, 0LL);
if ( v4 != (_DWORD *)-1LL )
{
while ( 1 )
{
v4[2] = 15;
printf("%x\n", 15LL);
sleep(1u);
v4[2] = 0;
sleep(1u);
}
}
_assert_fail("regs != MAP_FAILED", "ich2-mmap.c", 0x13u, "main");
}
_assert_fail("fd >= 0", "ich2-mmap.c", 0x11u, "main");
}

original_code:
int main(int argc, char *argv[]) {
 uint8_t *regs;
 int fd;
 fd = open("/dev/ich2", 02);
 ((void) sizeof ((fd >= 0) ? 1 : 0), __extension__ ({ if (fd >= 0) ; else __assert_fail ("fd >= 0", "ich2-mmap.c", 17, __extension__ __PRETTY_FUNCTION__); }));
 regs = mmap(((void *)0), (8 * 1024), 0x1 | 0x2, 0x01, fd, (0 * 0x20000000UL));
 ((void) sizeof ((regs != ((void *) -1)) ? 1 : 0), __extension__ ({ if (regs != ((void *) -1)) ; else __assert_fail ("regs != MAP_FAILED", "ich2-mmap.c", 19, __extension__ __PRETTY_FUNCTION__); }));
        while(1) {
            *(int *) (regs + 0x08) = 0xf;
            printf("%x\n", *(int *) (regs + 0x08));
            sleep(1);
            *(int *) (regs + 0x08) = 0;
            sleep(1);
        }
 close(fd);
 return 0;
}

canonical_original_code:
int main(int argc, char *argv[]) {
 unsigned char *regs;
 int fd;
 fd = open("/dev/ich2", 02);
 ((void) sizeof ((fd >= 0) ? 1 : 0), __extension__ ({ if (fd >= 0) ; else __assert_fail ("fd >= 0", "ich2-mmap.c", 17, __extension__ __PRETTY_FUNCTION__); }));
 regs = mmap(((void *)0), (8 * 1024), 0x1 | 0x2, 0x01, fd, (0 * 0x20000000UL));
 ((void) sizeof ((regs != ((void *) -1)) ? 1 : 0), __extension__ ({ if (regs != ((void *) -1)) ; else __assert_fail ("regs != MAP_FAILED", "ich2-mmap.c", 19, __extension__ __PRETTY_FUNCTION__); }));
        while(1) {
            *(int *) (regs + 0x08) = 0xf;
            printf("%x\n", *(int *) (regs + 0x08));
            sleep(1);
            *(int *) (regs + 0x08) = 0;
            sleep(1);
        }
 close(fd);
 return 0;
}

variable_types:
regs
unsigned char *

variable_types: fd int


repo: cwu/neural-net

original_code:
void display_num(int num, real_num pattern[], real_num answer[])
{
 printf("\tNumber: %d\n", num);
 printf("--------- 0 - 1 - 2 - 3 - 4 - 5 - 6 - 7 - 8 - 9 -\n");
 printf("answers: ");
 int row, col;
 for (col = 0; col < 10; col++)
 {
  printf("%3.1f ", answer[col]);
 }
 printf("\n\n");
 for (row = 0; row < 9; row++)
 {
  for (col = 0; col < 5; col++)
  {
   printf(" %c", (fabs(pattern[row * 5 + col]) <= 1e-1) ? ' ' : '.');
  }
  printf("\n");
 }
 printf("\n");
}

canonical_original_code:
void display_num(int num, float pattern[], float answer[])
{
 printf("\tNumber: %d\n", num);
 printf("--------- 0 - 1 - 2 - 3 - 4 - 5 - 6 - 7 - 8 - 9 -\n");
 printf("answers: ");
 int row; int col;
 for (col = 0; col < 10; col++)
 {
  printf("%3.1f ", answer[col]);
 }
 printf("\n\n");
 for (row = 0; row < 9; row++)
 {
  for (col = 0; col < 5; col++)
  {
   printf(" %c", (fabs(pattern[row * 5 + col]) <= 1e-1) ? ' ' : '.');
  }
  printf("\n");
 }
 printf("\n");
}

variable_types: num int

variable_types:
pattern
float []

variable_types:
answer
float []

variable_types: row int

variable_types: col int


original_code:
void display_set(real_num inputs[10][45], real_num answers[10][10])
{
 printf("============= start inputs ==============\n\n");
 int num;
 for (num = 0; num < 10; num++)
 {
  display_num(num, inputs[num], answers[num]);
 }
 printf("============= end inputs ==============\n\n");
}

canonical_original_code:
void display_set(float inputs[10][45], float answers[10][10])
{
 printf("============= start inputs ==============\n\n");
 int num;
 for (num = 0; num < 10; num++)
 {
  display_num(num, inputs[num], answers[num]);
 }
 printf("============= end inputs ==============\n\n");
}

variable_types:
inputs
float [10][45]

variable_types:
answers
float [10][10]


correct

decompiled_code:
__int64 __fastcall correct(int a1, __int64 a2, __int64 a3)
{
__int64 v3; // rdx
__int64 v4; // rax

v3 = a3 + 40LL * a1;
v4 = 0LL;
while ( COERCE_FLOAT(COERCE_UNSIGNED_INT(*(float *)(a2 + v4) - *(float *)(v3 + v4)) & LC5) < 0.1 )
{
v4 += 4LL;
if ( v4 == 40 )
return 1LL;
}
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func2(int a1, __int64 a2, __int64 a3)
{
__int64 v3; // rdx
__int64 v4; // rax

v3 = a3 + 40LL * a1;
v4 = 0LL;
while ( COERCE_FLOAT(COERCE_UNSIGNED_INT(*(float *)(a2 + v4) - *(float *)(v3 + v4)) & LC5) < 0.1 )
{
v4 += 4LL;
if ( v4 == 40 )
return 1LL;
}
return 0LL;
}

original_code:
int correct(int num, real_num output[],real_num answers[10][10])
{
 int i;
 for (i = 0; i < 10; i++)
 {
  if (fabs(output[i] - answers[num][i]) >= 1e-1)
   return 0;
 }
 return 1;
}

canonical_original_code:
int correct(int num, float output[], float answers[10][10])
{
 int i;
 for (i = 0; i < 10; i++)
 {
  if (fabs(output[i] - answers[num][i]) >= 1e-1)
   return 0;
 }
 return 1;
}

variable_types:
output
float []

variable_types: i int


decompiled_code:
bool __fastcall eq_real_num(float a1, float a2)
{
return COERCE_FLOAT(COERCE_UNSIGNED_INT(a1 - a2) & LC0) <= 0.000000001;
}

canonical_decompiled_code:
bool __fastcall func0(float a1, float a2)
{
return COERCE_FLOAT(COERCE_UNSIGNED_INT(a1 - a2) & LC0) <= 0.000000001;
}

original_code:
_Bool eq_real_num(real_num x, real_num y)
{
 return fabs(x - y) <= 1e-9;
}

canonical_original_code:
_Bool eq_real_num(float x, float y)
{
 return fabs(x - y) <= 1e-9;
}

variable_types: x float

variable_types: y float


decompiled_code:
size_t __fastcall parse_input(char *src)
{
char *v1; // rbx
size_t result; // rax
__int64 i; // rdx
char v4; // al
__int64 v5; // r12

if ( !src )
_assert_fail("input_str", "my_shell.c", 0x31u, "parse_input");
src[strlen(src) - 1] = 0;
v1 = strchr(src, 32);
*(_BYTE *)arguments = 0;
if ( !v1 )
return (size_t)strcpy(cur_command, src);
strncpy(cur_command, src, v1 - src);
cur_command[v1 - src] = 0;
result = strlen(src);
while ( 1 )
{
if ( &src[result] <= v1 )
{
*((_BYTE *)arguments + 1) = 0;
return result;
}
if ( *v1 != 32 && *v1 != 9 )
break;
++v1;
}
for ( i = 0LL; ; i = v5 )
{
result += (size_t)src;
v5 = i + 1;
if ( (unsigned __int64)v1 >= result )
break;
v4 = *v1++;
*((_BYTE *)arguments + i) = v4;
result = strlen(src);
}
*((_BYTE *)arguments + v5) = 0;
return result;
}

canonical_decompiled_code:
size_t __fastcall func0(char *src)
{
char *v1; // rbx
size_t result; // rax
__int64 i; // rdx
char v4; // al
__int64 v5; // r12

if ( !src )
_assert_fail("input_str", "my_shell.c", 0x31u, "parse_input");
src[strlen(src) - 1] = 0;
v1 = strchr(src, 32);
*(_BYTE *)arguments = 0;
if ( !v1 )
return (size_t)strcpy(cur_command, src);
strncpy(cur_command, src, v1 - src);
cur_command[v1 - src] = 0;
result = strlen(src);
while ( 1 )
{
if ( &src[result] <= v1 )
{
*((_BYTE *)arguments + 1) = 0;
return result;
}
if ( *v1 != 32 && *v1 != 9 )
break;
++v1;
}
for ( i = 0LL; ; i = v5 )
{
result += (size_t)src;
v5 = i + 1;
if ( (unsigned __int64)v1 >= result )
break;
v4 = *v1++;
*((_BYTE *)arguments + i) = v4;
result = strlen(src);
}
*((_BYTE *)arguments + v5) = 0;
return result;
}

original_code:
void parse_input(char * input_str)
{
 ((void) sizeof ((input_str) ? 1 : 0), __extension__ ({ if (input_str) ; else __assert_fail ("input_str", "my_shell.c", 49, __extension__ __PRETTY_FUNCTION__); }));
 char *result;
 int j;
 *(input_str + strlen(input_str) - 1) = 0;
 result = strchr(input_str, ' ');
 *arguments = 0;
 if (result)
 {
  strncpy(cur_command, input_str, result - input_str);
  *(cur_command + (result - input_str)) = 0;
  while (result < input_str + strlen(input_str) && (*result == ' ' || *result == '\t')) result++;
  j = 0;
  while (result < input_str + strlen(input_str))
  {
   *(arguments + j) = *result;
   j++;
   result++;
  }
  *(arguments + j + 1) = 0;
 }
 else
 {
  strcpy(cur_command, input_str);
 }
}

canonical_original_code:
void parse_input(char *input_str)
{
 ((void) sizeof ((input_str) ? 1 : 0), __extension__ ({ if (input_str) ; else __assert_fail ("input_str", "my_shell.c", 49, __extension__ __PRETTY_FUNCTION__); }));
 char *result;
 int j;
 *(input_str + strlen(input_str) - 1) = 0;
 result = strchr(input_str, ' ');
 *arguments = 0;
 if (result)
 {
  strncpy(cur_command, input_str, result - input_str);
  *(cur_command + (result - input_str)) = 0;
  while (result < input_str + strlen(input_str) && (*result == ' ' || *result == '\t')) result++;
  j = 0;
  while (result < input_str + strlen(input_str))
  {
   *(arguments + j) = *result;
   j++;
   result++;
  }
  *(arguments + j + 1) = 0;
 }
 else
 {
  strcpy(cur_command, input_str);
 }
}

variable_types:
result
char *

variable_types: j int


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
char *v3; // rbx
char *v4; // rbp
_BYTE *v5; // rax

v3 = (char *)malloc(0xC8uLL);
user_input = v3;
v4 = (char *)malloc(0xC8uLL);
cur_command = v4;
v5 = malloc(0xC8uLL);
*v4 = 0;
arguments = v5;
*v5 = 0;
*v3 = 0;
do
{
printf(">>> ");
user_input = fgets(user_input, 200, stdin);
parse_input(user_input);
if ( !strcmp(cur_command, "exit") )
break;
system(user_input);
}
while ( strcmp(cur_command, "exit") );
free(user_input);
free(cur_command);
free(arguments);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
char *v3; // rbx
char *v4; // rbp
_BYTE *v5; // rax

v3 = (char *)malloc(0xC8uLL);
user_input = v3;
v4 = (char *)malloc(0xC8uLL);
cur_command = v4;
v5 = malloc(0xC8uLL);
*v4 = 0;
arguments = v5;
*v5 = 0;
*v3 = 0;
do
{
printf(">>> ");
user_input = fgets(user_input, 200, stdin);
func0(user_input);
if ( !strcmp(cur_command, "exit") )
break;
system(user_input);
}
while ( strcmp(cur_command, "exit") );
free(user_input);
free(cur_command);
free(arguments);
return 0;
}

original_code:
int main(void)
{
 user_input = malloc(sizeof(char) * 200);
 cur_command = malloc(sizeof(char) * 200);
 arguments = malloc(sizeof(char) * 200);
 *user_input = *cur_command = *arguments = 0;
 do
 {
  printf( ">>> ");
  user_input = fgets(user_input, 200, stdin);
  parse_input(user_input);
  if (strcmp(cur_command, "exit"))
  {
   system(user_input);
  }
 }
 while (strcmp(cur_command, "exit"));
 free(user_input);
 free(cur_command);
 free(arguments);
 return 0;
}

canonical_original_code:
int main()
{
 user_input = malloc(sizeof(char) * 200);
 cur_command = malloc(sizeof(char) * 200);
 arguments = malloc(sizeof(char) * 200);
 *user_input = *cur_command = *arguments = 0;
 do
 {
  printf( ">>> ");
  user_input = fgets(user_input, 200, stdin);
  parse_input(user_input);
  if (strcmp(cur_command, "exit"))
  {
   system(user_input);
  }
 }
 while (strcmp(cur_command, "exit"));
 free(user_input);
 free(cur_command);
 free(arguments);
 return 0;
}


repo: cyfdecyf/cqueue

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
char *v3; // rbp
pthread_t *v4; // rbx
pthread_t *v5; // r12
pthread_t v6; // rdi
_BYTE v8[64]; // [rsp+0h] [rbp-68h] BYREF
pthread_t newthread; // [rsp+40h] [rbp-28h] BYREF
__int64 v10; // [rsp+48h] [rbp-20h] BYREF

v3 = 0LL;
v4 = (pthread_t *)v8;
queue = (void *)mpsc_q_new(4LL, argv, envp);
v5 = (pthread_t *)v8;
do
pthread_create(v5++, 0LL, producer, v3++);
while ( v3 != (char *)8 );
pthread_create(&newthread, 0LL, consumer, 0LL);
do
{
v6 = *v4++;
pthread_join(v6, 0LL);
}
while ( &v10 != (__int64 *)v4 );
mpsc_q_free(queue);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
char *v3; // rbp
pthread_t *v4; // rbx
pthread_t *v5; // r12
pthread_t v6; // rdi
_BYTE v8[64]; // [rsp+0h] [rbp-68h] BYREF
pthread_t newthread; // [rsp+40h] [rbp-28h] BYREF
__int64 v10; // [rsp+48h] [rbp-20h] BYREF

v3 = 0LL;
v4 = (pthread_t *)v8;
queue = (void *)mpsc_q_new(4LL, argv, envp);
v5 = (pthread_t *)v8;
do
pthread_create(v5++, 0LL, producer, v3++);
while ( v3 != (char *)8 );
pthread_create(&newthread, 0LL, consumer, 0LL);
do
{
v6 = *v4++;
pthread_join(v6, 0LL);
}
while ( &v10 != (__int64 *)v4 );
func9(queue);
return 0;
}

original_code:
int main(int argc, const char *argv[])
{
    int i;
    pthread_t thr[8 +1];
    queue = mpsc_q_new(4);
    for (i = 0; i < 8; i++) {
        pthread_create(&thr[i], ((void *)0), producer, (void *)(long)i);
    }
    pthread_create(&thr[8], ((void *)0), consumer, ((void *)0));
    for (i = 0; i < 8 +1; i++) {
        pthread_join(thr[i], ((void *)0));
    }
    mpsc_q_free(queue);
    return 0;
}

canonical_original_code:
int main(int argc, char *argv[])
{
    int i;
    unsigned long thr[-1];
    queue = mpsc_q_new(4);
    for (i = 0; i < 8; i++) {
        pthread_create(&thr[i], ((void *)0), producer, (void *)(long)i);
    }
    pthread_create(&thr[8], ((void *)0), consumer, ((void *)0));
    for (i = 0; i < 8 +1; i++) {
        pthread_join(thr[i], ((void *)0));
    }
    mpsc_q_free(queue);
    return 0;
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types:
thr
unsigned long [-1]


producer

decompiled_code:
void *__fastcall producer(void *a1)
{
__int64 i; // rbx
__int64 v2; // rsi

for ( i = 0LL; i != 100000; ++i )
{
v2 = i | ((_QWORD)a1 << 32);
mpsc_q_push(queue, v2);
}
return 0LL;
}

canonical_decompiled_code:
void *__fastcall func7(void *a1)
{
__int64 i; // rbx
__int64 v2; // rsi

for ( i = 0LL; i != 100000; ++i )
{
v2 = i | ((_QWORD)a1 << 32);
func10(queue, v2);
}
return 0LL;
}

original_code:
void *producer(void *d)
{
    long i;
    long pid = (long)d;
    for (i = 0; i < 100000; i++) {
        mpsc_q_push(queue, (void *)((pid<<32) | i));
    }
    return ((void *)0);
}

variable_types:
d
void *

variable_types: i long

variable_types: pid long


consumer

original_code:
void *consumer(void *dummy)
{
    long i;
    long expect[8];
    memset(expect, 0, sizeof(expect));
    for (i = 0; i < 8*100000; i++) {
        void *msg = mpsc_q_pop(queue);
        long pid = (long)msg >> 32;
        long val = (long)msg & 0xffffffff;
        ;
        if (val != expect[pid]) {
            printf("[ERROR] %x msg %ld: %ld|%ld, expected val %ld\n",
                    (int)pthread_self(), i, pid, val, expect[pid]);
            exit(1);
        }
        expect[pid]++;
    }
    return ((void *)0);
}

variable_types:
dummy
void *

variable_types:
expect
long [8]

variable_types:
msg
void *

variable_types: val long


decompiled_code:
void __fastcall mpsc_q_free(void *ptr)
{
free(*(void **)ptr);
free(*((void **)ptr + 1));
free(ptr);
}

canonical_decompiled_code:
void __fastcall func9(void *ptr)
{
free(*(void **)ptr);
free(*((void **)ptr + 1));
free(ptr);
}

original_code:
void mpsc_q_free(struct mpsc_q *q)
{
    free(q->arr);
    free(q->w);
    q->arr = ((void *)0);
    free(q);
}

variable_types: struct mpsc_q { void **arr; _Bool *w; int n; long head; long tail; } *


original_code:
void *mpsc_q_pop(struct mpsc_q *q)
{
    while (q->head == q->tail) {
        sched_yield();
    }
    int idx = q->head % q->n;
    while (!q->w[idx]) {
        asm volatile ("pause\n" : : : "memory");
    }
    void *r = q->arr[idx];
    q->w[idx] = 0;
    ;
    asm volatile ("" : : : "memory");
    q->head++;
    ((void) (0));
    return r;
}

variable_types: idx int

variable_types:
r
void *

user_defined_types: struct mpsc_q { void **arr; _Bool *w; int n; long head; long tail; }


decompiled_code:
bool __fastcall mpsc_q_empty(__int64 a1)
{
return *(_QWORD *)(a1 + 24) == *(_QWORD *)(a1 + 32);
}

canonical_decompiled_code:
bool __fastcall func12(__int64 a1)
{
return *(_QWORD *)(a1 + 24) == *(_QWORD *)(a1 + 32);
}

original_code:
_Bool mpsc_q_empty(struct mpsc_q *q)
{
    ((void) (0));
    return q->head == q->tail;
}


wake

repo: cyfdecyf/futex-exp

decompiled_code:
__int64 __fastcall wake(void *a1)
{
sleep(1u);
puts("requeue from ft_wait to ft_requ");
sys_futex_constprop_0_isra_0((__int64)&ft_wait, 3u, 0, 1LL, (__int64)&ft_requ);
sleep(1u);
puts("futex_wake on ft_wait");
sys_futex_constprop_0_isra_0((__int64)&ft_wait, 1u, 1u, 0LL, 0LL);
sleep(1u);
puts("futex_wake on ft_requ");
return sys_futex_constprop_0_isra_0((__int64)&ft_requ, 1u, 1u, 0LL, 0LL);
}

canonical_decompiled_code:
__int64 __fastcall func9(void *a1)
{
sleep(1u);
puts("requeue from ft_wait to ft_requ");
func7((__int64)&ft_wait, 3u, 0, 1LL, (__int64)&ft_requ);
sleep(1u);
puts("futex_wake on ft_wait");
func7((__int64)&ft_wait, 1u, 1u, 0LL, 0LL);
sleep(1u);
puts("futex_wake on ft_requ");
return func7((__int64)&ft_requ, 1u, 1u, 0LL, 0LL);
}

original_code:
void *wake(void *dummy)
{
    sleep(1);
    printf("requeue from ft_wait to ft_requ\n");
    sys_futex(&ft_wait, 3, 0, (void *)1, &ft_requ, 0);
    sleep(1);
    printf("futex_wake on ft_wait\n");
    sys_futex(&ft_wait, 1, 1, ((void *)0), ((void *)0), 0);
    sleep(1);
    printf("futex_wake on ft_requ\n");
    sys_futex(&ft_requ, 1, 1, ((void *)0), ((void *)0), 0);
}