decompiled_code:
__int64 __fastcall config_resolv_prefix(__int64 a1, __int64 a2, unsigned int a3)
{
char v5; // al
const char *v6; // rdx
const char *v7; // rsi
unsigned int v8; // er13
char *v10; // r12
int v11; // eax
int v12; // edi
size_t v13; // rax
size_t v14; // rdx
int v15; // ebp
int v16; // eax
char *v17; // rax
int *v18; // rax
char *v19; // rax
int *v20; // rax
char *v21; // rax
struct stat v22; // [rsp+0h] [rbp-10B8h] BYREF
char s[4136]; // [rsp+90h] [rbp-1028h] BYREF

v5 = *(_BYTE *)(a2 + 520);
if ( v5 == 47 )
{
v10 = (char *)(a2 + 520);
v11 = snprintf(s, 0x1000uLL, "%s", (const char *)(a2 + 520));
}
else
{
if ( !*(_BYTE *)(a1 + 5168) )
{
v6 = (const char *)(a2 + 264);
v7 = (const char *)(a2 + 8);
v8 = 0;
if ( v5 )
logmsg_err("collection %s/%s: prefix %s: must be the absolute path", v7, v6, (const char *)(a2 + 520));
else
logmsg_err("collection %s/%s: no prefix", v7, v6);
return v8;
}
v10 = (char *)(a2 + 520);
v11 = snprintf(s, 0x1000uLL, "%s/%s", (const char *)(a1 + 5168), (const char *)(a2 + 520));
}
v12 = 22;
if ( (unsigned int)(v11 - 1) > 0xFFE )
goto LABEL_18;
if ( stat(s, &v22) == -1 )
{
LABEL_17:
v12 = *_errno_location();
goto LABEL_18;
}
v12 = 20;
if ( (v22.st_mode & 0xF000) != 0x4000 )
{
LABEL_18:
v17 = strerror(v12);
v8 = 0;
logmsg_err("collection %s/%s: prefix %s: %s", (const char *)(a2 + 8), (const char *)(a2 + 264), v10, v17);
return v8;
}
if ( !realpath(s, v10) )
goto LABEL_17;
v13 = strlen(v10);
v12 = 36;
v14 = v13 + 1;
*(_QWORD *)(a2 + 8712) = v13;
if ( v13 + 1 > 0xFFF )
goto LABEL_18;
*(_QWORD *)(a2 + 8712) = v14;
v8 = a3;
*(_BYTE *)(a2 + v13 + 520) = 47;
*(_BYTE *)(a2 + v14 + 520) = 0;
if ( !(_BYTE)a3 )
{
qmemcpy((void *)(a2 + v13 + 521), ".cvsync.XXXXXX", 14);
*(_BYTE *)(a2 + *(_QWORD *)(a2 + 8712) + 534) = 0;
v15 = mkstemp(v10);
if ( v15 == -1 )
{
*(_BYTE *)(a2 + *(_QWORD *)(a2 + 8712) + 520) = 0;
}
else
{
if ( unlink(v10) == -1 )
{
*(_BYTE *)(a2 + *(_QWORD *)(a2 + 8712) + 520) = 0;
v20 = _errno_location();
v21 = strerror(*v20);
logmsg_err("collection %s/%s: prefix %s: %s", (const char *)(a2 + 8), (const char *)(a2 + 264), v10, v21);
close(v15);
return v8;
}
v16 = close(v15);
*(_BYTE *)(a2 + *(_QWORD *)(a2 + 8712) + 520) = 0;
if ( v16 != -1 )
return 1;
}
v18 = _errno_location();
v19 = strerror(*v18);
logmsg_err("collection %s/%s: prefix %s: %s", (const char *)(a2 + 8), (const char *)(a2 + 264), v10, v19);
}
return v8;
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1, __int64 a2, unsigned int a3)
{
char v5; // al
const char *v6; // rdx
const char *v7; // rsi
unsigned int v8; // er13
char *v10; // r12
int v11; // eax
int v12; // edi
size_t v13; // rax
size_t v14; // rdx
int v15; // ebp
int v16; // eax
char *v17; // rax
int *v18; // rax
char *v19; // rax
int *v20; // rax
char *v21; // rax
struct stat v22; // [rsp+0h] [rbp-10B8h] BYREF
char s[4136]; // [rsp+90h] [rbp-1028h] BYREF

v5 = *(_BYTE *)(a2 + 520);
if ( v5 == 47 )
{
v10 = (char *)(a2 + 520);
v11 = snprintf(s, 0x1000uLL, "%s", (const char *)(a2 + 520));
}
else
{
if ( !*(_BYTE *)(a1 + 5168) )
{
v6 = (const char *)(a2 + 264);
v7 = (const char *)(a2 + 8);
v8 = 0;
if ( v5 )
logmsg_err("collection %s/%s: prefix %s: must be the absolute path", v7, v6, (const char *)(a2 + 520));
else
logmsg_err("collection %s/%s: no prefix", v7, v6);
return v8;
}
v10 = (char *)(a2 + 520);
v11 = snprintf(s, 0x1000uLL, "%s/%s", (const char *)(a1 + 5168), (const char *)(a2 + 520));
}
v12 = 22;
if ( (unsigned int)(v11 - 1) > 0xFFE )
goto LABEL_18;
if ( stat(s, &v22) == -1 )
{
LABEL_17:
v12 = *_errno_location();
goto LABEL_18;
}
v12 = 20;
if ( (v22.st_mode & 0xF000) != 0x4000 )
{
LABEL_18:
v17 = strerror(v12);
v8 = 0;
logmsg_err("collection %s/%s: prefix %s: %s", (const char *)(a2 + 8), (const char *)(a2 + 264), v10, v17);
return v8;
}
if ( !realpath(s, v10) )
goto LABEL_17;
v13 = strlen(v10);
v12 = 36;
v14 = v13 + 1;
*(_QWORD *)(a2 + 8712) = v13;
if ( v13 + 1 > 0xFFF )
goto LABEL_18;
*(_QWORD *)(a2 + 8712) = v14;
v8 = a3;
*(_BYTE *)(a2 + v13 + 520) = 47;
*(_BYTE *)(a2 + v14 + 520) = 0;
if ( !(_BYTE)a3 )
{
qmemcpy((void *)(a2 + v13 + 521), ".cvsync.XXXXXX", 14);
*(_BYTE *)(a2 + *(_QWORD *)(a2 + 8712) + 534) = 0;
v15 = mkstemp(v10);
if ( v15 == -1 )
{
*(_BYTE *)(a2 + *(_QWORD *)(a2 + 8712) + 520) = 0;
}
else
{
if ( unlink(v10) == -1 )
{
*(_BYTE *)(a2 + *(_QWORD *)(a2 + 8712) + 520) = 0;
v20 = _errno_location();
v21 = strerror(*v20);
logmsg_err("collection %s/%s: prefix %s: %s", (const char *)(a2 + 8), (const char *)(a2 + 264), v10, v21);
close(v15);
return v8;
}
v16 = close(v15);
*(_BYTE *)(a2 + *(_QWORD *)(a2 + 8712) + 520) = 0;
if ( v16 != -1 )
return 1;
}
v18 = _errno_location();
v19 = strerror(*v18);
logmsg_err("collection %s/%s: prefix %s: %s", (const char *)(a2 + 8), (const char *)(a2 + 264), v10, v19);
}
return v8;
}

original_code:
_Bool
config_resolv_prefix(struct config *cf, struct collection *cl, _Bool rdonly)
{
 struct stat st;
 char path[4096];
 int fd, wn;
 if (cl->cl_prefix[0] != '/') {
  if (strlen(cf->cf_base_prefix) == 0) {
   if (strlen(cl->cl_prefix) == 0) {
    logmsg_err("collection %s/%s: no prefix",
        cl->cl_name, cl->cl_release);
   } else {
    logmsg_err("collection %s/%s: prefix %s: "
        "must be the absolute path",
        cl->cl_name, cl->cl_release,
        cl->cl_prefix);
   }
   return (0);
  }
  wn = snprintf(path, sizeof(path), "%s/%s", cf->cf_base_prefix,
         cl->cl_prefix);
 } else {
  wn = snprintf(path, sizeof(path), "%s", cl->cl_prefix);
 }
 if ((wn <= 0) || ((size_t)wn >= sizeof(path))) {
  logmsg_err("collection %s/%s: prefix %s: %s", cl->cl_name,
      cl->cl_release, cl->cl_prefix, strerror(22));
  return (0);
 }
 if (stat(path, &st) == -1) {
  logmsg_err("collection %s/%s: prefix %s: %s", cl->cl_name,
      cl->cl_release, cl->cl_prefix, strerror((*__errno_location ())));
  return (0);
 }
 if (!((((st.st_mode)) & 0170000) == (0040000))) {
  logmsg_err("collection %s/%s: prefix %s: %s", cl->cl_name,
      cl->cl_release, cl->cl_prefix, strerror(20));
  return (0);
 }
 if (realpath(path, cl->cl_prefix) == ((void *)0)) {
  logmsg_err("collection %s/%s: prefix %s: %s", cl->cl_name,
      cl->cl_release, cl->cl_prefix, strerror((*__errno_location ())));
  return (0);
 }
 cl->cl_prefixlen = strlen(cl->cl_prefix);
 if (cl->cl_prefixlen + 1 >= sizeof(cl->cl_prefix)) {
  logmsg_err("collection %s/%s: prefix %s: %s", cl->cl_name,
      cl->cl_release, cl->cl_prefix,
      strerror(36));
  return (0);
 }
 cl->cl_prefix[cl->cl_prefixlen++] = '/';
 cl->cl_prefix[cl->cl_prefixlen] = '\0';
 if (!rdonly) {
  (void)memcpy(&cl->cl_prefix[cl->cl_prefixlen], ".cvsync.XXXXXX",
        (14));
  cl->cl_prefix[cl->cl_prefixlen + (14)] = '\0';
  if ((fd = mkstemp(cl->cl_prefix)) == -1) {
   cl->cl_prefix[cl->cl_prefixlen] = '\0';
   logmsg_err("collection %s/%s: prefix %s: %s",
       cl->cl_name, cl->cl_release, cl->cl_prefix,
       strerror((*__errno_location ())));
   return (0);
  }
  if (unlink(cl->cl_prefix) == -1) {
   cl->cl_prefix[cl->cl_prefixlen] = '\0';
   logmsg_err("collection %s/%s: prefix %s: %s",
       cl->cl_name, cl->cl_release, cl->cl_prefix,
       strerror((*__errno_location ())));
   (void)close(fd);
   return (0);
  }
  if (close(fd) == -1) {
   cl->cl_prefix[cl->cl_prefixlen] = '\0';
   logmsg_err("collection %s/%s: prefix %s: %s",
       cl->cl_name, cl->cl_release, cl->cl_prefix,
       strerror((*__errno_location ())));
   return (0);
  }
  cl->cl_prefix[cl->cl_prefixlen] = '\0';
 }
 return (1);
}

canonical_original_code:
_Bool config_resolv_prefix(struct config *cf, struct collection *cl, _Bool rdonly)
{
 struct stat st;
 char path[4096];
 int fd; int wn;
 if (cl->cl_prefix[0] != '/') {
  if (strlen(cf->cf_base_prefix) == 0) {
   if (strlen(cl->cl_prefix) == 0) {
    logmsg_err("collection %s/%s: no prefix",
        cl->cl_name, cl->cl_release);
   } else {
    logmsg_err("collection %s/%s: prefix %s: "
        "must be the absolute path",
        cl->cl_name, cl->cl_release,
        cl->cl_prefix);
   }
   return (0);
  }
  wn = snprintf(path, sizeof(path), "%s/%s", cf->cf_base_prefix,
         cl->cl_prefix);
 } else {
  wn = snprintf(path, sizeof(path), "%s", cl->cl_prefix);
 }
 if ((wn <= 0) || ((unsigned long)wn >= sizeof(path))) {
  logmsg_err("collection %s/%s: prefix %s: %s", cl->cl_name,
      cl->cl_release, cl->cl_prefix, strerror(22));
  return (0);
 }
 if (stat(path, &st) == -1) {
  logmsg_err("collection %s/%s: prefix %s: %s", cl->cl_name,
      cl->cl_release, cl->cl_prefix, strerror((*__errno_location ())));
  return (0);
 }
 if (!((((st.st_mode)) & 0170000) == (0040000))) {
  logmsg_err("collection %s/%s: prefix %s: %s", cl->cl_name,
      cl->cl_release, cl->cl_prefix, strerror(20));
  return (0);
 }
 if (realpath(path, cl->cl_prefix) == ((void *)0)) {
  logmsg_err("collection %s/%s: prefix %s: %s", cl->cl_name,
      cl->cl_release, cl->cl_prefix, strerror((*__errno_location ())));
  return (0);
 }
 cl->cl_prefixlen = strlen(cl->cl_prefix);
 if (cl->cl_prefixlen + 1 >= sizeof(cl->cl_prefix)) {
  logmsg_err("collection %s/%s: prefix %s: %s", cl->cl_name,
      cl->cl_release, cl->cl_prefix,
      strerror(36));
  return (0);
 }
 cl->cl_prefix[cl->cl_prefixlen++] = '/';
 cl->cl_prefix[cl->cl_prefixlen] = '\0';
 if (!rdonly) {
  (void)memcpy(&cl->cl_prefix[cl->cl_prefixlen], ".cvsync.XXXXXX",
        (14));
  cl->cl_prefix[cl->cl_prefixlen + (14)] = '\0';
  if ((fd = mkstemp(cl->cl_prefix)) == -1) {
   cl->cl_prefix[cl->cl_prefixlen] = '\0';
   logmsg_err("collection %s/%s: prefix %s: %s",
       cl->cl_name, cl->cl_release, cl->cl_prefix,
       strerror((*__errno_location ())));
   return (0);
  }
  if (unlink(cl->cl_prefix) == -1) {
   cl->cl_prefix[cl->cl_prefixlen] = '\0';
   logmsg_err("collection %s/%s: prefix %s: %s",
       cl->cl_name, cl->cl_release, cl->cl_prefix,
       strerror((*__errno_location ())));
   (void)close(fd);
   return (0);
  }
  if (close(fd) == -1) {
   cl->cl_prefix[cl->cl_prefixlen] = '\0';
   logmsg_err("collection %s/%s: prefix %s: %s",
       cl->cl_name, cl->cl_release, cl->cl_prefix,
       strerror((*__errno_location ())));
   return (0);
  }
  cl->cl_prefix[cl->cl_prefixlen] = '\0';
 }
 return (1);
}

variable_types:
path
char [4096]

variable_types: fd int

variable_types: wn int

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

user_defined_types: struct config_include { struct config_include *ci_next; char ci_name[-1]; long ci_mtime; }


repo: cvsync/cvsync

decompiled_code:
__int64 __fastcall config_resolv_scanfile(__int64 a1, const char *a2)
{
char v2; // al
char *v3; // r12
int v4; // eax
__int64 result; // rax
char *v6; // rax
char *v7; // rax
char v8[4376]; // [rsp-1118h] [rbp-1118h] BYREF

v2 = a2[13344];
if ( !v2 )
return 1LL;
v3 = (char *)(a2 + 13344);
if ( v2 == 47 )
{
v4 = snprintf(v8, 0x1100uLL, "%s", a2 + 13344);
}
else
{
if ( !*(_BYTE *)(a1 + 1072) )
{
logmsg_err("collection %s/%s: scanfile %s: must be an absolute path", a2 + 8, a2 + 264, a2 + 13344);
return 0LL;
}
v4 = snprintf(v8, 0x1100uLL, "%s/%s", (const char *)(a1 + 1072), a2 + 13344);
}
if ( (unsigned int)(v4 - 1) > 0x10FE )
{
v6 = strerror(22);
logmsg_err("collection %s/%s: scanfile %s: %s", a2 + 8, a2 + 264, v3, v6);
result = 0LL;
}
else if ( (unsigned int)(snprintf(v3, 0x1100uLL, "%s", v8) - 1) > 0x10FE )
{
v7 = strerror(22);
logmsg_err("collection %s/%s: scanfile %s: %s", a2 + 8, a2 + 264, v8, v7);
result = 0LL;
}
else
{
result = 1LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1, const char *a2)
{
char v2; // al
char *v3; // r12
int v4; // eax
__int64 result; // rax
char *v6; // rax
char *v7; // rax
char v8[4376]; // [rsp-1118h] [rbp-1118h] BYREF

v2 = a2[13344];
if ( !v2 )
return 1LL;
v3 = (char *)(a2 + 13344);
if ( v2 == 47 )
{
v4 = snprintf(v8, 0x1100uLL, "%s", a2 + 13344);
}
else
{
if ( !*(_BYTE *)(a1 + 1072) )
{
logmsg_err("collection %s/%s: scanfile %s: must be an absolute path", a2 + 8, a2 + 264, a2 + 13344);
return 0LL;
}
v4 = snprintf(v8, 0x1100uLL, "%s/%s", (const char *)(a1 + 1072), a2 + 13344);
}
if ( (unsigned int)(v4 - 1) > 0x10FE )
{
v6 = strerror(22);
logmsg_err("collection %s/%s: scanfile %s: %s", a2 + 8, a2 + 264, v3, v6);
result = 0LL;
}
else if ( (unsigned int)(snprintf(v3, 0x1100uLL, "%s", v8) - 1) > 0x10FE )
{
v7 = strerror(22);
logmsg_err("collection %s/%s: scanfile %s: %s", a2 + 8, a2 + 264, v8, v7);
result = 0LL;
}
else
{
result = 1LL;
}
return result;
}

original_code:
_Bool
config_resolv_scanfile(struct config *cf, struct collection *cl)
{
 char path[4096 + (255) + 1];
 int wn;
 if (strlen(cl->cl_scan_name) == 0)
  return (1);
 if (cl->cl_scan_name[0] != '/') {
  if (strlen(cf->cf_base) == 0) {
   logmsg_err("collection %s/%s: scanfile %s: must be an "
       "absolute path", cl->cl_name,
       cl->cl_release, cl->cl_scan_name);
   return (0);
  }
  wn = snprintf(path, sizeof(path), "%s/%s", cf->cf_base,
         cl->cl_scan_name);
 } else {
  wn = snprintf(path, sizeof(path), "%s", cl->cl_scan_name);
 }
 if ((wn <= 0) || ((size_t)wn >= sizeof(path))) {
  logmsg_err("collection %s/%s: scanfile %s: %s", cl->cl_name,
      cl->cl_release, cl->cl_scan_name, strerror(22));
  return (0);
 }
 wn = snprintf(cl->cl_scan_name, sizeof(cl->cl_scan_name), "%s", path);
 if ((wn <= 0) || ((size_t)wn >= sizeof(cl->cl_scan_name))) {
  logmsg_err("collection %s/%s: scanfile %s: %s", cl->cl_name,
      cl->cl_release, path, strerror(22));
  return (0);
 }
 return (1);
}

canonical_original_code:
_Bool config_resolv_scanfile(struct config *cf, struct collection *cl)
{
 char path[-1];
 int wn;
 if (strlen(cl->cl_scan_name) == 0)
  return (1);
 if (cl->cl_scan_name[0] != '/') {
  if (strlen(cf->cf_base) == 0) {
   logmsg_err("collection %s/%s: scanfile %s: must be an "
       "absolute path", cl->cl_name,
       cl->cl_release, cl->cl_scan_name);
   return (0);
  }
  wn = snprintf(path, sizeof(path), "%s/%s", cf->cf_base,
         cl->cl_scan_name);
 } else {
  wn = snprintf(path, sizeof(path), "%s", cl->cl_scan_name);
 }
 if ((wn <= 0) || ((unsigned long)wn >= sizeof(path))) {
  logmsg_err("collection %s/%s: scanfile %s: %s", cl->cl_name,
      cl->cl_release, cl->cl_scan_name, strerror(22));
  return (0);
 }
 wn = snprintf(cl->cl_scan_name, sizeof(cl->cl_scan_name), "%s", path);
 if ((wn <= 0) || ((unsigned long)wn >= sizeof(cl->cl_scan_name))) {
  logmsg_err("collection %s/%s: scanfile %s: %s", cl->cl_name,
      cl->cl_release, path, strerror(22));
  return (0);
 }
 return (1);
}

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

variable_types:
cl
struct collection *

variable_types:
path
char [-1]

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


decompiled_code:
__int64 __fastcall attr_rcs_encode_dir(_WORD *a1, unsigned __int64 a2, __int16 a3)
{
__int64 result; // rax

result = 0LL;
if ( a2 > 1 )
{
result = 2LL;
*a1 = __ROL2__(a3, 8);
}
return result;
}

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

result = 0LL;
if ( a2 > 1 )
{
result = 2LL;
*a1 = __ROL2__(a3, 8);
}
return result;
}

original_code:
size_t
attr_rcs_encode_dir(uint8_t *buffer, size_t bufsize, uint16_t mode)
{
 if (bufsize < (2))
  return (0);
 do { (buffer)[0] = (uint8_t)((uint16_t)(mode) >> 8); (buffer)[1] = (uint8_t)((uint16_t)(mode) >> 0); } while ( 0);
 return ((2));
}

canonical_original_code:
unsigned long attr_rcs_encode_dir(unsigned char *buffer, unsigned long bufsize, unsigned short mode)
{
 if (bufsize < (2))
  return (0);
 do { (buffer)[0] = (unsigned char)((unsigned short)(mode) >> 8); (buffer)[1] = (unsigned char)((unsigned short)(mode) >> 0); } while ( 0);
 return ((2));
}

variable_types:
buffer
unsigned char *

variable_types:
bufsize
unsigned long

variable_types:
mode
unsigned short

return_type: unsigned long


decompiled_code:
__int64 __fastcall attr_rcs_encode_file(__int64 a1, unsigned __int64 a2, unsigned __int64 a3, unsigned __int64 a4, __int16 a5)
{
__int64 result; // rax

result = 0LL;
if ( a2 > 0x11 )
{
*(_QWORD *)a1 = _byteswap_uint64(a3);
*(_QWORD *)(a1 + 8) = _byteswap_uint64(a4);
result = 18LL;
*(_WORD *)(a1 + 16) = __ROL2__(a5, 8);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, unsigned __int64 a2, unsigned __int64 a3, unsigned __int64 a4, __int16 a5)
{
__int64 result; // rax

result = 0LL;
if ( a2 > 0x11 )
{
*(_QWORD *)a1 = _byteswap_uint64(a3);
*(_QWORD *)(a1 + 8) = _byteswap_uint64(a4);
result = 18LL;
*(_WORD *)(a1 + 16) = __ROL2__(a5, 8);
}
return result;
}

canonical_original_code:
unsigned long attr_rcs_encode_file(unsigned char *buffer, unsigned long bufsize, long mtime, long size, unsigned short mode)
{
 if (bufsize < (18))
  return (0);
 do { (buffer)[0] = (unsigned char)((unsigned long)(mtime) >> 56); (buffer)[1] = (unsigned char)((unsigned long)(mtime) >> 48); (buffer)[2] = (unsigned char)((unsigned long)(mtime) >> 40); (buffer)[3] = (unsigned char)((unsigned long)(mtime) >> 32); (buffer)[4] = (unsigned char)((unsigned long)(mtime) >> 24); (buffer)[5] = (unsigned char)((unsigned long)(mtime) >> 16); (buffer)[6] = (unsigned char)((unsigned long)(mtime) >> 8); (buffer)[7] = (unsigned char)((unsigned long)(mtime) >> 0); } while ( 0);
 do { (&buffer[8])[0] = (unsigned char)((unsigned long)(size) >> 56); (&buffer[8])[1] = (unsigned char)((unsigned long)(size) >> 48); (&buffer[8])[2] = (unsigned char)((unsigned long)(size) >> 40); (&buffer[8])[3] = (unsigned char)((unsigned long)(size) >> 32); (&buffer[8])[4] = (unsigned char)((unsigned long)(size) >> 24); (&buffer[8])[5] = (unsigned char)((unsigned long)(size) >> 16); (&buffer[8])[6] = (unsigned char)((unsigned long)(size) >> 8); (&buffer[8])[7] = (unsigned char)((unsigned long)(size) >> 0); } while ( 0);
 do { (&buffer[16])[0] = (unsigned char)((unsigned short)(mode) >> 8); (&buffer[16])[1] = (unsigned char)((unsigned short)(mode) >> 0); } while ( 0);
 return ((18));
}

variable_types: mtime long

variable_types: size long


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

result = 0LL;
if ( a2 > 9 )
{
*(_QWORD *)a1 = _byteswap_uint64(a3);
result = 10LL;
*(_WORD *)(a1 + 8) = __ROL2__(a4, 8);
}
return result;
}

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

result = 0LL;
if ( a2 > 9 )
{
*(_QWORD *)a1 = _byteswap_uint64(a3);
result = 10LL;
*(_WORD *)(a1 + 8) = __ROL2__(a4, 8);
}
return result;
}

original_code:
size_t
attr_rcs_encode_rcs(uint8_t *buffer, size_t bufsize, time_t mtime,
      uint16_t mode)
{
 if (bufsize < (10))
  return (0);
 do { (buffer)[0] = (uint8_t)((uint64_t)(mtime) >> 56); (buffer)[1] = (uint8_t)((uint64_t)(mtime) >> 48); (buffer)[2] = (uint8_t)((uint64_t)(mtime) >> 40); (buffer)[3] = (uint8_t)((uint64_t)(mtime) >> 32); (buffer)[4] = (uint8_t)((uint64_t)(mtime) >> 24); (buffer)[5] = (uint8_t)((uint64_t)(mtime) >> 16); (buffer)[6] = (uint8_t)((uint64_t)(mtime) >> 8); (buffer)[7] = (uint8_t)((uint64_t)(mtime) >> 0); } while ( 0);
 do { (&buffer[8])[0] = (uint8_t)((uint16_t)(mode) >> 8); (&buffer[8])[1] = (uint8_t)((uint16_t)(mode) >> 0); } while ( 0);
 return ((10));
}

canonical_original_code:
unsigned long attr_rcs_encode_rcs(unsigned char *buffer, unsigned long bufsize, long mtime, unsigned short mode)
{
 if (bufsize < (10))
  return (0);
 do { (buffer)[0] = (unsigned char)((unsigned long)(mtime) >> 56); (buffer)[1] = (unsigned char)((unsigned long)(mtime) >> 48); (buffer)[2] = (unsigned char)((unsigned long)(mtime) >> 40); (buffer)[3] = (unsigned char)((unsigned long)(mtime) >> 32); (buffer)[4] = (unsigned char)((unsigned long)(mtime) >> 24); (buffer)[5] = (unsigned char)((unsigned long)(mtime) >> 16); (buffer)[6] = (unsigned char)((unsigned long)(mtime) >> 8); (buffer)[7] = (unsigned char)((unsigned long)(mtime) >> 0); } while ( 0);
 do { (&buffer[8])[0] = (unsigned char)((unsigned short)(mode) >> 8); (&buffer[8])[1] = (unsigned char)((unsigned short)(mode) >> 0); } while ( 0);
 return ((10));
}


decompiled_code:
__int64 __fastcall attr_rcs_decode_dir(_WORD *a1, unsigned __int64 a2, __int64 a3)
{
__int64 result; // rax

result = 0LL;
if ( a2 > 1 )
{
*(_WORD *)(a3 + 4384) = __ROL2__(*a1, 8);
result = 1LL;
}
return result;
}

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

result = 0LL;
if ( a2 > 1 )
{
*(_WORD *)(a3 + 4384) = __ROL2__(*a1, 8);
result = 1LL;
}
return result;
}

original_code:
_Bool
attr_rcs_decode_dir(uint8_t *buffer, size_t bufsize, struct cvsync_attr *cap)
{
 if (bufsize < (2))
  return (0);
 cap->ca_mode = ((uint16_t)((((uint16_t)((buffer)[0])) << 8) | (((uint16_t)((buffer)[1])) << 0)));
 return (1);
}

canonical_original_code:
_Bool attr_rcs_decode_dir(unsigned char *buffer, unsigned long bufsize, struct cvsync_attr *cap)
{
 if (bufsize < (2))
  return (0);
 cap->ca_mode = ((unsigned short)((((unsigned short)((buffer)[0])) << 8) | (((unsigned short)((buffer)[1])) << 0)));
 return (1);
}

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


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

result = 0LL;
if ( a2 > 0x11 )
{
*(_QWORD *)(a3 + 4368) = _byteswap_uint64(*(_QWORD *)a1);
*(_QWORD *)(a3 + 4376) = _byteswap_uint64(*(_QWORD *)(a1 + 8));
*(_WORD *)(a3 + 4384) = __ROL2__(*(_WORD *)(a1 + 16), 8);
result = 1LL;
}
return result;
}

canonical_original_code:
_Bool attr_rcs_decode_file(unsigned char *buffer, unsigned long bufsize, struct cvsync_attr *cap)
{
 if (bufsize < (18))
  return (0);
 cap->ca_mtime = (long)((unsigned long)((((unsigned long)((buffer)[0])) << 56) | (((unsigned long)((buffer)[1])) << 48) | (((unsigned long)((buffer)[2])) << 40) | (((unsigned long)((buffer)[3])) << 32) | (((unsigned long)((buffer)[4])) << 24) | (((unsigned long)((buffer)[5])) << 16) | (((unsigned long)((buffer)[6])) << 8) | (((unsigned long)((buffer)[7])) << 0)));
 cap->ca_size = ((unsigned long)((((unsigned long)((&buffer[8])[0])) << 56) | (((unsigned long)((&buffer[8])[1])) << 48) | (((unsigned long)((&buffer[8])[2])) << 40) | (((unsigned long)((&buffer[8])[3])) << 32) | (((unsigned long)((&buffer[8])[4])) << 24) | (((unsigned long)((&buffer[8])[5])) << 16) | (((unsigned long)((&buffer[8])[6])) << 8) | (((unsigned long)((&buffer[8])[7])) << 0)));
 cap->ca_mode = ((unsigned short)((((unsigned short)((&buffer[16])[0])) << 8) | (((unsigned short)((&buffer[16])[1])) << 0)));
 return (1);
}

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


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

result = 0LL;
if ( a2 > 9 )
{
*(_QWORD *)(a3 + 4368) = _byteswap_uint64(*(_QWORD *)a1);
*(_WORD *)(a3 + 4384) = __ROL2__(*(_WORD *)(a1 + 8), 8);
result = 1LL;
}
return result;
}

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

result = 0LL;
if ( a2 > 9 )
{
*(_QWORD *)(a3 + 4368) = _byteswap_uint64(*(_QWORD *)a1);
*(_WORD *)(a3 + 4384) = __ROL2__(*(_WORD *)(a1 + 8), 8);
result = 1LL;
}
return result;
}

canonical_original_code:
_Bool attr_rcs_decode_rcs(unsigned char *buffer, unsigned long bufsize, struct cvsync_attr *cap)
{
 if (bufsize < (10))
  return (0);
 cap->ca_mtime = (long)((unsigned long)((((unsigned long)((buffer)[0])) << 56) | (((unsigned long)((buffer)[1])) << 48) | (((unsigned long)((buffer)[2])) << 40) | (((unsigned long)((buffer)[3])) << 32) | (((unsigned long)((buffer)[4])) << 24) | (((unsigned long)((buffer)[5])) << 16) | (((unsigned long)((buffer)[6])) << 8) | (((unsigned long)((buffer)[7])) << 0)));
 cap->ca_mode = ((unsigned short)((((unsigned short)((&buffer[8])[0])) << 8) | (((unsigned short)((&buffer[8])[1])) << 0)));
 return (1);
}


decompiled_code:
int __fastcall cvsync_signal(int a1)
{
int result; // eax

sigaction(2, &cvsync_sig_ign, 0LL);
result = sigaction(15, &cvsync_sig_ign, 0LL);
if ( a1 == 2 )
{
cvsync_process_terminated = 1;
}
else if ( a1 != 15 )
{
return result;
}
cvsync_process_interrupted = 1;
return result;
}

canonical_decompiled_code:
int __fastcall func0(int a1)
{
int result; // eax

sigaction(2, &cvsync_sig_ign, 0LL);
result = sigaction(15, &cvsync_sig_ign, 0LL);
if ( a1 == 2 )
{
cvsync_process_terminated = 1;
}
else if ( a1 != 15 )
{
return result;
}
cvsync_process_interrupted = 1;
return result;
}

original_code:
void
cvsync_signal(int sig)
{
 sigaction(2, &cvsync_sig_ign, ((void *)0));
 sigaction(15, &cvsync_sig_ign, ((void *)0));
 switch (sig) {
 case 1:
 case 13:
  break;
 case 2:
  cvsync_process_terminated = 1;
 case 15:
  cvsync_process_interrupted = 1;
  break;
 default:
  break;
 }
}

variable_types: sig int

return_type: void


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

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

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

cvsync_sig_ign.sa_handler = (__sighandler_t)cvsync_signal;
if ( sigemptyset(&set) == -1 )
{
v4 = _errno_location();
v5 = strerror(*v4);
logmsg_err("sigemptyset: %s", v5);
result = 0LL;
}
else
{
dword_788 = 0;
if ( sigaction(1, &cvsync_sig_ign, 0LL) == -1
|| sigaction(13, &cvsync_sig_ign, 0LL) == -1
|| sigaction(2, 0LL, &v6) == -1
|| (v6.sa_flags &= 0xEFFFFFFF, v6.sa_handler = (__sighandler_t)cvsync_signal, sigaction(2, &v6, 0LL) == -1)
|| sigaction(15, 0LL, &v6) == -1
|| (v6.sa_flags &= 0xEFFFFFFF,
v6.sa_handler = (__sighandler_t)cvsync_signal,
v0 = sigaction(15, &v6, 0LL),
result = 1LL,
v0 == -1) )
{
v2 = _errno_location();
v3 = strerror(*v2);
logmsg_err("sigaction: %s", v3);
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; }


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

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

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

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

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)
{
int v1; // edx
char **v2; // rax
const char *v3; // r8

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

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

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

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)
{
const char *v2; // rdi
char **v3; // rbx

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

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

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

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)
{
int v1; // edx
char **v2; // rax
const char *v3; // r8

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

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

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

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)
{
const char *v2; // rdi
char **v3; // rbx

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

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

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

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)
{
int v1; // edx
char **v2; // rax
const char *v3; // r8

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

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

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

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; // r12
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; // r12
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 )
{
v6 = _errno_location();
v7 = strerror(*v6);
logmsg_err("%s", v7);
close(*(_DWORD *)ptr);
free(ptr);
result = 0LL;
}
else if ( close(*(_DWORD *)ptr) == -1 )
{
v4 = _errno_location();
v5 = strerror(*v4);
logmsg_err("%s", v5);
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 )
{
v6 = _errno_location();
v7 = strerror(*v6);
logmsg_err("%s", v7);
close(*(_DWORD *)ptr);
free(ptr);
result = 0LL;
}
else if ( close(*(_DWORD *)ptr) == -1 )
{
v4 = _errno_location();
v5 = strerror(*v4);
logmsg_err("%s", v5);
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; // er8
void *v5; // rax
int *v6; // rax
char *v7; // rax

*(_QWORD *)(a1 + 40) = a3;
if ( a3 )
{
v5 = mmap(0LL, a3, 1, 2, *(_DWORD *)a1, a2);
v3 = 1;
*(_QWORD *)(a1 + 32) = v5;
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; // er8
void *v5; // rax
int *v6; // rax
char *v7; // rax

*(_QWORD *)(a1 + 40) = a3;
if ( a3 )
{
v5 = mmap(0LL, a3, 1, 2, *(_DWORD *)a1, a2);
v3 = 1;
*(_QWORD *)(a1 + 32) = v5;
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

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)
{
unsigned int v1; // er12
void *v3; // rdi
int *v5; // rax
char *v6; // rax

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

canonical_decompiled_code:
__int64 __fastcall func12(__int64 a1)
{
unsigned int v1; // er12
void *v3; // rdi
int *v5; // rax
char *v6; // rax

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

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 *


variable_types:
namelen
unsigned long

variable_types:
i
unsigned long


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; // xmm1
__m128i *v4; // rbp
__m128i v5; // xmm2
__int64 v6; // rdi
__int64 result; // rax
int *v8; // rax
char *v9; // rax

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

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, const __m128i *a2)
{
__m128i *v2; // rax
__m128i v3; // xmm1
__m128i *v4; // rbp
__m128i v5; // xmm2
__int64 v6; // rdi
__int64 result; // rax
int *v8; // rax
char *v9; // rax

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

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

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)
{
__int8 v4; // r13
__int64 result; // rax

v4 = a3->m128i_i8[8];
if ( a2->m128i_i8[8] != 68 )
{
if ( v4 != 68 )
return 1LL;
*a2 = _mm_loadu_si128(a3);
a2[1] = _mm_loadu_si128(a3 + 1);
a2[2] = _mm_loadu_si128(a3 + 2);
return cvsup_write_dirdown(*(unsigned int *)(a1 + 32), a2);
}
if ( cvsync2cvsup_isparent((__int64)a2, (__int64)a3) )
{
if ( v4 != 68 )
return 1LL;
if ( (unsigned __int8)cvsync2cvsup_insert_attr(a1, a2) )
{
LABEL_20:
*a2 = _mm_loadu_si128(a3);
a2[1] = _mm_loadu_si128(a3 + 1);
a2[2] = _mm_loadu_si128(a3 + 2);
return cvsup_write_dirdown(*(unsigned int *)(a1 + 32), a2);
}
return 0LL;
}
if ( v4 == 68 )
{
while ( (unsigned __int8)cvsup_write_dirup(*(unsigned int *)(a1 + 32), a2) )
{
cvsync2cvsup_remove_attr(a1, a2);
if ( a2->m128i_i8[8] != 68 )
goto LABEL_20;
if ( cvsync2cvsup_isparent((__int64)a2, (__int64)a3) )
{
if ( !(unsigned __int8)cvsync2cvsup_insert_attr(a1, a2) )
return 0LL;
goto LABEL_20;
}
}
return 0LL;
}
while ( 1 )
{
result = list_isempty(*(_QWORD *)(a1 + 4392));
if ( (_BYTE)result )
break;
if ( !(unsigned __int8)cvsup_write_dirup(*(unsigned int *)(a1 + 32), a2) )
return 0LL;
cvsync2cvsup_remove_attr(a1, a2);
if ( a2->m128i_i8[8] != 68 || cvsync2cvsup_isparent((__int64)a2, (__int64)a3) )
return 1LL;
}
*a2 = 0LL;
a2[1] = 0LL;
a2[2] = 0LL;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, __m128i *a2, const __m128i *a3)
{
__int8 v4; // r13
__int64 result; // rax

v4 = a3->m128i_i8[8];
if ( a2->m128i_i8[8] != 68 )
{
if ( v4 != 68 )
return 1LL;
*a2 = _mm_loadu_si128(a3);
a2[1] = _mm_loadu_si128(a3 + 1);
a2[2] = _mm_loadu_si128(a3 + 2);
return cvsup_write_dirdown(*(unsigned int *)(a1 + 32), a2);
}
if ( func0((__int64)a2, (__int64)a3) )
{
if ( v4 != 68 )
return 1LL;
if ( (unsigned __int8)func1(a1, a2) )
{
LABEL_20:
*a2 = _mm_loadu_si128(a3);
a2[1] = _mm_loadu_si128(a3 + 1);
a2[2] = _mm_loadu_si128(a3 + 2);
return cvsup_write_dirdown(*(unsigned int *)(a1 + 32), a2);
}
return 0LL;
}
if ( v4 == 68 )
{
while ( (unsigned __int8)cvsup_write_dirup(*(unsigned int *)(a1 + 32), a2) )
{
func2(a1, a2);
if ( a2->m128i_i8[8] != 68 )
goto LABEL_20;
if ( func0((__int64)a2, (__int64)a3) )
{
if ( !(unsigned __int8)func1(a1, a2) )
return 0LL;
goto LABEL_20;
}
}
return 0LL;
}
while ( 1 )
{
result = list_isempty(*(_QWORD *)(a1 + 4392));
if ( (_BYTE)result )
break;
if ( !(unsigned __int8)cvsup_write_dirup(*(unsigned int *)(a1 + 32), a2) )
return 0LL;
func2(a1, a2);
if ( a2->m128i_i8[8] != 68 || func0((__int64)a2, (__int64)a3) )
return 1LL;
}
*a2 = 0LL;
a2[1] = 0LL;
a2[2] = 0LL;
return result;
}

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 v4; // eax
unsigned __int64 v5; // rax
unsigned __int64 v6; // rax
unsigned int v7; // er12
int v9; // edi
char *v10; // rax
int v11; // er13
__mode_t v12; // esi
int *v13; // rax
char *v14; // rax
__m128i v15[3]; // [rsp+0h] [rbp-1218h] BYREF
__m128i v16[3]; // [rsp+30h] [rbp-11E8h] BYREF
struct stat v17; // [rsp+60h] [rbp-11B8h] BYREF
char s[4392]; // [rsp+F0h] [rbp-1128h] BYREF

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

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1, const char *a2)
{
unsigned int v4; // eax
unsigned __int64 v5; // rax
unsigned __int64 v6; // rax
unsigned int v7; // er12
int v9; // edi
char *v10; // rax
int v11; // er13
__mode_t v12; // esi
int *v13; // rax
char *v14; // rax
__m128i v15[3]; // [rsp+0h] [rbp-1218h] BYREF
__m128i v16[3]; // [rsp+30h] [rbp-11E8h] BYREF
struct stat v17; // [rsp+60h] [rbp-11B8h] BYREF
char s[4392]; // [rsp+F0h] [rbp-1128h] BYREF

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

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; // r15
char *v4; // r14
char *v5; // r13
char v6; // r12
int v7; // eax
__int64 v8; // rbp
__int64 v9; // rax
__int64 v10; // rdi
int result; // eax
char *v12; // [rsp+8h] [rbp-40h]

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

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

v3 = 0LL;
v4 = 0LL;
v5 = 0LL;
v6 = 0;
v12 = 0LL;
while ( 1 )
{
v7 = _posix_getopt((unsigned int)argc, argv, "g:hi:o:qu:v");
if ( v7 == -1 )
break;
switch ( v7 )
{
case 'g':
v3 = optarg;
continue;
case 'i':
if ( v4 )
goto LABEL_5;
v4 = optarg;
break;
case 'o':
if ( v5 )
goto LABEL_5;
v5 = optarg;
break;
case 'q':
if ( v6 )
goto LABEL_5;
logmsg_quiet = 1;
v6 = 1;
break;
case 'u':
v12 = optarg;
continue;
case 'v':
if ( v6 )
goto LABEL_5;
logmsg_detail = 1;
v6 = 1;
break;
default:
goto LABEL_5;
}
}
if ( v5 != 0LL && v4 != 0LL && optind == argc )
{
if ( (unsigned __int8)cvsync_init() )
{
if ( (unsigned __int8)cvsup_init(v12, v3) )
{
v8 = scanfile_open(v4);
if ( v8 )
{
v9 = list_init();
*(_QWORD *)(v8 + 4392) = v9;
if ( v9 )
{
v10 = v8;
if ( (unsigned __int8)func4(v8, v5) )
{
scanfile_close(v8);
exit(0);
}
}
else
{
logmsg_err("Scanfile Error: list init");
v10 = v8;
}
scanfile_close(v10);
}
}
}
exit(1);
}
LABEL_5:
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; // r12
char v4; // bp
int v5; // eax
__int64 v6; // rbx
const char *v7; // r15
int v8; // eax
__off_t v9; // rax
size_t v10; // r13
void *v11; // r14
__int64 v12; // rax
char v13; // al
__int64 v14; // r8
int *v15; // rax
char *v16; // rax
int *v17; // rax
char *v18; // rax
int *v19; // rax
char *v20; // rax
int fd; // [rsp+0h] [rbp-48h]
__int64 fda; // [rsp+0h] [rbp-48h]
__int64 fdb; // [rsp+0h] [rbp-48h]
const char **v24; // [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 ( v3 )
goto LABEL_5;
v3 = 1;
}
else
{
if ( v5 != 118 || v4 )
goto LABEL_5;
v4 = 1;
}
}
LODWORD(v6) = argc - optind;
if ( argc != optind )
{
v6 = (int)v6;
v24 = &argv[optind];
while ( 1 )
{
if ( (int)v6 <= 0 )
exit(0);
v7 = v24[v6 - 1];
v8 = open(v7, 0, 0LL);
if ( v8 == -1 )
{
LABEL_29:
v17 = _errno_location();
v18 = strerror(*v17);
fprintf(stderr, "%s: %s\n", v7, v18);
exit(1);
}
fd = v8;
v9 = lseek(v8, 0LL, 2);
v10 = v9;
if ( v9 == -1 )
goto LABEL_27;
if ( !v9 )
break;
v11 = mmap(0LL, v9, 1, 2, fd, 0LL);
if ( v11 == (void *)-1LL )
{
LABEL_27:
v15 = _errno_location();
v16 = strerror(*v15);
fprintf(stderr, "%s: %s\n", v7, v16);
goto LABEL_28;
}
if ( close(fd) == -1 )
{
v19 = _errno_location();
v20 = strerror(*v19);
fprintf(stderr, "%s: %s\n", v7, v20);
munmap(v11, v10);
exit(1);
}
v12 = rcslib_init(v11, v10);
v14 = v12;
if ( v12 )
{
if ( v4 )
{
fda = v12;
v13 = rcscan_dump(v12);
v14 = fda;
if ( !v13 )
{
printf("ERROR: %s\n", v7);
v14 = fda;
}
}
else if ( !v3 )
{
fdb = v12;
printf("NO ERROR: %s\n", v7);
v14 = fdb;
}
rcslib_destroy(v14);
}
else
{
printf("ERROR: %s\n", v7);
}
--v6;
if ( munmap(v11, v10) == -1 )
goto LABEL_29;
}
fprintf(stderr, "%s: empty file\n", v7);
LABEL_28:
close(fd);
exit(1);
}
LABEL_5:
usage();
}

canonical_decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
char v3; // r12
char v4; // bp
int v5; // eax
__int64 v6; // rbx
const char *v7; // r15
int v8; // eax
__off_t v9; // rax
size_t v10; // r13
void *v11; // r14
__int64 v12; // rax
char v13; // al
__int64 v14; // r8
int *v15; // rax
char *v16; // rax
int *v17; // rax
char *v18; // rax
int *v19; // rax
char *v20; // rax
int fd; // [rsp+0h] [rbp-48h]
__int64 fda; // [rsp+0h] [rbp-48h]
__int64 fdb; // [rsp+0h] [rbp-48h]
const char **v24; // [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 ( v3 )
goto LABEL_5;
v3 = 1;
}
else
{
if ( v5 != 118 || v4 )
goto LABEL_5;
v4 = 1;
}
}
LODWORD(v6) = argc - optind;
if ( argc != optind )
{
v6 = (int)v6;
v24 = &argv[optind];
while ( 1 )
{
if ( (int)v6 <= 0 )
exit(0);
v7 = v24[v6 - 1];
v8 = open(v7, 0, 0LL);
if ( v8 == -1 )
{
LABEL_29:
v17 = _errno_location();
v18 = strerror(*v17);
fprintf(stderr, "%s: %s\n", v7, v18);
exit(1);
}
fd = v8;
v9 = lseek(v8, 0LL, 2);
v10 = v9;
if ( v9 == -1 )
goto LABEL_27;
if ( !v9 )
break;
v11 = mmap(0LL, v9, 1, 2, fd, 0LL);
if ( v11 == (void *)-1LL )
{
LABEL_27:
v15 = _errno_location();
v16 = strerror(*v15);
fprintf(stderr, "%s: %s\n", v7, v16);
goto LABEL_28;
}
if ( close(fd) == -1 )
{
v19 = _errno_location();
v20 = strerror(*v19);
fprintf(stderr, "%s: %s\n", v7, v20);
munmap(v11, v10);
exit(1);
}
v12 = rcslib_init(v11, v10);
v14 = v12;
if ( v12 )
{
if ( v4 )
{
fda = v12;
v13 = func0(v12);
v14 = fda;
if ( !v13 )
{
printf("ERROR: %s\n", v7);
v14 = fda;
}
}
else if ( !v3 )
{
fdb = v12;
printf("NO ERROR: %s\n", v7);
v14 = fdb;
}
rcslib_destroy(v14);
}
else
{
printf("ERROR: %s\n", v7);
}
--v6;
if ( munmap(v11, v10) == -1 )
goto LABEL_29;
}
fprintf(stderr, "%s: empty file\n", v7);
LABEL_28:
close(fd);
exit(1);
}
LABEL_5:
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; }