decompiled_code:
__int64 cvsync_init()
{
int v0; // edx
__int64 result; // rax
int *v2; // rax
char *v3; // rax
int *v4; // rax
char *v5; // rax
int *v6; // rax
char *v7; // rax
struct sigaction v8; // [rsp+0h] [rbp-A8h] BYREF

cvsync_sig_ign.sa_handler = (__sighandler_t)cvsync_signal;
if ( sigemptyset(&set) == -1 )
{
v2 = _errno_location();
v3 = strerror(*v2);
logmsg_err("sigemptyset: %s", v3);
result = 0LL;
}
else
{
dword_7A8 = 0;
if ( sigaction(1, &cvsync_sig_ign, 0LL) == -1 || sigaction(13, &cvsync_sig_ign, 0LL) == -1 )
{
v4 = _errno_location();
v5 = strerror(*v4);
logmsg_err("sigaction: %s", v5);
result = 0LL;
}
else if ( sigaction(2, 0LL, &v8) == -1
|| (v8.sa_handler = (__sighandler_t)cvsync_signal, v8.sa_flags &= 0xEFFFFFFF, sigaction(2, &v8, 0LL) == -1)
|| sigaction(15, 0LL, &v8) == -1
|| (v8.sa_handler = (__sighandler_t)cvsync_signal,
v8.sa_flags &= 0xEFFFFFFF,
v0 = sigaction(15, &v8, 0LL),
result = 1LL,
v0 == -1) )
{
v6 = _errno_location();
v7 = strerror(*v6);
logmsg_err("sigaction: %s", v7);
result = 0LL;
}
}
return result;
}

canonical_decompiled_code:
__int64 func1()
{
int v0; // edx
__int64 result; // rax
int *v2; // rax
char *v3; // rax
int *v4; // rax
char *v5; // rax
int *v6; // rax
char *v7; // rax
struct sigaction v8; // [rsp+0h] [rbp-A8h] BYREF

cvsync_sig_ign.sa_handler = (__sighandler_t)cvsync_signal;
if ( sigemptyset(&set) == -1 )
{
v2 = _errno_location();
v3 = strerror(*v2);
logmsg_err("sigemptyset: %s", v3);
result = 0LL;
}
else
{
dword_7A8 = 0;
if ( sigaction(1, &cvsync_sig_ign, 0LL) == -1 || sigaction(13, &cvsync_sig_ign, 0LL) == -1 )
{
v4 = _errno_location();
v5 = strerror(*v4);
logmsg_err("sigaction: %s", v5);
result = 0LL;
}
else if ( sigaction(2, 0LL, &v8) == -1
|| (v8.sa_handler = (__sighandler_t)cvsync_signal, v8.sa_flags &= 0xEFFFFFFF, sigaction(2, &v8, 0LL) == -1)
|| sigaction(15, 0LL, &v8) == -1
|| (v8.sa_handler = (__sighandler_t)cvsync_signal,
v8.sa_flags &= 0xEFFFFFFF,
v0 = sigaction(15, &v8, 0LL),
result = 1LL,
v0 == -1) )
{
v6 = _errno_location();
v7 = strerror(*v6);
logmsg_err("sigaction: %s", v7);
result = 0LL;
}
}
return result;
}

original_code:
_Bool
cvsync_init(void)
{
 struct sigaction act;
 cvsync_sig_ign.__sigaction_handler.sa_handler = cvsync_signal;
 if (sigemptyset(&cvsync_sig_ign.sa_mask) == -1) {
  logmsg_err("sigemptyset: %s", strerror((*__errno_location ())));
  return (0);
 }
 cvsync_sig_ign.sa_flags = 0;
 if (sigaction(1, &cvsync_sig_ign, ((void *)0)) == -1) {
  logmsg_err("sigaction: %s", strerror((*__errno_location ())));
  return (0);
 }
 if (sigaction(13, &cvsync_sig_ign, ((void *)0)) == -1) {
  logmsg_err("sigaction: %s", strerror((*__errno_location ())));
  return (0);
 }
 if (sigaction(2, ((void *)0), &act) == -1) {
  logmsg_err("sigaction: %s", strerror((*__errno_location ())));
  return (0);
 }
 act.__sigaction_handler.sa_handler = cvsync_signal;
 act.sa_flags &= ~0x10000000;
 if (sigaction(2, &act, ((void *)0)) == -1) {
  logmsg_err("sigaction: %s", strerror((*__errno_location ())));
  return (0);
 }
 if (sigaction(15, ((void *)0), &act) == -1) {
  logmsg_err("sigaction: %s", strerror((*__errno_location ())));
  return (0);
 }
 act.__sigaction_handler.sa_handler = cvsync_signal;
 act.sa_flags &= ~0x10000000;
 if (sigaction(15, &act, ((void *)0)) == -1) {
  logmsg_err("sigaction: %s", strerror((*__errno_location ())));
  return (0);
 }
 return (1);
}

canonical_original_code:
_Bool cvsync_init()
{
 struct sigaction act;
 cvsync_sig_ign.__sigaction_handler.sa_handler = cvsync_signal;
 if (sigemptyset(&cvsync_sig_ign.sa_mask) == -1) {
  logmsg_err("sigemptyset: %s", strerror((*__errno_location ())));
  return (0);
 }
 cvsync_sig_ign.sa_flags = 0;
 if (sigaction(1, &cvsync_sig_ign, ((void *)0)) == -1) {
  logmsg_err("sigaction: %s", strerror((*__errno_location ())));
  return (0);
 }
 if (sigaction(13, &cvsync_sig_ign, ((void *)0)) == -1) {
  logmsg_err("sigaction: %s", strerror((*__errno_location ())));
  return (0);
 }
 if (sigaction(2, ((void *)0), &act) == -1) {
  logmsg_err("sigaction: %s", strerror((*__errno_location ())));
  return (0);
 }
 act.__sigaction_handler.sa_handler = cvsync_signal;
 act.sa_flags &= ~0x10000000;
 if (sigaction(2, &act, ((void *)0)) == -1) {
  logmsg_err("sigaction: %s", strerror((*__errno_location ())));
  return (0);
 }
 if (sigaction(15, ((void *)0), &act) == -1) {
  logmsg_err("sigaction: %s", strerror((*__errno_location ())));
  return (0);
 }
 act.__sigaction_handler.sa_handler = cvsync_signal;
 act.sa_flags &= ~0x10000000;
 if (sigaction(15, &act, ((void *)0)) == -1) {
  logmsg_err("sigaction: %s", strerror((*__errno_location ())));
  return (0);
 }
 return (1);
}

variable_types: struct sigaction { union { void (*sa_handler)(int); void (*sa_sigaction)(int, struct siginfo_t { int si_signo; int si_errno; int si_code; int __pad0; union { int _pad[-1]; struct { int si_pid; unsigned int si_uid; } _kill; struct { int si_tid; int si_overrun; union sigval { int sival_int; void *sival_ptr; } si_sigval; } _timer; struct { int si_pid; unsigned int si_uid; union sigval si_sigval; } _rt; struct { int si_pid; unsigned int si_uid; int si_status; long si_utime; long si_stime; } _sigchld; struct { void *si_addr; short si_addr_lsb; union { struct { void *_lower; void *_upper; } _addr_bnd; unsigned int _pkey; } _bounds; } _sigfault; struct { long si_band; int si_fd; } _sigpoll; struct { void *_call_addr; int _syscall; unsigned int _arch; } _sigsys; } _sifields; } *, void *); } __sigaction_handler; struct __sigset_t { unsigned long __val[-1]; } sa_mask; int sa_flags; void (*sa_restorer)(); }

user_defined_types: struct sigaction { union { void (*sa_handler)(int); void (*sa_sigaction)(int, struct siginfo_t *, void *); } __sigaction_handler; struct __sigset_t sa_mask; int sa_flags; void (*sa_restorer)(); }

user_defined_types: struct siginfo_t { int si_signo; int si_errno; int si_code; int __pad0; union { int _pad[-1]; struct { int si_pid; unsigned int si_uid; } _kill; struct { int si_tid; int si_overrun; union sigval si_sigval; } _timer; struct { int si_pid; unsigned int si_uid; union sigval si_sigval; } _rt; struct { int si_pid; unsigned int si_uid; int si_status; long si_utime; long si_stime; } _sigchld; struct { void *si_addr; short si_addr_lsb; union { struct { void *_lower; void *_upper; } _addr_bnd; unsigned int _pkey; } _bounds; } _sigfault; struct { long si_band; int si_fd; } _sigpoll; struct { void *_call_addr; int _syscall; unsigned int _arch; } _sigsys; } _sifields; }


repo: cvsync/cvsync

decompiled_code:
__int64 __fastcall cvsync_compress_pton(char *s2)
{
char **v2; // rbx
const char *v3; // rdi

v2 = &cvsync_compress_types;
v3 = "none";
while ( strcasecmp(v3, s2) )
{
v2 += 2;
v3 = *v2;
if ( !*v2 )
return 0LL;
}
return *((unsigned int *)v2 + 2);
}

canonical_decompiled_code:
__int64 __fastcall func2(char *s2)
{
char **v2; // rbx
const char *v3; // rdi

v2 = &cvsync_compress_types;
v3 = "none";
while ( strcasecmp(v3, s2) )
{
v2 += 2;
v3 = *v2;
if ( !*v2 )
return 0LL;
}
return *((unsigned int *)v2 + 2);
}

original_code:
int
cvsync_compress_pton(const char *name)
{
 const struct cvsync_token_type *t;
 for (t = cvsync_compress_types ; t->name != ((void *)0) ; t++) {
  if (strcasecmp(t->name, name) == 0)
   return (t->type);
 }
 return (CVSYNC_COMPRESS_UNSPEC);
}

canonical_original_code:
int cvsync_compress_pton(char *name)
{
 struct cvsync_token_type *t;
 for (t = cvsync_compress_types ; t->name != ((void *)0) ; t++) {
  if (strcasecmp(t->name, name) == 0)
   return (t->type);
 }
 return (CVSYNC_COMPRESS_UNSPEC);
}

variable_types:
name
char *

variable_types: struct cvsync_token_type { char *name; int type; } *

return_type: int


decompiled_code:
const char *__fastcall cvsync_compress_ntop(int a1)
{
char **v1; // rax
const char *v2; // rdx

v1 = &cvsync_compress_types;
v2 = "none";
while ( *((_DWORD *)v1 + 2) != a1 )
{
v1 += 2;
v2 = *v1;
if ( !*v1 )
return "unspecified";
}
return v2;
}

canonical_decompiled_code:
const char *__fastcall func3(int a1)
{
char **v1; // rax
const char *v2; // rdx

v1 = &cvsync_compress_types;
v2 = "none";
while ( *((_DWORD *)v1 + 2) != a1 )
{
v1 += 2;
v2 = *v1;
if ( !*v1 )
return "unspecified";
}
return v2;
}

original_code:
const char *
cvsync_compress_ntop(int type)
{
 const struct cvsync_token_type *t;
 for (t = cvsync_compress_types ; t->name != ((void *)0) ; t++) {
  if (t->type == type)
   return (t->name);
 }
 return ("unspecified");
}

canonical_original_code:
char *cvsync_compress_ntop(int type)
{
 struct cvsync_token_type *t;
 for (t = cvsync_compress_types ; t->name != ((void *)0) ; t++) {
  if (t->type == type)
   return (t->name);
 }
 return ("unspecified");
}

variable_types: type int

return_type: char *

user_defined_types: struct cvsync_token_type { char *name; int type; }


decompiled_code:
__int64 __fastcall cvsync_list_pton(char *s2)
{
char **v2; // rbx
const char *v3; // rdi

v2 = &cvsync_list_types;
v3 = "all";
while ( strcasecmp(v3, s2) )
{
v2 += 2;
v3 = *v2;
if ( !*v2 )
return 0LL;
}
return *((unsigned int *)v2 + 2);
}

canonical_decompiled_code:
__int64 __fastcall func4(char *s2)
{
char **v2; // rbx
const char *v3; // rdi

v2 = &cvsync_list_types;
v3 = "all";
while ( strcasecmp(v3, s2) )
{
v2 += 2;
v3 = *v2;
if ( !*v2 )
return 0LL;
}
return *((unsigned int *)v2 + 2);
}

original_code:
int
cvsync_list_pton(const char *name)
{
 const struct cvsync_token_type *t;
 for (t = cvsync_list_types ; t->name != ((void *)0) ; t++) {
  if (strcasecmp(t->name, name) == 0)
   return (t->type);
 }
 return (CVSYNC_LIST_UNKNOWN);
}

canonical_original_code:
int cvsync_list_pton(char *name)
{
 struct cvsync_token_type *t;
 for (t = cvsync_list_types ; t->name != ((void *)0) ; t++) {
  if (strcasecmp(t->name, name) == 0)
   return (t->type);
 }
 return (CVSYNC_LIST_UNKNOWN);
}


decompiled_code:
const char *__fastcall cvsync_list_ntop(int a1)
{
char **v1; // rax
const char *v2; // rdx

v1 = &cvsync_list_types;
v2 = "all";
while ( *((_DWORD *)v1 + 2) != a1 )
{
v1 += 2;
v2 = *v1;
if ( !*v1 )
return "unknown";
}
return v2;
}

canonical_decompiled_code:
const char *__fastcall func5(int a1)
{
char **v1; // rax
const char *v2; // rdx

v1 = &cvsync_list_types;
v2 = "all";
while ( *((_DWORD *)v1 + 2) != a1 )
{
v1 += 2;
v2 = *v1;
if ( !*v1 )
return "unknown";
}
return v2;
}

original_code:
const char *
cvsync_list_ntop(int type)
{
 const struct cvsync_token_type *t;
 for (t = cvsync_list_types ; t->name != ((void *)0) ; t++) {
  if (t->type == type)
   return (t->name);
 }
 return ("unknown");
}

canonical_original_code:
char *cvsync_list_ntop(int type)
{
 struct cvsync_token_type *t;
 for (t = cvsync_list_types ; t->name != ((void *)0) ; t++) {
  if (t->type == type)
   return (t->name);
 }
 return ("unknown");
}


decompiled_code:
__int64 __fastcall cvsync_release_pton(char *s2)
{
char **v2; // rbx
const char *v3; // rdi

v2 = &cvsync_release_types;
v3 = "list";
while ( strcasecmp(v3, s2) )
{
v2 += 2;
v3 = *v2;
if ( !*v2 )
return 0LL;
}
return *((unsigned int *)v2 + 2);
}

canonical_decompiled_code:
__int64 __fastcall func6(char *s2)
{
char **v2; // rbx
const char *v3; // rdi

v2 = &cvsync_release_types;
v3 = "list";
while ( strcasecmp(v3, s2) )
{
v2 += 2;
v3 = *v2;
if ( !*v2 )
return 0LL;
}
return *((unsigned int *)v2 + 2);
}

original_code:
int
cvsync_release_pton(const char *name)
{
 const struct cvsync_token_type *t;
 for (t = cvsync_release_types ; t->name != ((void *)0) ; t++) {
  if (strcasecmp(t->name, name) == 0)
   return (t->type);
 }
 return (CVSYNC_RELEASE_UNKNOWN);
}

canonical_original_code:
int cvsync_release_pton(char *name)
{
 struct cvsync_token_type *t;
 for (t = cvsync_release_types ; t->name != ((void *)0) ; t++) {
  if (strcasecmp(t->name, name) == 0)
   return (t->type);
 }
 return (CVSYNC_RELEASE_UNKNOWN);
}


decompiled_code:
const char *__fastcall cvsync_release_ntop(int a1)
{
char **v1; // rax
const char *v2; // rdx

v1 = &cvsync_release_types;
v2 = "list";
while ( *((_DWORD *)v1 + 2) != a1 )
{
v1 += 2;
v2 = *v1;
if ( !*v1 )
return "unknown";
}
return v2;
}

canonical_decompiled_code:
const char *__fastcall func7(int a1)
{
char **v1; // rax
const char *v2; // rdx

v1 = &cvsync_release_types;
v2 = "list";
while ( *((_DWORD *)v1 + 2) != a1 )
{
v1 += 2;
v2 = *v1;
if ( !*v1 )
return "unknown";
}
return v2;
}

original_code:
const char *
cvsync_release_ntop(int type)
{
 const struct cvsync_token_type *t;
 for (t = cvsync_release_types ; t->name != ((void *)0) ; t++) {
  if (t->type == type)
   return (t->name);
 }
 return ("unknown");
}

canonical_original_code:
char *cvsync_release_ntop(int type)
{
 struct cvsync_token_type *t;
 for (t = cvsync_release_types ; t->name != ((void *)0) ; t++) {
  if (t->type == type)
   return (t->name);
 }
 return ("unknown");
}


decompiled_code:
void *__fastcall cvsync_memdup(void *src, size_t n)
{
void *v2; // rax
void *v3; // rbx
int *v5; // rax
char *v6; // rax

v2 = malloc(n);
v3 = v2;
if ( v2 )
{
memcpy(v2, src, n);
}
else
{
v5 = _errno_location();
v6 = strerror(*v5);
logmsg_err("%s", v6);
}
return v3;
}

canonical_decompiled_code:
void *__fastcall func8(void *src, size_t n)
{
void *v2; // rax
void *v3; // rbx
int *v5; // rax
char *v6; // rax

v2 = malloc(n);
v3 = v2;
if ( v2 )
{
memcpy(v2, src, n);
}
else
{
v5 = _errno_location();
v6 = strerror(*v5);
logmsg_err("%s", v6);
}
return v3;
}

original_code:
void *
cvsync_memdup(void *ptr, size_t size)
{
 void *newptr;
 if ((newptr = malloc(size)) == ((void *)0)) {
  logmsg_err("%s", strerror((*__errno_location ())));
  return (((void *)0));
 }
 (void)memcpy(newptr, ptr, size);
 return (newptr);
}

canonical_original_code:
void *cvsync_memdup(void *ptr, unsigned long size)
{
 void *newptr;
 if ((newptr = malloc(size)) == ((void *)0)) {
  logmsg_err("%s", strerror((*__errno_location ())));
  return (((void *)0));
 }
 (void)memcpy(newptr, ptr, size);
 return (newptr);
}

variable_types:
ptr
void *

variable_types:
size
unsigned long

variable_types:
newptr
void *

return_type: void *


decompiled_code:
__int64 __fastcall cvsync_cmp_pathname(char *a1, __int64 a2, char *a3, __int64 a4)
{
char *v4; // r9
char *v5; // r10
char v6; // al
char v7; // r8
__int64 result; // rax

v4 = &a1[a2];
v5 = &a3[a4];
if ( a1 >= &a1[a2] || a3 >= v5 )
return (unsigned int)(a2 - a4);
while ( 1 )
{
v6 = *a1;
v7 = *a3;
if ( *a1 != *a3 )
break;
++a1;
++a3;
if ( v4 <= a1 || v5 <= a3 )
return (unsigned int)(a2 - a4);
}
if ( v6 == 47 )
return 0xFFFFFFFFLL;
if ( v6 >= v7 || (result = 0xFFFFFFFFLL, v7 == 47) )
result = 1LL;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func9(char *a1, __int64 a2, char *a3, __int64 a4)
{
char *v4; // r9
char *v5; // r10
char v6; // al
char v7; // r8
__int64 result; // rax

v4 = &a1[a2];
v5 = &a3[a4];
if ( a1 >= &a1[a2] || a3 >= v5 )
return (unsigned int)(a2 - a4);
while ( 1 )
{
v6 = *a1;
v7 = *a3;
if ( *a1 != *a3 )
break;
++a1;
++a3;
if ( v4 <= a1 || v5 <= a3 )
return (unsigned int)(a2 - a4);
}
if ( v6 == 47 )
return 0xFFFFFFFFLL;
if ( v6 >= v7 || (result = 0xFFFFFFFFLL, v7 == 47) )
result = 1LL;
return result;
}

original_code:
int
cvsync_cmp_pathname(const char *n1, size_t nlen1, const char *n2, size_t nlen2)
{
 const char *bp1 = n1 + nlen1, *bp2 = n2 + nlen2;
 while ((n1 < bp1) && (n2 < bp2)) {
  if (*n1 == *n2) {
   n1++;
   n2++;
   continue;
  }
  if (*n1 == '/')
   return (-1);
  if (*n2 == '/')
   return (1);
  if (*n1 < *n2)
   return (-1);
  else
   return (1);
 }
 return ((int)(nlen1 - nlen2));
}

canonical_original_code:
int cvsync_cmp_pathname(char *n1, unsigned long nlen1, char *n2, unsigned long nlen2)
{
 char *bp1 = n1 + nlen1; char *bp2 = n2 + nlen2;
 while ((n1 < bp1) && (n2 < bp2)) {
  if (*n1 == *n2) {
   n1++;
   n2++;
   continue;
  }
  if (*n1 == '/')
   return (-1);
  if (*n2 == '/')
   return (1);
  if (*n1 < *n2)
   return (-1);
  else
   return (1);
 }
 return ((int)(nlen1 - nlen2));
}


decompiled_code:
__int64 __fastcall cvsync_fclose(void *ptr)
{
void *v2; // rdi
__int64 result; // rax
int *v4; // rax
char *v5; // rax
int *v6; // rax
char *v7; // rax

v2 = (void *)*((_QWORD *)ptr + 4);
if ( v2 && munmap(v2, *((_QWORD *)ptr + 5)) == -1 )
{
v4 = _errno_location();
v5 = strerror(*v4);
logmsg_err("%s", v5);
close(*(_DWORD *)ptr);
free(ptr);
result = 0LL;
}
else if ( close(*(_DWORD *)ptr) == -1 )
{
v6 = _errno_location();
v7 = strerror(*v6);
logmsg_err("%s", v7);
free(ptr);
result = 0LL;
}
else
{
free(ptr);
result = 1LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func10(void *ptr)
{
void *v2; // rdi
__int64 result; // rax
int *v4; // rax
char *v5; // rax
int *v6; // rax
char *v7; // rax

v2 = (void *)*((_QWORD *)ptr + 4);
if ( v2 && munmap(v2, *((_QWORD *)ptr + 5)) == -1 )
{
v4 = _errno_location();
v5 = strerror(*v4);
logmsg_err("%s", v5);
close(*(_DWORD *)ptr);
free(ptr);
result = 0LL;
}
else if ( close(*(_DWORD *)ptr) == -1 )
{
v6 = _errno_location();
v7 = strerror(*v6);
logmsg_err("%s", v7);
free(ptr);
result = 0LL;
}
else
{
free(ptr);
result = 1LL;
}
return result;
}

original_code:
_Bool
cvsync_fclose(struct cvsync_file *cfp)
{
 if (cfp->cf_addr != ((void *)0)) {
  if (munmap(cfp->cf_addr, cfp->cf_msize) == -1) {
   logmsg_err("%s", strerror((*__errno_location ())));
   (void)close(cfp->cf_fileno);
   free(cfp);
   return (0);
  }
 }
 if (close(cfp->cf_fileno) == -1) {
  logmsg_err("%s", strerror((*__errno_location ())));
  free(cfp);
  return (0);
 }
 free(cfp);
 return (1);
}

variable_types: struct cvsync_file { int cf_fileno; long cf_size; long cf_mtime; unsigned int cf_mode; void *cf_addr; unsigned long cf_msize; } *


decompiled_code:
__int64 __fastcall cvsync_mmap(__int64 a1, __off_t a2, size_t a3)
{
unsigned int v3; // edx
void *v5; // rax
int *v6; // rax
char *v7; // rax

*(_QWORD *)(a1 + 40) = a3;
if ( a3 )
{
v5 = mmap(0LL, a3, 1, 2, *(_DWORD *)a1, a2);
*(_QWORD *)(a1 + 32) = v5;
v3 = 1;
if ( v5 == (void *)-1LL )
{
v6 = _errno_location();
v7 = strerror(*v6);
logmsg_err("%s", v7);
v3 = 0;
}
}
else
{
*(_QWORD *)(a1 + 32) = 0LL;
v3 = 1;
}
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func11(__int64 a1, __off_t a2, size_t a3)
{
unsigned int v3; // edx
void *v5; // rax
int *v6; // rax
char *v7; // rax

*(_QWORD *)(a1 + 40) = a3;
if ( a3 )
{
v5 = mmap(0LL, a3, 1, 2, *(_DWORD *)a1, a2);
*(_QWORD *)(a1 + 32) = v5;
v3 = 1;
if ( v5 == (void *)-1LL )
{
v6 = _errno_location();
v7 = strerror(*v6);
logmsg_err("%s", v7);
v3 = 0;
}
}
else
{
*(_QWORD *)(a1 + 32) = 0LL;
v3 = 1;
}
return v3;
}

original_code:
_Bool
cvsync_mmap(struct cvsync_file *cfp, off_t offset, off_t size)
{
 uint64_t size64 = (uint64_t)size;
 if (size64 > (18446744073709551615UL)) {
  logmsg_err("%" "l" "u" ": %s", size64, strerror(34));
  return (0);
 }
 if ((cfp->cf_msize = (size_t)size) == 0) {
  cfp->cf_addr = ((void *)0);
  return (1);
 }
 if ((cfp->cf_addr = mmap(((void *)0), cfp->cf_msize, 0x1, 0x02,
     cfp->cf_fileno, offset)) == ((void *) -1)) {
  logmsg_err("%s", strerror((*__errno_location ())));
  return (0);
 }
 return (1);
}

canonical_original_code:
_Bool cvsync_mmap(struct cvsync_file *cfp, long offset, long size)
{
 unsigned long size64 = (uint64_t)size;
 if (size64 > (18446744073709551615UL)) {
  logmsg_err("%" "l" "u" ": %s", size64, strerror(34));
  return (0);
 }
 if ((cfp->cf_msize = (unsigned long)size) == 0) {
  cfp->cf_addr = ((void *)0);
  return (1);
 }
 if ((cfp->cf_addr = mmap(((void *)0), cfp->cf_msize, 0x1, 0x02,
     cfp->cf_fileno, offset)) == ((void *) -1)) {
  logmsg_err("%s", strerror((*__errno_location ())));
  return (0);
 }
 return (1);
}

variable_types: offset long

variable_types: size long

user_defined_types: struct cvsync_file { int cf_fileno; long cf_size; long cf_mtime; unsigned int cf_mode; void *cf_addr; unsigned long cf_msize; }


decompiled_code:
__int64 __fastcall cvsync_munmap(__int64 a1)
{
void *v2; // rdi
__int64 result; // rax
int *v4; // rax
char *v5; // rax

v2 = *(void **)(a1 + 32);
result = 1LL;
if ( v2 )
{
if ( munmap(v2, *(_QWORD *)(a1 + 40)) == -1 )
{
v4 = _errno_location();
v5 = strerror(*v4);
logmsg_err("%s", v5);
result = 0LL;
}
else
{
*(_QWORD *)(a1 + 32) = 0LL;
*(_QWORD *)(a1 + 40) = 0LL;
result = 1LL;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func12(__int64 a1)
{
void *v2; // rdi
__int64 result; // rax
int *v4; // rax
char *v5; // rax

v2 = *(void **)(a1 + 32);
result = 1LL;
if ( v2 )
{
if ( munmap(v2, *(_QWORD *)(a1 + 40)) == -1 )
{
v4 = _errno_location();
v5 = strerror(*v4);
logmsg_err("%s", v5);
result = 0LL;
}
else
{
*(_QWORD *)(a1 + 32) = 0LL;
*(_QWORD *)(a1 + 40) = 0LL;
result = 1LL;
}
}
return result;
}

original_code:
_Bool
cvsync_munmap(struct cvsync_file *cfp)
{
 if (cfp->cf_addr != ((void *)0)) {
  if (munmap(cfp->cf_addr, cfp->cf_msize) == -1) {
   logmsg_err("%s", strerror((*__errno_location ())));
   return (0);
  }
  cfp->cf_addr = ((void *)0);
  cfp->cf_msize = 0;
 }
 return (1);
}


original_code:
_Bool
cvsync_rcs_append_attic(char *path, size_t pathlen, size_t pathmax)
{
 size_t len;
 if ((len = pathlen + _atticlen + 1) >= pathmax)
  return (0);
 path[pathlen] = '/';
 (void)memcpy(&path[pathlen + 1], _attic, _atticlen);
 path[len] = '\0';
 return (1);
}

canonical_original_code:
_Bool cvsync_rcs_append_attic(char *path, unsigned long pathlen, unsigned long pathmax)
{
 unsigned long len;
 if ((len = pathlen + _atticlen + 1) >= pathmax)
  return (0);
 path[pathlen] = '/';
 (void)memcpy(&path[pathlen + 1], _attic, _atticlen);
 path[len] = '\0';
 return (1);
}

variable_types:
path
char *

variable_types:
pathlen
unsigned long

variable_types:
pathmax
unsigned long

variable_types:
len
unsigned long


original_code:
_Bool
cvsync_rcs_insert_attic(char *path, size_t pathlen, size_t pathmax)
{
 char *rpath;
 size_t len;
 if ((len = pathlen + _atticlen) >= pathmax)
  return (0);
 rpath = &path[pathlen - 1];
 if (*rpath == '/')
  return (0);
 while (rpath > path) {
  if (*rpath == '/') {
   rpath++;
   break;
  }
  rpath--;
 }
 len = pathlen - (size_t)(rpath - path);
 (void)memmove(&rpath[_atticlen], rpath, len + 1);
 (void)memcpy(rpath, _attic, _atticlen);
 return (1);
}

canonical_original_code:
_Bool cvsync_rcs_insert_attic(char *path, unsigned long pathlen, unsigned long pathmax)
{
 char *rpath;
 unsigned long len;
 if ((len = pathlen + _atticlen) >= pathmax)
  return (0);
 rpath = &path[pathlen - 1];
 if (*rpath == '/')
  return (0);
 while (rpath > path) {
  if (*rpath == '/') {
   rpath++;
   break;
  }
  rpath--;
 }
 len = pathlen - (unsigned long)(rpath - path);
 (void)memmove(&rpath[_atticlen], rpath, len + 1);
 (void)memcpy(rpath, _attic, _atticlen);
 return (1);
}

variable_types:
rpath
char *


original_code:
_Bool
cvsync_rcs_remove_attic(char *path, size_t pathlen)
{
 char *rpath, *sp = ((void *)0);
 size_t len;
 rpath = &path[pathlen - 1];
 if (*rpath == '/')
  return (0);
 while (rpath > path) {
  if (*rpath == '/') {
   sp = rpath + 1;
   break;
  }
  rpath--;
 }
 if (sp == ((void *)0))
  return (0);
 len = pathlen - (size_t)(sp - path);
 for (rpath-- ; rpath > path ; rpath--) {
  if (*rpath == '/') {
   rpath++;
   break;
  }
 }
 if (!(((sp - rpath - 1) == 5) && ((rpath)[0] == 'A') && ((rpath)[1] == 't') && ((rpath)[2] == 't') && ((rpath)[3] == 'i') && ((rpath)[4] == 'c')))
  return (0);
 (void)memmove(rpath, sp, len + 1);
 return (1);
}

canonical_original_code:
_Bool cvsync_rcs_remove_attic(char *path, unsigned long pathlen)
{
 char *rpath; char *sp = ((void *)0);
 unsigned long len;
 rpath = &path[pathlen - 1];
 if (*rpath == '/')
  return (0);
 while (rpath > path) {
  if (*rpath == '/') {
   sp = rpath + 1;
   break;
  }
  rpath--;
 }
 if (sp == ((void *)0))
  return (0);
 len = pathlen - (unsigned long)(sp - path);
 for (rpath-- ; rpath > path ; rpath--) {
  if (*rpath == '/') {
   rpath++;
   break;
  }
 }
 if (!(((sp - rpath - 1) == 5) && ((rpath)[0] == 'A') && ((rpath)[1] == 't') && ((rpath)[2] == 't') && ((rpath)[3] == 'i') && ((rpath)[4] == 'c')))
  return (0);
 (void)memmove(rpath, sp, len + 1);
 return (1);
}

variable_types:
sp
char *


decompiled_code:
bool __fastcall cvsync_rcs_filename(_BYTE *a1, __int64 a2)
{
_BYTE *v2; // rax
bool result; // al

if ( !a2 )
return 1;
v2 = a1;
do
{
if ( *v2 == 47 )
return 0;
++v2;
}
while ( v2 != &a1[a2] );
switch ( a2 )
{
case 1LL:
return *a1 != 46;
case 2LL:
result = 1;
if ( *a1 == 46 )
result = a1[1] != 46;
break;
case 14LL:
result = 1;
if ( *a1 == 46 && a1[1] == 99 && a1[2] == 118 && a1[3] == 115 && a1[4] == 121 && a1[5] == 110 && a1[6] == 99 )
result = a1[7] != 46;
break;
default:
result = 1;
break;
}
return result;
}

variable_types:
namelen
unsigned long

variable_types:
i
unsigned long


decompiled_code:
__int64 __fastcall cvsync_rcs_pathname(_BYTE *a1, unsigned __int64 a2)
{
__int64 result; // rax
unsigned __int64 i; // rax
unsigned __int64 v4; // rax

result = 0LL;
if ( a2 && *a1 != 47 && a1[a2 - 1] != 47 )
{
for ( i = 0LL; ; i = 0LL )
{
do
{
if ( a1[i] == 47 )
break;
++i;
}
while ( i < a2 );
switch ( i )
{
case 0uLL:
return 0LL;
case 1uLL:
if ( *a1 == 46 )
return 0LL;
break;
case 2uLL:
if ( *a1 == 46 && a1[1] == 46 )
return 0LL;
break;
default:
if ( i == 14
&& *a1 == 46
&& a1[1] == 99
&& a1[2] == 118
&& a1[3] == 115
&& a1[4] == 121
&& a1[5] == 110
&& a1[6] == 99
&& a1[7] == 46 )
{
return 0LL;
}
break;
}
if ( i == a2 )
return 1LL;
v4 = i + 1;
a1 += v4;
a2 -= v4;
if ( !a2 )
return 0LL;
}
}
return result;
}


decompiled_code:
bool __fastcall cvsync2cvsup_isparent(__int64 a1, __int64 a2)
{
size_t v2; // rdx
bool result; // al
const void *v4; // rsi

v2 = *(_QWORD *)(a1 + 24);
result = 0;
if ( v2 < *(_QWORD *)(a2 + 24) )
{
v4 = *(const void **)(a2 + 16);
if ( *((_BYTE *)v4 + v2) == 47 )
result = memcmp(*(const void **)(a1 + 16), v4, v2) == 0;
}
return result;
}

canonical_decompiled_code:
bool __fastcall func0(__int64 a1, __int64 a2)
{
size_t v2; // rdx
bool result; // al
const void *v4; // rsi

v2 = *(_QWORD *)(a1 + 24);
result = 0;
if ( v2 < *(_QWORD *)(a2 + 24) )
{
v4 = *(const void **)(a2 + 16);
if ( *((_BYTE *)v4 + v2) == 47 )
result = memcmp(*(const void **)(a1 + 16), v4, v2) == 0;
}
return result;
}

original_code:
_Bool
cvsync2cvsup_isparent(struct scanfile_attr *attr1, struct scanfile_attr *attr2)
{
 uint8_t *name2 = (uint8_t *)attr2->a_name;
 if ((attr1->a_namelen < attr2->a_namelen) &&
     (name2[attr1->a_namelen] == '/') &&
     (memcmp(attr1->a_name, name2, attr1->a_namelen) == 0)) {
  return (1);
 }
 return (0);
}

canonical_original_code:
_Bool cvsync2cvsup_isparent(struct scanfile_attr *attr1, struct scanfile_attr *attr2)
{
 unsigned char *name2 = (uint8_t *)attr2->a_name;
 if ((attr1->a_namelen < attr2->a_namelen) &&
     (name2[attr1->a_namelen] == '/') &&
     (memcmp(attr1->a_name, name2, attr1->a_namelen) == 0)) {
  return (1);
 }
 return (0);
}

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


decompiled_code:
__int64 __fastcall cvsync2cvsup_insert_attr(__int64 a1, const __m128i *a2)
{
__m128i *v2; // rax
__m128i *v3; // rbx
unsigned int v4; // ebp
int *v6; // rax
char *v7; // rax

v2 = (__m128i *)malloc(0x30uLL);
if ( v2 )
{
v3 = v2;
*v2 = _mm_loadu_si128(a2);
v2[1] = _mm_loadu_si128(a2 + 1);
v2[2] = _mm_loadu_si128(a2 + 2);
v4 = list_insert_tail(*(_QWORD *)(a1 + 4392), v2);
if ( !(_BYTE)v4 )
free(v3);
}
else
{
v6 = _errno_location();
v7 = strerror(*v6);
logmsg_err(&unk_89C, v7);
v4 = 0;
}
return v4;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, const __m128i *a2)
{
__m128i *v2; // rax
__m128i *v3; // rbx
unsigned int v4; // ebp
int *v6; // rax
char *v7; // rax

v2 = (__m128i *)malloc(0x30uLL);
if ( v2 )
{
v3 = v2;
*v2 = _mm_loadu_si128(a2);
v2[1] = _mm_loadu_si128(a2 + 1);
v2[2] = _mm_loadu_si128(a2 + 2);
v4 = list_insert_tail(*(_QWORD *)(a1 + 4392), v2);
if ( !(_BYTE)v4 )
free(v3);
}
else
{
v6 = _errno_location();
v7 = strerror(*v6);
logmsg_err(&unk_89C, v7);
v4 = 0;
}
return v4;
}

original_code:
_Bool
cvsync2cvsup_insert_attr(struct scanfile_args *sa, struct scanfile_attr *attr)
{
 struct scanfile_attr *new_attr;
 if ((new_attr = malloc(sizeof(*new_attr))) == ((void *)0)) {
  logmsg_err("%s", strerror((*__errno_location ())));
  return (0);
 }
 (void)memcpy(new_attr, attr, sizeof(*new_attr));
 if (!list_insert_tail(sa->sa_dirlist, new_attr)) {
  free(new_attr);
  return (0);
 }
 return (1);
}

variable_types: struct scanfile_args { struct cvsync_file { int cf_fileno; long cf_size; long cf_mtime; unsigned int cf_mode; void *cf_addr; unsigned long cf_msize; } *sa_scanfile; char *sa_scanfile_name; unsigned char *sa_start; int sa_tmp; char sa_tmp_name[-1]; unsigned int sa_tmp_mode; struct list { struct listent { struct listent *le_next; void *le_elm; int le_state; } *l_entries; void (*l_destructor)(void *); } *sa_dirlist; 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; } sa_attr; _Bool sa_changed; } *

variable_types:
attr
struct scanfile_attr *

user_defined_types: struct scanfile_args { struct cvsync_file *sa_scanfile; char *sa_scanfile_name; unsigned char *sa_start; int sa_tmp; char sa_tmp_name[-1]; unsigned int sa_tmp_mode; struct list *sa_dirlist; struct scanfile_attr sa_attr; _Bool sa_changed; }

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


original_code:
void
cvsync2cvsup_remove_attr(struct scanfile_args *sa, struct scanfile_attr *attr)
{
 struct scanfile_attr *new_attr;
 if ((new_attr = list_remove_tail(sa->sa_dirlist)) == ((void *)0)) {
  (void)memset(attr, 0, sizeof(*attr));
 } else {
  (void)memcpy(attr, new_attr, sizeof(*attr));
  free(new_attr);
 }
}

return_type: void

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

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


decompiled_code:
__int64 __fastcall cvsync2cvsup_chdir(__int64 a1, __m128i *a2, const __m128i *a3)
{
unsigned int v4; // ebx
unsigned int v6; // eax
unsigned int v7; // eax

if ( a2->m128i_i8[8] == 68 )
{
LOBYTE(v6) = cvsync2cvsup_isparent((__int64)a2, (__int64)a3);
v4 = v6;
if ( (_BYTE)v6 )
{
if ( a3->m128i_i8[8] == 68 )
{
v4 = cvsync2cvsup_insert_attr(a1, a2);
if ( (_BYTE)v4 )
{
LABEL_8:
*a2 = _mm_loadu_si128(a3);
a2[1] = _mm_loadu_si128(a3 + 1);
a2[2] = _mm_loadu_si128(a3 + 2);
v4 = cvsup_write_dirdown(*(unsigned int *)(a1 + 32), a2);
}
}
}
else if ( a3->m128i_i8[8] == 68 )
{
while ( 1 )
{
v4 = cvsup_write_dirup(*(unsigned int *)(a1 + 32), a2);
if ( !(_BYTE)v4 )
break;
cvsync2cvsup_remove_attr(a1, a2);
if ( a2->m128i_i8[8] != 68 )
goto LABEL_8;
if ( cvsync2cvsup_isparent((__int64)a2, (__int64)a3) )
{
v4 = cvsync2cvsup_insert_attr(a1, a2);
if ( !(_BYTE)v4 )
return v4;
goto LABEL_8;
}
}
}
else
{
while ( 1 )
{
v4 = list_isempty(*(_QWORD *)(a1 + 4392));
if ( (_BYTE)v4 )
break;
v4 = cvsup_write_dirup(*(unsigned int *)(a1 + 32), a2);
if ( (_BYTE)v4 )
{
cvsync2cvsup_remove_attr(a1, a2);
if ( a2->m128i_i8[8] == 68 )
{
LOBYTE(v7) = cvsync2cvsup_isparent((__int64)a2, (__int64)a3);
v4 = v7;
if ( !(_BYTE)v7 )
continue;
}
}
return v4;
}
a2->m128i_i64[0] = 0LL;
a2->m128i_i64[1] = 0LL;
a2[1].m128i_i64[0] = 0LL;
a2[1].m128i_i64[1] = 0LL;
a2[2].m128i_i64[0] = 0LL;
a2[2].m128i_i64[1] = 0LL;
}
}
else
{
v4 = 1;
if ( a3->m128i_i8[8] == 68 )
{
*a2 = _mm_loadu_si128(a3);
a2[1] = _mm_loadu_si128(a3 + 1);
a2[2] = _mm_loadu_si128(a3 + 2);
v4 = cvsup_write_dirdown(*(unsigned int *)(a1 + 32), a2);
}
}
return v4;
}

original_code:
_Bool
cvsync2cvsup_chdir(struct scanfile_args *sa, struct scanfile_attr *dirattr,
     struct scanfile_attr *attr)
{
 if (dirattr->a_type != 'D') {
  if (attr->a_type == 'D') {
   (void)memcpy(dirattr, attr, sizeof(*dirattr));
   if (!cvsup_write_dirdown(sa->sa_tmp, dirattr))
    return (0);
  }
  return (1);
 }
 if (cvsync2cvsup_isparent(dirattr, attr)) {
  if (attr->a_type == 'D') {
   if (!cvsync2cvsup_insert_attr(sa, dirattr))
    return (0);
   (void)memcpy(dirattr, attr, sizeof(*dirattr));
   if (!cvsup_write_dirdown(sa->sa_tmp, dirattr))
    return (0);
  }
  return (1);
 }
 if (attr->a_type == 'D') {
  for (;;) {
   if (!cvsup_write_dirup(sa->sa_tmp, dirattr))
    return (0);
   cvsync2cvsup_remove_attr(sa, dirattr);
   if (dirattr->a_type != 'D')
    break;
   if (cvsync2cvsup_isparent(dirattr, attr)) {
    if (!cvsync2cvsup_insert_attr(sa, dirattr))
     return (0);
    break;
   }
  }
  (void)memcpy(dirattr, attr, sizeof(*dirattr));
  if (!cvsup_write_dirdown(sa->sa_tmp, dirattr))
   return (0);
  return (1);
 }
 for (;;) {
  if (list_isempty(sa->sa_dirlist)) {
   (void)memset(dirattr, 0, sizeof(*dirattr));
   break;
  }
  if (!cvsup_write_dirup(sa->sa_tmp, dirattr))
   return (0);
  cvsync2cvsup_remove_attr(sa, dirattr);
  if ((dirattr->a_type != 'D') ||
      cvsync2cvsup_isparent(dirattr, attr)) {
   break;
  }
 }
 return (1);
}

variable_types:
dirattr
struct scanfile_attr *


decompiled_code:
__int64 __fastcall cvsync2cvsup(__int64 a1, const char *a2)
{
unsigned int v3; // eax
unsigned int v4; // ebx
int v5; // edi
int *v7; // rax
unsigned __int64 v8; // rax
int v9; // er13
int *v10; // rax
char *v11; // rax
char v12[4352]; // [rsp+0h] [rbp-1218h] BYREF
struct stat v13; // [rsp+1100h] [rbp-118h] BYREF
__m128i v14; // [rsp+1190h] [rbp-88h] BYREF
__int64 v15; // [rsp+11A0h] [rbp-78h]
__int64 v16; // [rsp+11A8h] [rbp-70h]
__int64 v17; // [rsp+11B0h] [rbp-68h]
__int64 v18; // [rsp+11B8h] [rbp-60h]
__m128i v19[5]; // [rsp+11C0h] [rbp-58h] BYREF

if ( stat(a2, &v13) == -1 )
{
v5 = *_errno_location();
if ( v5 != 2 )
{
strerror(v5);
logmsg_err("%s: %s", a2);
return 0;
}
v13.st_mode = 420;
}
else
{
v13.st_mode = v13.st_mode & 0xFFF;
}
if ( (unsigned int)(snprintf(v12, 0x1100uLL, "%s.XXXXXX", a2) - 1) > 0x10FE )
{
strerror(22);
logmsg_err("%s: %s", a2);
return 0;
}
v3 = mkstemp(v12);
if ( v3 == -1 )
{
v7 = _errno_location();
strerror(*v7);
logmsg_err("%s: %s", a2);
return 0;
}
*(_DWORD *)(a1 + 32) = v3;
v4 = cvsup_write_header(v3, *(_QWORD *)(*(_QWORD *)a1 + 16LL));
if ( (_BYTE)v4 )
{
v14 = 0uLL;
v15 = 0LL;
v16 = 0LL;
v17 = 0LL;
v18 = 0LL;
if ( *(_QWORD *)(a1 + 16) >= *(_QWORD *)(a1 + 24) )
{
LABEL_7:
if ( v14.m128i_i8[8] != 68 || (v4 = cvsup_write_dirup(*(unsigned int *)(a1 + 32), &v14), (_BYTE)v4) )
{
while ( 1 )
{
v4 = list_isempty(*(_QWORD *)(a1 + 4392));
if ( (_BYTE)v4 )
break;
cvsync2cvsup_remove_attr(a1, &v14);
if ( v14.m128i_i8[8] == 68 )
{
v4 = cvsup_write_dirup(*(unsigned int *)(a1 + 32), &v14);
if ( (_BYTE)v4 )
continue;
}
return v4;
}
v9 = *(_DWORD *)(a1 + 32);
*(_DWORD *)(a1 + 32) = -1;
if ( fchmod(v9, v13.st_mode) == -1 || close(v9) == -1 || rename(v12, a2) == -1 )
{
v10 = _errno_location();
v11 = strerror(*v10);
logmsg_err("%s: %s", a2, v11);
unlink(v12);
v4 = 0;
}
else
{
logmsg("Finished successfully");
}
}
return v4;
}
while ( 1 )
{
if ( (unsigned __int8)cvsync_isinterrupted() )
{
logmsg_intr();
unlink(v12);
return 0;
}
v4 = scanfile_read_attr(*(_QWORD *)(a1 + 16), *(_QWORD *)(a1 + 24), v19);
if ( !(_BYTE)v4 || (v4 = cvsync2cvsup_chdir(a1, &v14, v19), !(_BYTE)v4) )
{
unlink(v12);
return v4;
}
if ( v19[0].m128i_i8[8] == 82 )
{
LABEL_23:
v4 = cvsup_write_rcs(*(unsigned int *)(a1 + 32), v19);
if ( !(_BYTE)v4 )
return v4;
goto LABEL_28;
}
if ( v19[0].m128i_i8[8] > 0x52u )
break;
if ( v19[0].m128i_i8[8] == 68 )
goto LABEL_28;
if ( v19[0].m128i_i8[8] != 70 )
goto LABEL_27;
v4 = cvsup_write_file(*(unsigned int *)(a1 + 32), v19);
if ( !(_BYTE)v4 )
return v4;
LABEL_28:
v8 = *(_QWORD *)(a1 + 16) + v19[0].m128i_i64[0];
*(_QWORD *)(a1 + 16) = v8;
if ( v8 >= *(_QWORD *)(a1 + 24) )
goto LABEL_7;
}
if ( v19[0].m128i_i8[8] == 83 )
{
v4 = cvsup_write_symlink(*(unsigned int *)(a1 + 32), v19);
if ( !(_BYTE)v4 )
return v4;
goto LABEL_28;
}
if ( v19[0].m128i_i8[8] == 114 )
goto LABEL_23;
LABEL_27:
logmsg_err("%c: Unknown attr type", &v14);
goto LABEL_28;
}
return v4;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1, const char *a2)
{
unsigned int v3; // eax
unsigned int v4; // ebx
int v5; // edi
int *v7; // rax
unsigned __int64 v8; // rax
int v9; // er13
int *v10; // rax
char *v11; // rax
char v12[4352]; // [rsp+0h] [rbp-1218h] BYREF
struct stat v13; // [rsp+1100h] [rbp-118h] BYREF
__m128i v14; // [rsp+1190h] [rbp-88h] BYREF
__int64 v15; // [rsp+11A0h] [rbp-78h]
__int64 v16; // [rsp+11A8h] [rbp-70h]
__int64 v17; // [rsp+11B0h] [rbp-68h]
__int64 v18; // [rsp+11B8h] [rbp-60h]
__m128i v19[5]; // [rsp+11C0h] [rbp-58h] BYREF

if ( stat(a2, &v13) == -1 )
{
v5 = *_errno_location();
if ( v5 != 2 )
{
strerror(v5);
logmsg_err("%s: %s", a2);
return 0;
}
v13.st_mode = 420;
}
else
{
v13.st_mode = v13.st_mode & 0xFFF;
}
if ( (unsigned int)(snprintf(v12, 0x1100uLL, "%s.XXXXXX", a2) - 1) > 0x10FE )
{
strerror(22);
logmsg_err("%s: %s", a2);
return 0;
}
v3 = mkstemp(v12);
if ( v3 == -1 )
{
v7 = _errno_location();
strerror(*v7);
logmsg_err("%s: %s", a2);
return 0;
}
*(_DWORD *)(a1 + 32) = v3;
v4 = cvsup_write_header(v3, *(_QWORD *)(*(_QWORD *)a1 + 16LL));
if ( (_BYTE)v4 )
{
v14 = 0uLL;
v15 = 0LL;
v16 = 0LL;
v17 = 0LL;
v18 = 0LL;
if ( *(_QWORD *)(a1 + 16) >= *(_QWORD *)(a1 + 24) )
{
LABEL_7:
if ( v14.m128i_i8[8] != 68 || (v4 = cvsup_write_dirup(*(unsigned int *)(a1 + 32), &v14), (_BYTE)v4) )
{
while ( 1 )
{
v4 = list_isempty(*(_QWORD *)(a1 + 4392));
if ( (_BYTE)v4 )
break;
func2(a1, &v14);
if ( v14.m128i_i8[8] == 68 )
{
v4 = cvsup_write_dirup(*(unsigned int *)(a1 + 32), &v14);
if ( (_BYTE)v4 )
continue;
}
return v4;
}
v9 = *(_DWORD *)(a1 + 32);
*(_DWORD *)(a1 + 32) = -1;
if ( fchmod(v9, v13.st_mode) == -1 || close(v9) == -1 || rename(v12, a2) == -1 )
{
v10 = _errno_location();
v11 = strerror(*v10);
logmsg_err("%s: %s", a2, v11);
unlink(v12);
v4 = 0;
}
else
{
logmsg("Finished successfully");
}
}
return v4;
}
while ( 1 )
{
if ( (unsigned __int8)cvsync_isinterrupted() )
{
logmsg_intr();
unlink(v12);
return 0;
}
v4 = scanfile_read_attr(*(_QWORD *)(a1 + 16), *(_QWORD *)(a1 + 24), v19);
if ( !(_BYTE)v4 || (v4 = func3(a1, &v14, v19), !(_BYTE)v4) )
{
unlink(v12);
return v4;
}
if ( v19[0].m128i_i8[8] == 82 )
{
LABEL_23:
v4 = cvsup_write_rcs(*(unsigned int *)(a1 + 32), v19);
if ( !(_BYTE)v4 )
return v4;
goto LABEL_28;
}
if ( v19[0].m128i_i8[8] > 0x52u )
break;
if ( v19[0].m128i_i8[8] == 68 )
goto LABEL_28;
if ( v19[0].m128i_i8[8] != 70 )
goto LABEL_27;
v4 = cvsup_write_file(*(unsigned int *)(a1 + 32), v19);
if ( !(_BYTE)v4 )
return v4;
LABEL_28:
v8 = *(_QWORD *)(a1 + 16) + v19[0].m128i_i64[0];
*(_QWORD *)(a1 + 16) = v8;
if ( v8 >= *(_QWORD *)(a1 + 24) )
goto LABEL_7;
}
if ( v19[0].m128i_i8[8] == 83 )
{
v4 = cvsup_write_symlink(*(unsigned int *)(a1 + 32), v19);
if ( !(_BYTE)v4 )
return v4;
goto LABEL_28;
}
if ( v19[0].m128i_i8[8] == 114 )
goto LABEL_23;
LABEL_27:
logmsg_err("%c: Unknown attr type", &v14);
goto LABEL_28;
}
return v4;
}

original_code:
_Bool
cvsync2cvsup(struct scanfile_args *sa, const char *ofile)
{
 struct scanfile_attr attr, dirattr;
 struct stat st;
 char new_ofile[4096 + (255) + 1];
 int fd, wn;
 if (stat(ofile, &st) != -1) {
  st.st_mode &= (04000|02000|01000| (0400|0200|0100)|((0400|0200|0100) >> 3)|(((0400|0200|0100) >> 3) >> 3));
 } else {
  if ((*__errno_location ()) != 2) {
   logmsg_err("%s: %s", ofile, strerror((*__errno_location ())));
   return (0);
  }
  st.st_mode = 0400|0200|(0400 >> 3)|((0400 >> 3) >> 3);
 }
 wn = snprintf(new_ofile, sizeof(new_ofile), "%s.XXXXXX", ofile);
 if ((wn <= 0) || ((size_t)wn >= sizeof(new_ofile))) {
  logmsg_err("%s: %s", ofile, strerror(22));
  return (0);
 }
 if ((fd = mkstemp(new_ofile)) == -1) {
  logmsg_err("%s: %s", ofile, strerror((*__errno_location ())));
  return (0);
 }
 sa->sa_tmp = fd;
 if (!cvsup_write_header(sa->sa_tmp, sa->sa_scanfile->cf_mtime))
  return (0);
 (void)memset(&dirattr, 0, sizeof(dirattr));
 while (sa->sa_start < sa->sa_end) {
  if (cvsync_isinterrupted()) {
   logmsg_intr();
   (void)unlink(new_ofile);
   return (0);
  }
  if (!scanfile_read_attr(sa->sa_start, sa->sa_end, &attr)) {
   (void)unlink(new_ofile);
   return (0);
  }
  if (!cvsync2cvsup_chdir(sa, &dirattr, &attr)) {
   (void)unlink(new_ofile);
   return (0);
  }
  switch (attr.a_type) {
  case 'D':
   break;
  case 'F':
   if (!cvsup_write_file(sa->sa_tmp, &attr))
    return (0);
   break;
  case 'R':
  case 'r':
   if (!cvsup_write_rcs(sa->sa_tmp, &attr))
    return (0);
   break;
  case 'S':
   if (!cvsup_write_symlink(sa->sa_tmp, &attr))
    return (0);
   break;
  default:
   logmsg_err("%c: Unknown attr type");
   break;
  }
  sa->sa_start += attr.a_size;
 }
 if (dirattr.a_type == 'D') {
  if (!cvsup_write_dirup(sa->sa_tmp, &dirattr))
   return (0);
 }
 while (!list_isempty(sa->sa_dirlist)) {
  cvsync2cvsup_remove_attr(sa, &dirattr);
  if (dirattr.a_type != 'D')
   return (0);
  if (!cvsup_write_dirup(sa->sa_tmp, &dirattr))
   return (0);
 }
 fd = sa->sa_tmp;
 sa->sa_tmp = -1;
 if (fchmod(fd, st.st_mode) == -1) {
  logmsg_err("%s: %s", ofile, strerror((*__errno_location ())));
  (void)unlink(new_ofile);
  return (0);
 }
 if (close(fd) == -1) {
  logmsg_err("%s: %s", ofile, strerror((*__errno_location ())));
  (void)unlink(new_ofile);
  return (0);
 }
 if (rename(new_ofile, ofile) == -1) {
  logmsg_err("%s: %s", ofile, strerror((*__errno_location ())));
  (void)unlink(new_ofile);
  return (0);
 }
 logmsg("Finished successfully");
 return (1);
}

canonical_original_code:
_Bool cvsync2cvsup(struct scanfile_args *sa, char *ofile)
{
 struct scanfile_attr attr; struct scanfile_attr dirattr;
 struct stat st;
 char new_ofile[-1];
 int fd; int wn;
 if (stat(ofile, &st) != -1) {
  st.st_mode &= (04000|02000|01000| (0400|0200|0100)|((0400|0200|0100) >> 3)|(((0400|0200|0100) >> 3) >> 3));
 } else {
  if ((*__errno_location ()) != 2) {
   logmsg_err("%s: %s", ofile, strerror((*__errno_location ())));
   return (0);
  }
  st.st_mode = 0400|0200|(0400 >> 3)|((0400 >> 3) >> 3);
 }
 wn = snprintf(new_ofile, sizeof(new_ofile), "%s.XXXXXX", ofile);
 if ((wn <= 0) || ((unsigned long)wn >= sizeof(new_ofile))) {
  logmsg_err("%s: %s", ofile, strerror(22));
  return (0);
 }
 if ((fd = mkstemp(new_ofile)) == -1) {
  logmsg_err("%s: %s", ofile, strerror((*__errno_location ())));
  return (0);
 }
 sa->sa_tmp = fd;
 if (!cvsup_write_header(sa->sa_tmp, sa->sa_scanfile->cf_mtime))
  return (0);
 (void)memset(&dirattr, 0, sizeof(dirattr));
 while (sa->sa_start < sa->sa_end) {
  if (cvsync_isinterrupted()) {
   logmsg_intr();
   (void)unlink(new_ofile);
   return (0);
  }
  if (!scanfile_read_attr(sa->sa_start, sa->sa_end, &attr)) {
   (void)unlink(new_ofile);
   return (0);
  }
  if (!cvsync2cvsup_chdir(sa, &dirattr, &attr)) {
   (void)unlink(new_ofile);
   return (0);
  }
  switch (attr.a_type) {
  case 'D':
   break;
  case 'F':
   if (!cvsup_write_file(sa->sa_tmp, &attr))
    return (0);
   break;
  case 'R':
  case 'r':
   if (!cvsup_write_rcs(sa->sa_tmp, &attr))
    return (0);
   break;
  case 'S':
   if (!cvsup_write_symlink(sa->sa_tmp, &attr))
    return (0);
   break;
  default:
   logmsg_err("%c: Unknown attr type");
   break;
  }
  sa->sa_start += attr.a_size;
 }
 if (dirattr.a_type == 'D') {
  if (!cvsup_write_dirup(sa->sa_tmp, &dirattr))
   return (0);
 }
 while (!list_isempty(sa->sa_dirlist)) {
  cvsync2cvsup_remove_attr(sa, &dirattr);
  if (dirattr.a_type != 'D')
   return (0);
  if (!cvsup_write_dirup(sa->sa_tmp, &dirattr))
   return (0);
 }
 fd = sa->sa_tmp;
 sa->sa_tmp = -1;
 if (fchmod(fd, st.st_mode) == -1) {
  logmsg_err("%s: %s", ofile, strerror((*__errno_location ())));
  (void)unlink(new_ofile);
  return (0);
 }
 if (close(fd) == -1) {
  logmsg_err("%s: %s", ofile, strerror((*__errno_location ())));
  (void)unlink(new_ofile);
  return (0);
 }
 if (rename(new_ofile, ofile) == -1) {
  logmsg_err("%s: %s", ofile, strerror((*__errno_location ())));
  (void)unlink(new_ofile);
  return (0);
 }
 logmsg("Finished successfully");
 return (1);
}

variable_types:
ofile
char *

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

variable_types: fd int

variable_types: wn int


usage

decompiled_code:
void __noreturn usage()
{
logmsg_err("Usage: cvsync2cvsup [-hqv] -i <cvsync-scanfile> -o <cvsup-scanfile>");
exit(1);
}

canonical_decompiled_code:
void __noreturn func5()
{
logmsg_err("Usage: cvsync2cvsup [-hqv] -i <cvsync-scanfile> -o <cvsup-scanfile>");
exit(1);
}

original_code:
void
usage(void)
{
 logmsg_err("Usage: cvsync2cvsup [-hqv] "
     "-i <cvsync-scanfile> -o <cvsup-scanfile>");
 exit(1);
}

canonical_original_code:
void usage()
{
 logmsg_err("Usage: cvsync2cvsup [-hqv] "
     "-i <cvsync-scanfile> -o <cvsup-scanfile>");
 exit(1);
}


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
char v3; // r12
char *v4; // r15
char *v5; // r13
char *v6; // r14
int v7; // eax
__int64 v8; // rbx
__int64 v9; // rax
int result; // eax
char *v11; // [rsp+8h] [rbp-40h]

v3 = 0;
v4 = 0LL;
v11 = 0LL;
v5 = 0LL;
v6 = 0LL;
while ( 1 )
{
v7 = _posix_getopt((unsigned int)argc, argv, "g:hi:o:qu:v");
if ( v7 == -1 )
break;
switch ( v7 )
{
case 'g':
v4 = optarg;
break;
case 'h':
usage();
return result;
case 'i':
if ( v6 )
usage();
v6 = optarg;
break;
case 'o':
if ( v5 )
usage();
v5 = optarg;
break;
case 'q':
if ( v3 )
usage();
logmsg_quiet = 1;
v3 = 1;
break;
case 'u':
v11 = optarg;
break;
case 'v':
if ( v3 )
usage();
logmsg_detail = 1;
v3 = 1;
break;
default:
usage();
return result;
}
}
if ( v5 != 0LL && v6 != 0LL && optind == argc )
{
if ( !(unsigned __int8)cvsync_init() )
exit(1);
if ( !(unsigned __int8)cvsup_init(v11, v4) )
exit(1);
v8 = scanfile_open(v6);
if ( v8 )
{
v9 = list_init();
*(_QWORD *)(v8 + 4392) = v9;
if ( v9 )
{
if ( !(unsigned __int8)cvsync2cvsup(v8, v5) )
{
scanfile_close(v8);
exit(1);
}
scanfile_close(v8);
exit(0);
}
logmsg_err("Scanfile Error: list init");
scanfile_close(v8);
exit(1);
}
exit(1);
}
usage();
return result;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
char v3; // r12
char *v4; // r15
char *v5; // r13
char *v6; // r14
int v7; // eax
__int64 v8; // rbx
__int64 v9; // rax
int result; // eax
char *v11; // [rsp+8h] [rbp-40h]

v3 = 0;
v4 = 0LL;
v11 = 0LL;
v5 = 0LL;
v6 = 0LL;
while ( 1 )
{
v7 = _posix_getopt((unsigned int)argc, argv, "g:hi:o:qu:v");
if ( v7 == -1 )
break;
switch ( v7 )
{
case 'g':
v4 = optarg;
break;
case 'h':
func5();
return result;
case 'i':
if ( v6 )
func5();
v6 = optarg;
break;
case 'o':
if ( v5 )
func5();
v5 = optarg;
break;
case 'q':
if ( v3 )
func5();
logmsg_quiet = 1;
v3 = 1;
break;
case 'u':
v11 = optarg;
break;
case 'v':
if ( v3 )
func5();
logmsg_detail = 1;
v3 = 1;
break;
default:
func5();
return result;
}
}
if ( v5 != 0LL && v6 != 0LL && optind == argc )
{
if ( !(unsigned __int8)cvsync_init() )
exit(1);
if ( !(unsigned __int8)cvsup_init(v11, v4) )
exit(1);
v8 = scanfile_open(v6);
if ( v8 )
{
v9 = list_init();
*(_QWORD *)(v8 + 4392) = v9;
if ( v9 )
{
if ( !(unsigned __int8)func4(v8, v5) )
{
scanfile_close(v8);
exit(1);
}
scanfile_close(v8);
exit(0);
}
logmsg_err("Scanfile Error: list init");
scanfile_close(v8);
exit(1);
}
exit(1);
}
func5();
return result;
}

original_code:
int
main(int argc, char *argv[])
{
 const char *ifile = ((void *)0), *ofile = ((void *)0);
 struct scanfile_args *sa;
 char *user = ((void *)0), *group = ((void *)0);
 int ch;
 _Bool log_flag = 0;
 while ((ch = getopt(argc, argv, "g:hi:o:qu:v")) != -1) {
  switch (ch) {
  case 'g':
   group = optarg;
   break;
  case 'h':
   usage();
  case 'i':
   if (ifile != ((void *)0)) {
    usage();
   }
   ifile = optarg;
   break;
  case 'o':
   if (ofile != ((void *)0)) {
    usage();
   }
   ofile = optarg;
   break;
  case 'q':
   if (log_flag) {
    usage();
   }
   logmsg_quiet = 1;
   log_flag = 1;
   break;
  case 'u':
   user = optarg;
   break;
  case 'v':
   if (log_flag) {
    usage();
   }
   logmsg_detail = 1;
   log_flag = 1;
   break;
  default:
   usage();
  }
 }
 argc -= optind;
 argv += optind;
 if ((argc != 0) || (ifile == ((void *)0)) || (ofile == ((void *)0))) {
  usage();
 }
 if (!cvsync_init())
  exit(1);
 if (!cvsup_init(user, group))
  exit(1);
 if ((sa = scanfile_open(ifile)) == ((void *)0))
  exit(1);
 if ((sa->sa_dirlist = list_init()) == ((void *)0)) {
  logmsg_err("Scanfile Error: list init");
  scanfile_close(sa);
  exit(1);
 }
 if (!cvsync2cvsup(sa, ofile)) {
  scanfile_close(sa);
  exit(1);
 }
 scanfile_close(sa);
 exit(0);
}

canonical_original_code:
int main(int argc, char *argv[])
{
 char *ifile = ((void *)0); char *ofile = ((void *)0);
 struct scanfile_args *sa;
 char *user = ((void *)0); char *group = ((void *)0);
 int ch;
 _Bool log_flag = 0;
 while ((ch = getopt(argc, argv, "g:hi:o:qu:v")) != -1) {
  switch (ch) {
  case 'g':
   group = optarg;
   break;
  case 'h':
   usage();
  case 'i':
   if (ifile != ((void *)0)) {
    usage();
   }
   ifile = optarg;
   break;
  case 'o':
   if (ofile != ((void *)0)) {
    usage();
   }
   ofile = optarg;
   break;
  case 'q':
   if (log_flag) {
    usage();
   }
   logmsg_quiet = 1;
   log_flag = 1;
   break;
  case 'u':
   user = optarg;
   break;
  case 'v':
   if (log_flag) {
    usage();
   }
   logmsg_detail = 1;
   log_flag = 1;
   break;
  default:
   usage();
  }
 }
 argc -= optind;
 argv += optind;
 if ((argc != 0) || (ifile == ((void *)0)) || (ofile == ((void *)0))) {
  usage();
 }
 if (!cvsync_init())
  exit(1);
 if (!cvsup_init(user, group))
  exit(1);
 if ((sa = scanfile_open(ifile)) == ((void *)0))
  exit(1);
 if ((sa->sa_dirlist = list_init()) == ((void *)0)) {
  logmsg_err("Scanfile Error: list init");
  scanfile_close(sa);
  exit(1);
 }
 if (!cvsync2cvsup(sa, ofile)) {
  scanfile_close(sa);
  exit(1);
 }
 scanfile_close(sa);
 exit(0);
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types:
ifile
char *

variable_types:
user
char *

variable_types:
group
char *

variable_types: ch int


original_code:
_Bool
rcscan_dump(struct rcslib_file *rcs)
{
 struct rcsid *id;
 struct rcsnum *num;
 struct rcssym *sym;
 struct iovec iov[10];
 size_t len, i;
 ssize_t wn;
 int fd = 1;
 iov[0].iov_base = "head\t";
 if (rcs->head.n_len > 0)
  iov[0].iov_len = 5;
 else
  iov[0].iov_len = 4;
 iov[1].iov_base = rcs->head.n_str;
 iov[1].iov_len = rcs->head.n_len;
 iov[2].iov_base = ";\n";
 iov[2].iov_len = 2;
 len = iov[0].iov_len + iov[1].iov_len + iov[2].iov_len;
 i = 3;
 if (rcs->branch.n_len > 0) {
  iov[i].iov_base = "branch\t";
  iov[i].iov_len = 7;
  len += iov[i++].iov_len;
  iov[i].iov_base = rcs->branch.n_str;
  iov[i].iov_len = rcs->branch.n_len;
  len += iov[i++].iov_len;
  iov[i].iov_base = ";\n";
  iov[i].iov_len = 2;
  len += iov[i++].iov_len;
 }
 iov[i].iov_base = "access";
 iov[i].iov_len = 6;
 len += iov[i++].iov_len;
 if ((wn = writev(fd, iov, (int)i)) == -1) {
  (void)fprintf(stderr, "%s\n", strerror((*__errno_location ())));
  return (0);
 }
 if ((size_t)wn != len) {
  (void)fprintf(stderr, "writev error\n");
  return (0);
 }
 for (i = 0 ; i < rcs->access.ra_count ; i++) {
  id = &rcs->access.ra_id[i];
  iov[0].iov_base = "\n\t";
  iov[0].iov_len = 2;
  iov[1].iov_base = id->i_id;
  iov[1].iov_len = id->i_len;
  len = iov[0].iov_len + iov[1].iov_len;
  if ((wn = writev(fd, iov, 2)) == -1) {
   (void)fprintf(stderr, "%s\n", strerror((*__errno_location ())));
   return (0);
  }
  if ((size_t)wn != len) {
   (void)fprintf(stderr, "writev error\n");
   return (0);
  }
 }
 len = 9;
 if ((wn = write(fd, ";\nsymbols", len)) == -1) {
  (void)fprintf(stderr, "%s\n", strerror((*__errno_location ())));
  return (0);
 }
 if ((size_t)wn != len) {
  (void)fprintf(stderr, "write error\n");
  return (0);
 }
 for (i = 0 ; i < rcs->symbols.rs_count ; i++) {
  struct rcslib_symbol *symbol = &rcs->symbols.rs_symbols[i];
  sym = &symbol->sym;
  num = &symbol->num;
  iov[0].iov_base = "\n\t";
  iov[0].iov_len = 2;
  iov[1].iov_base = sym->s_sym;
  iov[1].iov_len = sym->s_len;
  iov[2].iov_base = ":";
  iov[2].iov_len = 1;
  iov[3].iov_base = num->n_str;
  iov[3].iov_len = num->n_len;
  len = iov[0].iov_len + iov[1].iov_len + iov[2].iov_len +
        iov[3].iov_len;
  if ((wn = writev(fd, iov, 4)) == -1) {
   (void)fprintf(stderr, "%s\n", strerror((*__errno_location ())));
   return (0);
  }
  if ((size_t)wn != len) {
   (void)fprintf(stderr, "writev error\n");
   return (0);
  }
 }
 len = 7;
 if ((wn = write(fd, ";\nlocks", len)) == -1) {
  (void)fprintf(stderr, "%s\n", strerror((*__errno_location ())));
  return (0);
 }
 if ((size_t)wn != len) {
  (void)fprintf(stderr, "write error\n");
  return (0);
 }
 for (i = 0 ; i < rcs->locks.rl_count ; i++) {
  struct rcslib_lock *lock = &rcs->locks.rl_locks[i];
  id = &lock->id;
  num = &lock->num;
  iov[0].iov_base = "\n\t";
  iov[0].iov_len = 2;
  iov[1].iov_base = id->i_id;
  iov[1].iov_len = id->i_len;
  iov[2].iov_base = ":";
  iov[2].iov_len = 1;
  iov[3].iov_base = num->n_str;
  iov[3].iov_len = num->n_len;
  len = iov[0].iov_len + iov[1].iov_len + iov[2].iov_len +
        iov[3].iov_len;
  if ((wn = writev(fd, iov, 4)) == -1) {
   (void)fprintf(stderr, "%s\n", strerror((*__errno_location ())));
   return (0);
  }
  if ((size_t)wn != len) {
   (void)fprintf(stderr, "writev error\n");
   return (0);
  }
 }
 iov[0].iov_base = ";";
 iov[0].iov_len = 1;
 iov[1].iov_base = " strict;";
 if (rcs->locks.rl_strict)
  iov[1].iov_len = 8;
 else
  iov[1].iov_len = 0;
 iov[2].iov_base = "\ncomment";
 iov[2].iov_len = 8;
 iov[3].iov_base = "\t@";
 if (rcs->comment.s_len > 0)
  iov[3].iov_len = 2;
 else
  iov[3].iov_len = 0;
 iov[4].iov_base = rcs->comment.s_str;
 iov[4].iov_len = rcs->comment.s_len;
 iov[5].iov_base = "@";
 if (rcs->comment.s_len > 0)
  iov[5].iov_len = 1;
 else
  iov[5].iov_len = 0;
 iov[6].iov_base = ";\nexpand\t@";
 if (rcs->expand.s_len > 0)
  iov[6].iov_len = 10;
 else
  iov[6].iov_len = 2;
 iov[7].iov_base = rcs->expand.s_str;
 iov[7].iov_len = rcs->expand.s_len;
 iov[8].iov_base = "@;\n";
 if (rcs->expand.s_len > 0)
  iov[8].iov_len = 3;
 else
  iov[8].iov_len = 0;
 iov[9].iov_base = "\n\n\n";
 iov[9].iov_len = 3;
 len = iov[0].iov_len + iov[1].iov_len + iov[2].iov_len +
       iov[3].iov_len + iov[4].iov_len + iov[5].iov_len +
       iov[6].iov_len + iov[7].iov_len + iov[8].iov_len +
       iov[9].iov_len;
 if ((wn = writev(fd, iov, 10)) == -1) {
  (void)fprintf(stderr, "%s\n", strerror((*__errno_location ())));
  return (0);
 }
 if ((size_t)wn != len) {
  (void)fprintf(stderr, "writev error\n");
  return (0);
 }
 for (i = 0 ; i < rcs->delta.rd_count ; i++) {
  if (!rcslib_write_delta(fd, &rcs->delta.rd_rev[i]))
   return (0);
 }
 iov[0].iov_base = "\ndesc\n@",
 iov[0].iov_len = 7;
 iov[1].iov_base = rcs->desc.s_str;
 iov[1].iov_len = rcs->desc.s_len;
 iov[2].iov_base = "@\n";
 iov[2].iov_len = 2;
 len = iov[0].iov_len + iov[1].iov_len + iov[2].iov_len;
 if ((wn = writev(fd, iov, 3)) == -1) {
  (void)fprintf(stderr, "%s\n", strerror((*__errno_location ())));
  return (0);
 }
 if ((size_t)wn != len) {
  (void)fprintf(stderr, "writev error\n");
  return (0);
 }
 for (i = 0 ; i < rcs->delta.rd_count ; i++) {
  if (!rcslib_write_deltatext(fd, &rcs->delta.rd_rev[i]))
   return (0);
 }
 return (1);
}

canonical_original_code:
_Bool rcscan_dump(struct rcslib_file *rcs)
{
 struct rcsid *id;
 struct rcsnum *num;
 struct rcssym *sym;
 struct iovec iov[10];
 unsigned long len; unsigned long i;
 long wn;
 int fd = 1;
 iov[0].iov_base = "head\t";
 if (rcs->head.n_len > 0)
  iov[0].iov_len = 5;
 else
  iov[0].iov_len = 4;
 iov[1].iov_base = rcs->head.n_str;
 iov[1].iov_len = rcs->head.n_len;
 iov[2].iov_base = ";\n";
 iov[2].iov_len = 2;
 len = iov[0].iov_len + iov[1].iov_len + iov[2].iov_len;
 i = 3;
 if (rcs->branch.n_len > 0) {
  iov[i].iov_base = "branch\t";
  iov[i].iov_len = 7;
  len += iov[i++].iov_len;
  iov[i].iov_base = rcs->branch.n_str;
  iov[i].iov_len = rcs->branch.n_len;
  len += iov[i++].iov_len;
  iov[i].iov_base = ";\n";
  iov[i].iov_len = 2;
  len += iov[i++].iov_len;
 }
 iov[i].iov_base = "access";
 iov[i].iov_len = 6;
 len += iov[i++].iov_len;
 if ((wn = writev(fd, iov, (int)i)) == -1) {
  (void)fprintf(stderr, "%s\n", strerror((*__errno_location ())));
  return (0);
 }
 if ((unsigned long)wn != len) {
  (void)fprintf(stderr, "writev error\n");
  return (0);
 }
 for (i = 0 ; i < rcs->access.ra_count ; i++) {
  id = &rcs->access.ra_id[i];
  iov[0].iov_base = "\n\t";
  iov[0].iov_len = 2;
  iov[1].iov_base = id->i_id;
  iov[1].iov_len = id->i_len;
  len = iov[0].iov_len + iov[1].iov_len;
  if ((wn = writev(fd, iov, 2)) == -1) {
   (void)fprintf(stderr, "%s\n", strerror((*__errno_location ())));
   return (0);
  }
  if ((unsigned long)wn != len) {
   (void)fprintf(stderr, "writev error\n");
   return (0);
  }
 }
 len = 9;
 if ((wn = write(fd, ";\nsymbols", len)) == -1) {
  (void)fprintf(stderr, "%s\n", strerror((*__errno_location ())));
  return (0);
 }
 if ((unsigned long)wn != len) {
  (void)fprintf(stderr, "write error\n");
  return (0);
 }
 for (i = 0 ; i < rcs->symbols.rs_count ; i++) {
  struct rcslib_symbol *symbol = &rcs->symbols.rs_symbols[i];
  sym = &symbol->sym;
  num = &symbol->num;
  iov[0].iov_base = "\n\t";
  iov[0].iov_len = 2;
  iov[1].iov_base = sym->s_sym;
  iov[1].iov_len = sym->s_len;
  iov[2].iov_base = ":";
  iov[2].iov_len = 1;
  iov[3].iov_base = num->n_str;
  iov[3].iov_len = num->n_len;
  len = iov[0].iov_len + iov[1].iov_len + iov[2].iov_len +
        iov[3].iov_len;
  if ((wn = writev(fd, iov, 4)) == -1) {
   (void)fprintf(stderr, "%s\n", strerror((*__errno_location ())));
   return (0);
  }
  if ((unsigned long)wn != len) {
   (void)fprintf(stderr, "writev error\n");
   return (0);
  }
 }
 len = 7;
 if ((wn = write(fd, ";\nlocks", len)) == -1) {
  (void)fprintf(stderr, "%s\n", strerror((*__errno_location ())));
  return (0);
 }
 if ((unsigned long)wn != len) {
  (void)fprintf(stderr, "write error\n");
  return (0);
 }
 for (i = 0 ; i < rcs->locks.rl_count ; i++) {
  struct rcslib_lock *lock = &rcs->locks.rl_locks[i];
  id = &lock->id;
  num = &lock->num;
  iov[0].iov_base = "\n\t";
  iov[0].iov_len = 2;
  iov[1].iov_base = id->i_id;
  iov[1].iov_len = id->i_len;
  iov[2].iov_base = ":";
  iov[2].iov_len = 1;
  iov[3].iov_base = num->n_str;
  iov[3].iov_len = num->n_len;
  len = iov[0].iov_len + iov[1].iov_len + iov[2].iov_len +
        iov[3].iov_len;
  if ((wn = writev(fd, iov, 4)) == -1) {
   (void)fprintf(stderr, "%s\n", strerror((*__errno_location ())));
   return (0);
  }
  if ((unsigned long)wn != len) {
   (void)fprintf(stderr, "writev error\n");
   return (0);
  }
 }
 iov[0].iov_base = ";";
 iov[0].iov_len = 1;
 iov[1].iov_base = " strict;";
 if (rcs->locks.rl_strict)
  iov[1].iov_len = 8;
 else
  iov[1].iov_len = 0;
 iov[2].iov_base = "\ncomment";
 iov[2].iov_len = 8;
 iov[3].iov_base = "\t@";
 if (rcs->comment.s_len > 0)
  iov[3].iov_len = 2;
 else
  iov[3].iov_len = 0;
 iov[4].iov_base = rcs->comment.s_str;
 iov[4].iov_len = rcs->comment.s_len;
 iov[5].iov_base = "@";
 if (rcs->comment.s_len > 0)
  iov[5].iov_len = 1;
 else
  iov[5].iov_len = 0;
 iov[6].iov_base = ";\nexpand\t@";
 if (rcs->expand.s_len > 0)
  iov[6].iov_len = 10;
 else
  iov[6].iov_len = 2;
 iov[7].iov_base = rcs->expand.s_str;
 iov[7].iov_len = rcs->expand.s_len;
 iov[8].iov_base = "@;\n";
 if (rcs->expand.s_len > 0)
  iov[8].iov_len = 3;
 else
  iov[8].iov_len = 0;
 iov[9].iov_base = "\n\n\n";
 iov[9].iov_len = 3;
 len = iov[0].iov_len + iov[1].iov_len + iov[2].iov_len +
       iov[3].iov_len + iov[4].iov_len + iov[5].iov_len +
       iov[6].iov_len + iov[7].iov_len + iov[8].iov_len +
       iov[9].iov_len;
 if ((wn = writev(fd, iov, 10)) == -1) {
  (void)fprintf(stderr, "%s\n", strerror((*__errno_location ())));
  return (0);
 }
 if ((unsigned long)wn != len) {
  (void)fprintf(stderr, "writev error\n");
  return (0);
 }
 for (i = 0 ; i < rcs->delta.rd_count ; i++) {
  if (!rcslib_write_delta(fd, &rcs->delta.rd_rev[i]))
   return (0);
 }
 iov[0].iov_base = "\ndesc\n@",
 iov[0].iov_len = 7;
 iov[1].iov_base = rcs->desc.s_str;
 iov[1].iov_len = rcs->desc.s_len;
 iov[2].iov_base = "@\n";
 iov[2].iov_len = 2;
 len = iov[0].iov_len + iov[1].iov_len + iov[2].iov_len;
 if ((wn = writev(fd, iov, 3)) == -1) {
  (void)fprintf(stderr, "%s\n", strerror((*__errno_location ())));
  return (0);
 }
 if ((unsigned long)wn != len) {
  (void)fprintf(stderr, "writev error\n");
  return (0);
 }
 for (i = 0 ; i < rcs->delta.rd_count ; i++) {
  if (!rcslib_write_deltatext(fd, &rcs->delta.rd_rev[i]))
   return (0);
 }
 return (1);
}

variable_types: struct rcslib_file { struct rcsnum { char *n_str; unsigned long n_len; unsigned long n_level; int n_num[-1]; } head; struct rcsnum branch; struct rcslib_access { unsigned long ra_size; struct rcsid { char *i_id; unsigned long i_len; } *ra_id; } access; struct rcslib_symbols { unsigned long rs_size; struct rcslib_symbol { struct rcssym { char *s_sym; unsigned long s_len; } sym; struct rcsnum num; } *rs_symbols; } symbols; struct rcslib_locks { unsigned long rl_size; struct rcslib_lock { struct rcsid id; struct rcsnum num; } *rl_locks; int rl_strict; } locks; struct rcsstr { char *s_str; unsigned long s_len; } comment; struct rcsstr expand; struct rcslib_delta { unsigned long rd_size; struct rcslib_revision { struct rcsnum num; struct rcslib_date { struct rcsnum rd_num; 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; } rd_tm; } date; struct rcsid author; struct rcsid state; struct rcslib_branches { unsigned long rb_size; struct rcsnum *rb_num; } branches; struct rcsnum next; struct rcsstr log; struct rcsstr text; struct rcslib_revision *rv_next; int rv_flags; } *rd_rev; } delta; struct rcsstr desc; } *

variable_types: struct rcsnum { char *n_str; unsigned long n_len; unsigned long n_level; int n_num[-1]; } *

variable_types: struct rcssym { char *s_sym; unsigned long s_len; } *

variable_types: struct iovec { void *iov_base; unsigned long iov_len; } [10]

variable_types:
len
unsigned long

variable_types: wn long

variable_types: struct rcslib_symbol { struct rcssym { char *s_sym; unsigned long s_len; } sym; struct rcsnum { char *n_str; unsigned long n_len; unsigned long n_level; int n_num[-1]; } num; } *

variable_types: struct rcslib_lock { struct rcsid { char *i_id; unsigned long i_len; } id; struct rcsnum { char *n_str; unsigned long n_len; unsigned long n_level; int n_num[-1]; } num; } *

user_defined_types: struct rcslib_file { struct rcsnum head; struct rcsnum branch; struct rcslib_access access; struct rcslib_symbols symbols; struct rcslib_locks locks; struct rcsstr comment; struct rcsstr expand; struct rcslib_delta delta; struct rcsstr desc; }

user_defined_types: struct rcslib_symbol { struct rcssym sym; struct rcsnum num; }

user_defined_types: struct rcslib_access { unsigned long ra_size; struct rcsid *ra_id; }

user_defined_types: struct rcslib_symbols { unsigned long rs_size; struct rcslib_symbol *rs_symbols; }

user_defined_types: struct rcslib_locks { unsigned long rl_size; struct rcslib_lock *rl_locks; int rl_strict; }

user_defined_types: struct rcslib_delta { unsigned long rd_size; struct rcslib_revision *rd_rev; }

user_defined_types: struct rcslib_revision { struct rcsnum num; struct rcslib_date date; struct rcsid author; struct rcsid state; struct rcslib_branches branches; struct rcsnum next; struct rcsstr log; struct rcsstr text; struct rcslib_revision *rv_next; int rv_flags; }

user_defined_types: struct rcslib_date { struct rcsnum rd_num; struct tm rd_tm; }


usage

decompiled_code:
void __noreturn usage()
{
fwrite("Usage: rcscan [-qv] <file> ...\n", 1uLL, 0x1FuLL, stderr);
exit(1);
}

canonical_decompiled_code:
void __noreturn func1()
{
fwrite("Usage: rcscan [-qv] <file> ...\n", 1uLL, 0x1FuLL, stderr);
exit(1);
}

original_code:
void
usage(void)
{
 (void)fprintf(stderr, "Usage: rcscan [-qv] <file> ...\n");
 exit(1);
}

canonical_original_code:
void usage()
{
 (void)fprintf(stderr, "Usage: rcscan [-qv] <file> ...\n");
 exit(1);
}


main

decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
char v3; // bp
char v4; // r12
int v5; // eax
__int64 v6; // rbx
int *v7; // rax
char *v8; // rax
int *v9; // rax
char *v10; // rax
int *v11; // rax
char *v12; // rax
int *v13; // rax
char *v14; // rax
const char *v15; // r15
int v16; // eax
int v17; // er14
__off_t v18; // rax
size_t v19; // r13
__int64 v20; // rax
__int64 v21; // r14
int *v22; // rax
char *v23; // rax
void *addr; // [rsp+0h] [rbp-48h]
const char **v25; // [rsp+8h] [rbp-40h]

v3 = 0;
v4 = 0;
while ( 1 )
{
v5 = _posix_getopt((unsigned int)argc, argv, "qv");
if ( v5 == -1 )
break;
if ( v5 == 113 )
{
if ( v4 )
usage();
v4 = 1;
}
else
{
if ( v5 != 118 )
usage();
if ( v3 )
usage();
v3 = 1;
}
}
LODWORD(v6) = argc - optind;
if ( argc != optind )
{
v6 = (int)v6;
v25 = &argv[optind];
while ( (int)v6 > 0 )
{
v15 = v25[v6 - 1];
v16 = open(v15, 0, 0LL);
v17 = v16;
if ( v16 == -1 )
{
v7 = _errno_location();
v8 = strerror(*v7);
fprintf(stderr, "%s: %s\n", v15, v8);
exit(1);
}
v18 = lseek(v16, 0LL, 2);
v19 = v18;
if ( v18 == -1 )
{
v9 = _errno_location();
v10 = strerror(*v9);
fprintf(stderr, "%s: %s\n", v15, v10);
close(v17);
exit(1);
}
if ( !v18 )
{
fprintf(stderr, "%s: empty file\n", v15);
close(v17);
exit(1);
}
addr = mmap(0LL, v18, 1, 2, v17, 0LL);
if ( addr == (void *)-1LL )
{
v11 = _errno_location();
v12 = strerror(*v11);
fprintf(stderr, "%s: %s\n", v15, v12);
close(v17);
exit(1);
}
if ( close(v17) == -1 )
{
v13 = _errno_location();
v14 = strerror(*v13);
fprintf(stderr, "%s: %s\n", v15, v14);
munmap(addr, v19);
exit(1);
}
v20 = rcslib_init(addr, v19);
v21 = v20;
if ( v20 )
{
if ( v3 )
{
if ( !(unsigned __int8)rcscan_dump(v20) )
printf("ERROR: %s\n", v15);
}
else if ( !v4 )
{
printf("NO ERROR: %s\n", v15);
}
rcslib_destroy(v21);
}
else
{
printf("ERROR: %s\n", v15);
}
--v6;
if ( munmap(addr, v19) == -1 )
{
v22 = _errno_location();
v23 = strerror(*v22);
fprintf(stderr, "%s: %s\n", v15, v23);
exit(1);
}
}
exit(0);
}
usage();
}

canonical_decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
char v3; // bp
char v4; // r12
int v5; // eax
__int64 v6; // rbx
int *v7; // rax
char *v8; // rax
int *v9; // rax
char *v10; // rax
int *v11; // rax
char *v12; // rax
int *v13; // rax
char *v14; // rax
const char *v15; // r15
int v16; // eax
int v17; // er14
__off_t v18; // rax
size_t v19; // r13
__int64 v20; // rax
__int64 v21; // r14
int *v22; // rax
char *v23; // rax
void *addr; // [rsp+0h] [rbp-48h]
const char **v25; // [rsp+8h] [rbp-40h]

v3 = 0;
v4 = 0;
while ( 1 )
{
v5 = _posix_getopt((unsigned int)argc, argv, "qv");
if ( v5 == -1 )
break;
if ( v5 == 113 )
{
if ( v4 )
func1();
v4 = 1;
}
else
{
if ( v5 != 118 )
func1();
if ( v3 )
func1();
v3 = 1;
}
}
LODWORD(v6) = argc - optind;
if ( argc != optind )
{
v6 = (int)v6;
v25 = &argv[optind];
while ( (int)v6 > 0 )
{
v15 = v25[v6 - 1];
v16 = open(v15, 0, 0LL);
v17 = v16;
if ( v16 == -1 )
{
v7 = _errno_location();
v8 = strerror(*v7);
fprintf(stderr, "%s: %s\n", v15, v8);
exit(1);
}
v18 = lseek(v16, 0LL, 2);
v19 = v18;
if ( v18 == -1 )
{
v9 = _errno_location();
v10 = strerror(*v9);
fprintf(stderr, "%s: %s\n", v15, v10);
close(v17);
exit(1);
}
if ( !v18 )
{
fprintf(stderr, "%s: empty file\n", v15);
close(v17);
exit(1);
}
addr = mmap(0LL, v18, 1, 2, v17, 0LL);
if ( addr == (void *)-1LL )
{
v11 = _errno_location();
v12 = strerror(*v11);
fprintf(stderr, "%s: %s\n", v15, v12);
close(v17);
exit(1);
}
if ( close(v17) == -1 )
{
v13 = _errno_location();
v14 = strerror(*v13);
fprintf(stderr, "%s: %s\n", v15, v14);
munmap(addr, v19);
exit(1);
}
v20 = rcslib_init(addr, v19);
v21 = v20;
if ( v20 )
{
if ( v3 )
{
if ( !(unsigned __int8)func0(v20) )
printf("ERROR: %s\n", v15);
}
else if ( !v4 )
{
printf("NO ERROR: %s\n", v15);
}
rcslib_destroy(v21);
}
else
{
printf("ERROR: %s\n", v15);
}
--v6;
if ( munmap(addr, v19) == -1 )
{
v22 = _errno_location();
v23 = strerror(*v22);
fprintf(stderr, "%s: %s\n", v15, v23);
exit(1);
}
}
exit(0);
}
func1();
}

original_code:
int
main(int argc, char *argv[])
{
 const char *fname;
 struct rcslib_file *rcs;
 void *addr;
 off_t size;
 uint64_t size64;
 int fd, ch;
 _Bool quiet = 0;
 _Bool verbose = 0;
 while ((ch = getopt(argc, argv, "qv")) != -1) {
  switch (ch) {
  case 'q':
   if (quiet) {
    usage();
   }
   quiet = 1;
   break;
  case 'v':
   if (verbose) {
    usage();
   }
   verbose = 1;
   break;
  default:
   usage();
  }
 }
 argc -= optind;
 argv += optind;
 if (argc == 0) {
  usage();
 }
 while (argc > 0) {
  fname = argv[--argc];
  if ((fd = open(fname, 00, 0)) == -1) {
   (void)fprintf(stderr, "%s: %s\n", fname,
          strerror((*__errno_location ())));
   exit(1);
  }
  if ((size = lseek(fd, (off_t)0, 2)) == (off_t)-1) {
   (void)fprintf(stderr, "%s: %s\n", fname,
          strerror((*__errno_location ())));
   (void)close(fd);
   exit(1);
  }
  if (size == 0) {
   (void)fprintf(stderr, "%s: empty file\n", fname);
   (void)close(fd);
   exit(1);
  }
  size64 = (uint64_t)size;
  if (size64 > (18446744073709551615UL)) {
   (void)fprintf(stderr, "%s: %" "l" "u" ": %s\n", fname,
          size64, strerror(34));
   (void)close(fd);
   exit(1);
  }
  if ((addr = mmap(((void *)0), (size_t)size, 0x1, 0x02,
     fd, (off_t)0)) == ((void *) -1)) {
   (void)fprintf(stderr, "%s: %s\n", fname,
          strerror((*__errno_location ())));
   (void)close(fd);
   exit(1);
  }
  if (close(fd) == -1) {
   (void)fprintf(stderr, "%s: %s\n", fname,
          strerror((*__errno_location ())));
   (void)munmap(addr, (size_t)size);
   exit(1);
  }
  if ((rcs = rcslib_init(addr, size)) != ((void *)0)) {
   if (verbose) {
    if (!rcscan_dump(rcs))
     (void)printf("ERROR: %s\n", fname);
   } else {
    if (!quiet)
     (void)printf("NO ERROR: %s\n", fname);
   }
   rcslib_destroy(rcs);
  } else {
   (void)printf("ERROR: %s\n", fname);
  }
  if (munmap(addr, (size_t)size) == -1) {
   (void)fprintf(stderr, "%s: %s\n", fname,
          strerror((*__errno_location ())));
   exit(1);
  }
 }
 exit(0);
}

canonical_original_code:
int main(int argc, char *argv[])
{
 char *fname;
 struct rcslib_file *rcs;
 void *addr;
 long size;
 unsigned long size64;
 int fd; int ch;
 _Bool quiet = 0;
 _Bool verbose = 0;
 while ((ch = getopt(argc, argv, "qv")) != -1) {
  switch (ch) {
  case 'q':
   if (quiet) {
    usage();
   }
   quiet = 1;
   break;
  case 'v':
   if (verbose) {
    usage();
   }
   verbose = 1;
   break;
  default:
   usage();
  }
 }
 argc -= optind;
 argv += optind;
 if (argc == 0) {
  usage();
 }
 while (argc > 0) {
  fname = argv[--argc];
  if ((fd = open(fname, 00, 0)) == -1) {
   (void)fprintf(stderr, "%s: %s\n", fname,
          strerror((*__errno_location ())));
   exit(1);
  }
  if ((size = lseek(fd, (long)0, 2)) == (off_t)-1) {
   (void)fprintf(stderr, "%s: %s\n", fname,
          strerror((*__errno_location ())));
   (void)close(fd);
   exit(1);
  }
  if (size == 0) {
   (void)fprintf(stderr, "%s: empty file\n", fname);
   (void)close(fd);
   exit(1);
  }
  size64 = (unsigned long)size;
  if (size64 > (18446744073709551615UL)) {
   (void)fprintf(stderr, "%s: %" "l" "u" ": %s\n", fname,
          size64, strerror(34));
   (void)close(fd);
   exit(1);
  }
  if ((addr = mmap(((void *)0), (unsigned long)size, 0x1, 0x02,
     fd, (long)0)) == ((void *) -1)) {
   (void)fprintf(stderr, "%s: %s\n", fname,
          strerror((*__errno_location ())));
   (void)close(fd);
   exit(1);
  }
  if (close(fd) == -1) {
   (void)fprintf(stderr, "%s: %s\n", fname,
          strerror((*__errno_location ())));
   (void)munmap(addr, (unsigned long)size);
   exit(1);
  }
  if ((rcs = rcslib_init(addr, size)) != ((void *)0)) {
   if (verbose) {
    if (!rcscan_dump(rcs))
     (void)printf("ERROR: %s\n", fname);
   } else {
    if (!quiet)
     (void)printf("NO ERROR: %s\n", fname);
   }
   rcslib_destroy(rcs);
  } else {
   (void)printf("ERROR: %s\n", fname);
  }
  if (munmap(addr, (unsigned long)size) == -1) {
   (void)fprintf(stderr, "%s: %s\n", fname,
          strerror((*__errno_location ())));
   exit(1);
  }
 }
 exit(0);
}

variable_types:
fname
char *

variable_types:
addr
void *

variable_types: size long

user_defined_types: struct rcsnum { char *n_str; unsigned long n_len; unsigned long n_level; int n_num[-1]; }

user_defined_types: struct rcsstr { char *s_str; unsigned long s_len; }

user_defined_types: struct rcsid { char *i_id; unsigned long i_len; }

user_defined_types: struct rcslib_lock { struct rcsid id; struct rcsnum num; }

user_defined_types: struct rcssym { char *s_sym; unsigned long s_len; }

user_defined_types: struct rcslib_branches { unsigned long rb_size; struct rcsnum *rb_num; }

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


decompiled_code:
void *__fastcall collection_init(__int64 a1)
{
void *result; // rax

result = memset((void *)a1, 0, 0x4628uLL);
*(_BYTE *)(a1 + 8988) = 1;
*(_WORD *)(a1 + 8990) = -1;
return result;
}

canonical_decompiled_code:
void *__fastcall func0(__int64 a1)
{
void *result; // rax

result = memset((void *)a1, 0, 0x4628uLL);
*(_BYTE *)(a1 + 8988) = 1;
*(_WORD *)(a1 + 8990) = -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]; } *


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

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

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

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

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 )
{
strerror(36);
logmsg_err("collection %s/%s: prefix: %s", a1 + 8);
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

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 )
{
strerror(36);
logmsg_err("collection %s/%s: prefix: %s", a1 + 8);
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; // rbx
char *v1; // rax
char *v2; // rbp
char *v3; // rsi
char *v4; // rdx
char *v5; // rcx
int *v7; // rax
char *v8; // rax
int *v9; // rax
char *v10; // rax

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

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

v0 = malloc(0x28uLL);
if ( v0 )
{
v1 = (char *)malloc(0x200uLL);
v2 = v1;
*v0 = v1;
if ( v1 )
{
v0[1] = 0LL;
v0[2] = 0LL;
v0[4] = 0LL;
v3 = v1 + 512;
v4 = 0LL;
do
{
v5 = v4;
v4 = v1;
*(_QWORD *)v1 = v5;
*((_DWORD *)v1 + 6) = 0;
v1 += 32;
}
while ( v1 != v3 );
v0[3] = v2 + 480;
}
else
{
v9 = _errno_location();
v10 = strerror(*v9);
logmsg_err(&unk_380, v10);
free(v0);
v0 = 0LL;
}
}
else
{
v7 = _errno_location();
v8 = strerror(*v7);
logmsg_err(&unk_380, 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
_QWORD *v3; // rbx
_QWORD *v4; // rbp
void (__fastcall *v5)(_QWORD); // rax
_DWORD *v6; // rdi

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

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

v2 = (_QWORD *)*((_QWORD *)ptr + 1);
while ( v2 )
{
v4 = v2;
v2 = (_QWORD *)*v2;
v5 = (void (__fastcall *)(_QWORD))*((_QWORD *)ptr + 4);
if ( v5 )
v5(v4[2]);
if ( *((_DWORD *)v4 + 6) == 1 )
free(v4);
}
v3 = (_QWORD *)*((_QWORD *)ptr + 3);
while ( v3 )
{
v6 = v3;
v3 = (_QWORD *)*v3;
if ( v6[6] == 1 )
free(v6);
}
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; } *


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_380, v6);
return 0LL;
}
v2[6] = 1;
}
*(_QWORD *)v2 = 0LL;
*((_QWORD *)v2 + 1) = a1[2];
*((_QWORD *)v2 + 2) = a2;
v3 = (_QWORD *)a1[2];
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);
}


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 func8(__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
__uid_t v8; // eax
struct passwd *v9; // rax
__gid_t v10; // eax
struct group *v11; // rax

v2 = s;
v3 = a2;
if ( !s )
{
v8 = getuid();
v9 = getpwuid(v8);
if ( !v9 )
goto LABEL_7;
v2 = v9->pw_name;
}
v4 = strlen(v2);
if ( a2 )
goto LABEL_3;
v10 = getgid();
v11 = getgrgid(v10);
if ( !v11 )
{
LABEL_7:
logmsg_err("Who am I?");
return 0LL;
}
v3 = v11->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
__uid_t v8; // eax
struct passwd *v9; // rax
__gid_t v10; // eax
struct group *v11; // rax

v2 = s;
v3 = a2;
if ( !s )
{
v8 = getuid();
v9 = getpwuid(v8);
if ( !v9 )
goto LABEL_7;
v2 = v9->pw_name;
}
v4 = strlen(v2);
if ( a2 )
goto LABEL_3;
v10 = getgid();
v11 = getgrgid(v10);
if ( !v11 )
{
LABEL_7:
logmsg_err("Who am I?");
return 0LL;
}
v3 = v11->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)
{
int v2; // ebx
ssize_t v3; // rax
unsigned int v4; // edx
char *v6; // rax
int *v7; // rax
char *v8; // rax
char v9[280]; // [rsp+0h] [rbp-118h] BYREF

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

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

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

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 *v4; // r8
unsigned __int64 v6; // rcx
char v8; // dl

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

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, _BYTE *a2, unsigned __int64 a3)
{
char *v3; // rax
char *v4; // r8
unsigned __int64 v6; // rcx
char v8; // dl

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

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