decompiled_code:
__int64 __fastcall xfer_chunk(__int64 a1, __int64 a2, __int64 (__fastcall *a3)(_QWORD, __int64, __int64), int a4, const char *a5)
{
int v8; // ebx
__int64 result; // rax
int *v10; // rbx
int v11; // er12
int *v12; // rbx
int v13; // ebp
char *v14; // rax
__pid_t v15; // eax
__pid_t v16; // er12
int *v17; // rbx
int v18; // ebp
char *v19; // rax
int *v20; // r13
int v21; // er15
char *v22; // rax
int v23; // eax
int *v24; // rbp
int v25; // er12
int v26; // ebx
int *v27; // rax
int *v28; // rbx
int v29; // ebp
char *v30; // rax
int *v31; // rbp
int v32; // er12
char *v33; // rax
int *v34; // rax
int *v35; // rbx
int v36; // ebp
char *v37; // rax
int stat_loc; // [rsp+14h] [rbp-74h] BYREF
int pipedes[2]; // [rsp+18h] [rbp-70h] BYREF
char v40[104]; // [rsp+20h] [rbp-68h] BYREF

if ( !a5 )
_assert_fail("fetch_cmd != NULL", "chunk-db-cmd.c", 0x20u, "xfer_chunk");
_digest_string(a2, v40);
if ( zunkfs_log_fp && zunkfs_log_level > 1 )
{
v10 = _errno_location();
v11 = *v10;
_zprintf(2LL, "xfer_chunk", 36LL, "chunk=%s using %s\n", v40, a5);
*v10 = v11;
}
v8 = pipe(pipedes);
if ( v8 )
{
result = 0LL;
if ( zunkfs_log_fp )
{
if ( zunkfs_log_level >= 0 )
{
v12 = _errno_location();
v13 = *v12;
v14 = strerror(*v12);
_zprintf(0LL, "xfer_chunk", 40LL, "pipe: %s\n", v14);
*v12 = v13;
result = 0LL;
}
}
return result;
}
v15 = fork();
v16 = v15;
if ( v15 >= 0 )
{
if ( !v15 )
{
close(pipedes[0]);
if ( dup2(pipedes[1], a4) >= 0 )
{
v26 = dup_log_fd(2LL);
if ( v26 )
{
if ( zunkfs_log_fp && zunkfs_log_level >= 0 )
{
v31 = _errno_location();
v32 = *v31;
v33 = strerror(-v26);
_zprintf(0LL, "xfer_chunk", 96LL, "stderr redirection failed: %s\n", v33);
*v31 = v32;
}
exit(v26);
}
execl(a5, a5, v40, 0LL);
if ( zunkfs_log_fp && zunkfs_log_level >= 0 )
{
v35 = _errno_location();
v36 = *v35;
v37 = strerror(0);
_zprintf(0LL, "xfer_chunk", 102LL, "\"%s %s\" failed: %s\n", a5, v40, v37);
*v35 = v36;
}
v34 = _errno_location();
exit(-*v34);
}
if ( zunkfs_log_fp && zunkfs_log_level >= 0 )
{
v28 = _errno_location();
v29 = *v28;
v30 = strerror(*v28);
_zprintf(0LL, "xfer_chunk", 90LL, "stdio redirection failed: %s\n", v30);
*v28 = v29;
}
v27 = _errno_location();
exit(-*v27);
}
close(pipedes[1]);
while ( 1 )
{
v23 = a3((unsigned int)pipedes[0], a1 + v8, 0x10000LL - v8);
if ( v23 < 0 )
{
v20 = _errno_location();
v21 = *v20;
if ( *v20 != 4 )
{
if ( zunkfs_log_fp && zunkfs_log_level > 0 )
{
v22 = strerror(v21);
_zprintf(1LL, "xfer_chunk", 62LL, "read: %s\n", v22);
*v20 = v21;
}
close(pipedes[1]);
kill(v16, 9);
waitpid(v16, 0LL, 0);
return 0LL;
}
}
else
{
if ( !v23 )
{
LABEL_27:
close(pipedes[0]);
waitpid(v16, &stat_loc, 0);
result = 1LL;
if ( zunkfs_log_fp && zunkfs_log_level > 1 )
{
v24 = _errno_location();
v25 = *v24;
_zprintf(2LL, "xfer_chunk", 81LL, "len=%d", (unsigned int)v8);
*v24 = v25;
result = 1LL;
}
return result;
}
v8 += v23;
}
if ( (unsigned int)v8 > 0xFFFF )
goto LABEL_27;
}
}
if ( zunkfs_log_fp && zunkfs_log_level >= 0 )
{
v17 = _errno_location();
v18 = *v17;
v19 = strerror(*v17);
_zprintf(0LL, "xfer_chunk", 46LL, "fork: %s\n", v19);
*v17 = v18;
}
close(pipedes[0]);
close(pipedes[1]);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, __int64 a2, __int64 (__fastcall *a3)(_QWORD, __int64, __int64), int a4, const char *a5)
{
int v8; // ebx
__int64 result; // rax
int *v10; // rbx
int v11; // er12
int *v12; // rbx
int v13; // ebp
char *v14; // rax
__pid_t v15; // eax
__pid_t v16; // er12
int *v17; // rbx
int v18; // ebp
char *v19; // rax
int *v20; // r13
int v21; // er15
char *v22; // rax
int v23; // eax
int *v24; // rbp
int v25; // er12
int v26; // ebx
int *v27; // rax
int *v28; // rbx
int v29; // ebp
char *v30; // rax
int *v31; // rbp
int v32; // er12
char *v33; // rax
int *v34; // rax
int *v35; // rbx
int v36; // ebp
char *v37; // rax
int stat_loc; // [rsp+14h] [rbp-74h] BYREF
int pipedes[2]; // [rsp+18h] [rbp-70h] BYREF
char v40[104]; // [rsp+20h] [rbp-68h] BYREF

if ( !a5 )
_assert_fail("fetch_cmd != NULL", "chunk-db-cmd.c", 0x20u, "xfer_chunk");
_digest_string(a2, v40);
if ( zunkfs_log_fp && zunkfs_log_level > 1 )
{
v10 = _errno_location();
v11 = *v10;
_zprintf(2LL, "xfer_chunk", 36LL, "chunk=%s using %s\n", v40, a5);
*v10 = v11;
}
v8 = pipe(pipedes);
if ( v8 )
{
result = 0LL;
if ( zunkfs_log_fp )
{
if ( zunkfs_log_level >= 0 )
{
v12 = _errno_location();
v13 = *v12;
v14 = strerror(*v12);
_zprintf(0LL, "xfer_chunk", 40LL, "pipe: %s\n", v14);
*v12 = v13;
result = 0LL;
}
}
return result;
}
v15 = fork();
v16 = v15;
if ( v15 >= 0 )
{
if ( !v15 )
{
close(pipedes[0]);
if ( dup2(pipedes[1], a4) >= 0 )
{
v26 = dup_log_fd(2LL);
if ( v26 )
{
if ( zunkfs_log_fp && zunkfs_log_level >= 0 )
{
v31 = _errno_location();
v32 = *v31;
v33 = strerror(-v26);
_zprintf(0LL, "xfer_chunk", 96LL, "stderr redirection failed: %s\n", v33);
*v31 = v32;
}
exit(v26);
}
execl(a5, a5, v40, 0LL);
if ( zunkfs_log_fp && zunkfs_log_level >= 0 )
{
v35 = _errno_location();
v36 = *v35;
v37 = strerror(0);
_zprintf(0LL, "xfer_chunk", 102LL, "\"%s %s\" failed: %s\n", a5, v40, v37);
*v35 = v36;
}
v34 = _errno_location();
exit(-*v34);
}
if ( zunkfs_log_fp && zunkfs_log_level >= 0 )
{
v28 = _errno_location();
v29 = *v28;
v30 = strerror(*v28);
_zprintf(0LL, "xfer_chunk", 90LL, "stdio redirection failed: %s\n", v30);
*v28 = v29;
}
v27 = _errno_location();
exit(-*v27);
}
close(pipedes[1]);
while ( 1 )
{
v23 = a3((unsigned int)pipedes[0], a1 + v8, 0x10000LL - v8);
if ( v23 < 0 )
{
v20 = _errno_location();
v21 = *v20;
if ( *v20 != 4 )
{
if ( zunkfs_log_fp && zunkfs_log_level > 0 )
{
v22 = strerror(v21);
_zprintf(1LL, "xfer_chunk", 62LL, "read: %s\n", v22);
*v20 = v21;
}
close(pipedes[1]);
kill(v16, 9);
waitpid(v16, 0LL, 0);
return 0LL;
}
}
else
{
if ( !v23 )
{
LABEL_27:
close(pipedes[0]);
waitpid(v16, &stat_loc, 0);
result = 1LL;
if ( zunkfs_log_fp && zunkfs_log_level > 1 )
{
v24 = _errno_location();
v25 = *v24;
_zprintf(2LL, "xfer_chunk", 81LL, "len=%d", (unsigned int)v8);
*v24 = v25;
result = 1LL;
}
return result;
}
v8 += v23;
}
if ( (unsigned int)v8 > 0xFFFF )
goto LABEL_27;
}
}
if ( zunkfs_log_fp && zunkfs_log_level >= 0 )
{
v17 = _errno_location();
v18 = *v17;
v19 = strerror(*v17);
_zprintf(0LL, "xfer_chunk", 46LL, "fork: %s\n", v19);
*v17 = v18;
}
close(pipedes[0]);
close(pipedes[1]);
return 0LL;
}

original_code:
static _Bool xfer_chunk(unsigned char *chunk, const unsigned char *digest,
  xfer_fn op, int orig_fd, void *db_info)
{
 const char *fetch_cmd = db_info;
 char chunk_name[(20 * 2)+1];
 int err;
 int fd[2];
 int pid;
 int len;
 int n;
 ((void) sizeof ((fetch_cmd != ((void *)0)) ? 1 : 0), __extension__ ({ if (fetch_cmd != ((void *)0)) ; else __assert_fail ("fetch_cmd != NULL", "chunk-db-cmd.c", 32, __extension__ __PRETTY_FUNCTION__); }));
 __digest_string(digest, chunk_name);
 ({ int ___ret = 0; if (zunkfs_log_fp && (2) <= zunkfs_log_level) { int ___saved_errno = (*__errno_location ()); __zprintf(2, __FUNCTION__, 36, "chunk=%s using %s\n", chunk_name, fetch_cmd); (*__errno_location ()) = ___saved_errno; ___ret = 1; } ___ret; });
 err = pipe(fd);
 if (err) {
  ({ int ___ret = 0; if (zunkfs_log_fp && (0) <= zunkfs_log_level) { int ___saved_errno = (*__errno_location ()); __zprintf(0, __FUNCTION__, 40, "pipe: %s\n", strerror((*__errno_location ()))); (*__errno_location ()) = ___saved_errno; ___ret = 1; } ___ret; });
  return 0;
 }
 pid = fork();
 if (pid < 0) {
  ({ int ___ret = 0; if (zunkfs_log_fp && (0) <= zunkfs_log_level) { int ___saved_errno = (*__errno_location ()); __zprintf(0, __FUNCTION__, 46, "fork: %s\n", strerror((*__errno_location ()))); (*__errno_location ()) = ___saved_errno; ___ret = 1; } ___ret; });
  close(fd[0]);
  close(fd[1]);
  return 0;
 }
 if (pid) {
  int status;
  close(fd[1]);
  for (len = 0; len < (1UL << 16); ) {
   n = op(fd[0], chunk + len, (1UL << 16) - len);
   if (n < 0) {
    if ((*__errno_location ()) == 4)
     continue;
    ({ int ___ret = 0; if (zunkfs_log_fp && (1) <= zunkfs_log_level) { int ___saved_errno = (*__errno_location ()); __zprintf(1, __FUNCTION__, 62, "read: %s\n", strerror((*__errno_location ()))); (*__errno_location ()) = ___saved_errno; ___ret = 1; } ___ret; });
    close(fd[1]);
    kill(pid, 9);
    waitpid(pid, ((void *)0), 0);
    return 0;
   }
   if (!n)
    break;
   len += n;
  }
  close(fd[0]);
  waitpid(pid, &status, 0);
  ({ int ___ret = 0; if (zunkfs_log_fp && (2) <= zunkfs_log_level) { int ___saved_errno = (*__errno_location ()); __zprintf(2, __FUNCTION__, 81, "len=%d", len); (*__errno_location ()) = ___saved_errno; ___ret = 1; } ___ret; });
  return 1;
 }
 close(fd[0]);
 err = dup2(fd[1], orig_fd);
 if (err < 0) {
  ({ int ___ret = 0; if (zunkfs_log_fp && (0) <= zunkfs_log_level) { int ___saved_errno = (*__errno_location ()); __zprintf(0, __FUNCTION__, 90, "stdio redirection failed: %s\n", strerror((*__errno_location ()))); (*__errno_location ()) = ___saved_errno; ___ret = 1; } ___ret; });
  exit(-(*__errno_location ()));
 }
 err = dup_log_fd(2);
 if (err) {
  ({ int ___ret = 0; if (zunkfs_log_fp && (0) <= zunkfs_log_level) { int ___saved_errno = (*__errno_location ()); __zprintf(0, __FUNCTION__, 96, "stderr redirection failed: %s\n", strerror(-err)); (*__errno_location ()) = ___saved_errno; ___ret = 1; } ___ret; });
  exit(err);
 }
 execl(fetch_cmd, fetch_cmd, chunk_name, ((void *)0));
 ({ int ___ret = 0; if (zunkfs_log_fp && (0) <= zunkfs_log_level) { int ___saved_errno = (*__errno_location ()); __zprintf(0, __FUNCTION__, 102, "\"%s %s\" failed: %s\n", fetch_cmd, chunk_name, strerror(err)); (*__errno_location ()) = ___saved_errno; ___ret = 1; } ___ret; });
 exit(-(*__errno_location ()));
 return 0;
}

canonical_original_code:
static _Bool xfer_chunk(unsigned char *chunk, unsigned char *digest, long (*op)(int fd, void *buf, unsigned long len), int orig_fd, void *db_info)
{
 char *fetch_cmd = db_info;
 char chunk_name[-1];
 int err;
 int fd[2];
 int pid;
 int len;
 int n;
 ((void) sizeof ((fetch_cmd != ((void *)0)) ? 1 : 0), __extension__ ({ if (fetch_cmd != ((void *)0)) ; else __assert_fail ("fetch_cmd != NULL", "chunk-db-cmd.c", 32, __extension__ __PRETTY_FUNCTION__); }));
 __digest_string(digest, chunk_name);
 ({ int ___ret = 0; if (zunkfs_log_fp && (2) <= zunkfs_log_level) { int ___saved_errno = (*__errno_location ()); __zprintf(2, __FUNCTION__, 36, "chunk=%s using %s\n", chunk_name, fetch_cmd); (*__errno_location ()) = ___saved_errno; ___ret = 1; } ___ret; });
 err = pipe(fd);
 if (err) {
  ({ int ___ret = 0; if (zunkfs_log_fp && (0) <= zunkfs_log_level) { int ___saved_errno = (*__errno_location ()); __zprintf(0, __FUNCTION__, 40, "pipe: %s\n", strerror((*__errno_location ()))); (*__errno_location ()) = ___saved_errno; ___ret = 1; } ___ret; });
  return 0;
 }
 pid = fork();
 if (pid < 0) {
  ({ int ___ret = 0; if (zunkfs_log_fp && (0) <= zunkfs_log_level) { int ___saved_errno = (*__errno_location ()); __zprintf(0, __FUNCTION__, 46, "fork: %s\n", strerror((*__errno_location ()))); (*__errno_location ()) = ___saved_errno; ___ret = 1; } ___ret; });
  close(fd[0]);
  close(fd[1]);
  return 0;
 }
 if (pid) {
  int status;
  close(fd[1]);
  for (len = 0; len < (1UL << 16); ) {
   n = op(fd[0], chunk + len, (1UL << 16) - len);
   if (n < 0) {
    if ((*__errno_location ()) == 4)
     continue;
    ({ int ___ret = 0; if (zunkfs_log_fp && (1) <= zunkfs_log_level) { int ___saved_errno = (*__errno_location ()); __zprintf(1, __FUNCTION__, 62, "read: %s\n", strerror((*__errno_location ()))); (*__errno_location ()) = ___saved_errno; ___ret = 1; } ___ret; });
    close(fd[1]);
    kill(pid, 9);
    waitpid(pid, ((void *)0), 0);
    return 0;
   }
   if (!n)
    break;
   len += n;
  }
  close(fd[0]);
  waitpid(pid, &status, 0);
  ({ int ___ret = 0; if (zunkfs_log_fp && (2) <= zunkfs_log_level) { int ___saved_errno = (*__errno_location ()); __zprintf(2, __FUNCTION__, 81, "len=%d", len); (*__errno_location ()) = ___saved_errno; ___ret = 1; } ___ret; });
  return 1;
 }
 close(fd[0]);
 err = dup2(fd[1], orig_fd);
 if (err < 0) {
  ({ int ___ret = 0; if (zunkfs_log_fp && (0) <= zunkfs_log_level) { int ___saved_errno = (*__errno_location ()); __zprintf(0, __FUNCTION__, 90, "stdio redirection failed: %s\n", strerror((*__errno_location ()))); (*__errno_location ()) = ___saved_errno; ___ret = 1; } ___ret; });
  exit(-(*__errno_location ()));
 }
 err = dup_log_fd(2);
 if (err) {
  ({ int ___ret = 0; if (zunkfs_log_fp && (0) <= zunkfs_log_level) { int ___saved_errno = (*__errno_location ()); __zprintf(0, __FUNCTION__, 96, "stderr redirection failed: %s\n", strerror(-err)); (*__errno_location ()) = ___saved_errno; ___ret = 1; } ___ret; });
  exit(err);
 }
 execl(fetch_cmd, fetch_cmd, chunk_name, ((void *)0));
 ({ int ___ret = 0; if (zunkfs_log_fp && (0) <= zunkfs_log_level) { int ___saved_errno = (*__errno_location ()); __zprintf(0, __FUNCTION__, 102, "\"%s %s\" failed: %s\n", fetch_cmd, chunk_name, strerror(err)); (*__errno_location ()) = ___saved_errno; ___ret = 1; } ___ret; });
 exit(-(*__errno_location ()));
 return 0;
}

variable_types:
chunk
unsigned char *

variable_types:
digest
unsigned char *

variable_types: long (*)(int fd, void *buf, unsigned long len)

variable_types: err int

variable_types:
fd
int [2]

variable_types: pid int

variable_types: n int

variable_types: status int


repo: dayne/zunkfs

decompiled_code:
__int64 __fastcall cmd_write_chunk(__int64 a1, __int64 a2, const char *a3)
{
return xfer_chunk(a1, a2, (__int64 (__fastcall *)(_QWORD, __int64, __int64))&write, 0, a3);
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, __int64 a2, const char *a3)
{
return func0(a1, a2, (__int64 (__fastcall *)(_QWORD, __int64, __int64))&write, 0, a3);
}

original_code:
static _Bool cmd_write_chunk(const unsigned char *chunk,
  const unsigned char *digest, void *db_info)
{
 return xfer_chunk((unsigned char *)chunk, digest,
   (xfer_fn)write, 0, db_info);
}

canonical_original_code:
static _Bool cmd_write_chunk(unsigned char *chunk, unsigned char *digest, void *db_info)
{
 return xfer_chunk((unsigned char *)chunk, digest,
   (long (*)(int fd, void *buf, unsigned long len))write, 0, db_info);
}


decompiled_code:
__int64 __fastcall cmd_read_chunk(__int64 a1, __int64 a2, const char *a3)
{
return xfer_chunk(a1, a2, (__int64 (__fastcall *)(_QWORD, __int64, __int64))&read, 1, a3);
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, __int64 a2, const char *a3)
{
return func0(a1, a2, (__int64 (__fastcall *)(_QWORD, __int64, __int64))&read, 1, a3);
}

original_code:
static _Bool cmd_read_chunk(unsigned char *chunk, const unsigned char *digest,
  void *db_info)
{
 return xfer_chunk(chunk, digest, (xfer_fn)read, 1, db_info);
}

canonical_original_code:
static _Bool cmd_read_chunk(unsigned char *chunk, unsigned char *digest, void *db_info)
{
 return xfer_chunk(chunk, digest, (long (*)(int fd, void *buf, unsigned long len))read, 1, db_info);
}


decompiled_code:
__int64 __fastcall cmd_chunkdb_ctor(char *name, __int64 a2)
{
int *v3; // r12
int v4; // er13

if ( zunkfs_log_fp && zunkfs_log_level > 1 )
{
v3 = _errno_location();
v4 = *v3;
_zprintf(2LL, "cmd_chunkdb_ctor", 124LL, "mode=0x%x spec=%s\n", *(unsigned int *)(a2 + 8), name);
*v3 = v4;
}
if ( access(name, 1) )
return sprintf_new("%s is not executable.", name);
*(_QWORD *)(a2 + 16) = name;
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func3(char *name, __int64 a2)
{
int *v3; // r12
int v4; // er13

if ( zunkfs_log_fp && zunkfs_log_level > 1 )
{
v3 = _errno_location();
v4 = *v3;
_zprintf(2LL, "cmd_chunkdb_ctor", 124LL, "mode=0x%x spec=%s\n", *(unsigned int *)(a2 + 8), name);
*v3 = v4;
}
if ( access(name, 1) )
return sprintf_new("%s is not executable.", name);
*(_QWORD *)(a2 + 16) = name;
return 0LL;
}

original_code:
static char *cmd_chunkdb_ctor(const char *spec, struct chunk_db *cdb)
{
 ({ int ___ret = 0; if (zunkfs_log_fp && (2) <= zunkfs_log_level) { int ___saved_errno = (*__errno_location ()); __zprintf(2, __FUNCTION__, 124, "mode=0x%x spec=%s\n", cdb->mode, spec); (*__errno_location ()) = ___saved_errno; ___ret = 1; } ___ret; });
 if (access(spec, 1))
  return sprintf_new("%s is not executable.", spec);
 cdb->db_info = (void *)spec;
 return ((void *)0);
}

canonical_original_code:
static char *cmd_chunkdb_ctor(char *spec, struct chunk_db *cdb)
{
 ({ int ___ret = 0; if (zunkfs_log_fp && (2) <= zunkfs_log_level) { int ___saved_errno = (*__errno_location ()); __zprintf(2, __FUNCTION__, 124, "mode=0x%x spec=%s\n", cdb->mode, spec); (*__errno_location ()) = ___saved_errno; ___ret = 1; } ___ret; });
 if (access(spec, 1))
  return sprintf_new("%s is not executable.", spec);
 cdb->db_info = (void *)spec;
 return ((void *)0);
}

variable_types:
spec
char *

variable_types: struct chunk_db { struct chunk_db_type { char *spec_prefix; unsigned int info_size; struct list_head { struct list_head *prev; } type_entry; char *(*ctor)(char *spec, struct chunk_db *chunk_db); _Bool (*read_chunk)(unsigned char *chunk, unsigned char *digest, void *db_info); _Bool (*write_chunk)(unsigned char *chunk, unsigned char *digest, void *db_info); char *help; } *type; int mode; void *db_info; struct list_head db_entry; } *

return_type: char *

user_defined_types: struct chunk_db { struct chunk_db_type *type; int mode; void *db_info; struct list_head db_entry; }

user_defined_types: struct chunk_db_type { char *spec_prefix; unsigned int info_size; struct list_head type_entry; char *(*ctor)(char *spec, struct chunk_db *chunk_db); _Bool (*read_chunk)(unsigned char *chunk, unsigned char *digest, void *db_info); _Bool (*write_chunk)(unsigned char *chunk, unsigned char *digest, void *db_info); char *help; }


decompiled_code:
__int64 init_chunkdb_cmd()
{
return register_chunkdb(&cmd_chunkdb_type);
}

canonical_decompiled_code:
__int64 func4()
{
return register_chunkdb(&cmd_chunkdb_type);
}

original_code:
static void __attribute__((constructor)) init_chunkdb_cmd(void)
{
 register_chunkdb(&cmd_chunkdb_type);
}

canonical_original_code:
static void init_chunkdb_cmd()
{
 register_chunkdb(&cmd_chunkdb_type);
}

return_type: void


original_code:
void init_mutex(struct mutex *m)
{
 *m = (struct mutex){ { { 0, 0, 0, 0, PTHREAD_MUTEX_ERRORCHECK_NP, 0, 0, { 0, 0 } } }, (pthread_t)-1 };
}

variable_types: struct mutex { union pthread_mutex_t { struct __pthread_mutex_s { int __lock; unsigned int __count; int __owner; unsigned int __nusers; int __kind; short __spins; short __elision; struct __pthread_internal_list { struct __pthread_internal_list *__prev; struct __pthread_internal_list *__next; } __list; } __data; char __size[40]; long __align; } mutex; unsigned long owner; } *

user_defined_types: struct mutex { union pthread_mutex_t mutex; unsigned long owner; }

user_defined_types: union pthread_mutex_t { struct __pthread_mutex_s __data; char __size[40]; long __align; }

user_defined_types: struct __pthread_mutex_s { int __lock; unsigned int __count; int __owner; unsigned int __nusers; int __kind; short __spins; short __elision; struct __pthread_internal_list __list; }


lock

decompiled_code:
pthread_t __fastcall lock(pthread_mutex_t *a1)
{
int v1; // eax
pthread_t result; // rax
int v3; // ebp
char *v4; // rax
int *v5; // rbx
int v6; // er12
char *v7; // rax

v1 = pthread_mutex_lock(a1);
if ( v1 )
{
v3 = v1;
if ( zunkfs_log_fp && zunkfs_log_level >= 0 )
{
v5 = _errno_location();
v6 = *v5;
v7 = strerror(v3);
_zprintf(0LL, "lock", 17LL, "pthread_mutex_lock: %s\n", v7);
*v5 = v6;
}
else
{
v4 = strerror(v1);
fprintf(stderr, "pthread_mutex_lock: %s\n", v4);
}
abort();
}
result = pthread_self();
a1[1].__align = result;
return result;
}

canonical_decompiled_code:
pthread_t __fastcall func1(pthread_mutex_t *a1)
{
int v1; // eax
pthread_t result; // rax
int v3; // ebp
char *v4; // rax
int *v5; // rbx
int v6; // er12
char *v7; // rax

v1 = pthread_mutex_lock(a1);
if ( v1 )
{
v3 = v1;
if ( zunkfs_log_fp && zunkfs_log_level >= 0 )
{
v5 = _errno_location();
v6 = *v5;
v7 = strerror(v3);
_zprintf(0LL, "lock", 17LL, "pthread_mutex_lock: %s\n", v7);
*v5 = v6;
}
else
{
v4 = strerror(v1);
fprintf(stderr, "pthread_mutex_lock: %s\n", v4);
}
abort();
}
result = pthread_self();
a1[1].__align = result;
return result;
}

original_code:
void lock(struct mutex *m)
{
 int err = pthread_mutex_lock(&m->mutex);
 if (err)
  do { if (!({ int ___ret = 0; if (zunkfs_log_fp && (0) <= zunkfs_log_level) { int ___saved_errno = (*__errno_location ()); __zprintf(0, __FUNCTION__, 17, "pthread_mutex_lock: %s\n", strerror(err)); (*__errno_location ()) = ___saved_errno; ___ret = 1; } ___ret; })) fprintf(stderr, "pthread_mutex_lock: %s\n", strerror(err)); abort(); } while(0);
 m->owner = pthread_self();
}

user_defined_types: struct __pthread_internal_list { struct __pthread_internal_list *__prev; struct __pthread_internal_list *__next; }


unlock

decompiled_code:
int __fastcall unlock(pthread_mutex_t *a1)
{
int result; // eax
int v2; // ebx
char *v3; // rax
int *v4; // rbp
int v5; // er12
char *v6; // rax

a1[1].__align = -1LL;
result = pthread_mutex_unlock(a1);
if ( result )
{
v2 = result;
if ( zunkfs_log_fp && zunkfs_log_level >= 0 )
{
v4 = _errno_location();
v5 = *v4;
v6 = strerror(v2);
_zprintf(0LL, "unlock", 27LL, "pthread_mutex_lock: %s\n", v6);
*v4 = v5;
}
else
{
v3 = strerror(result);
fprintf(stderr, "pthread_mutex_lock: %s\n", v3);
}
abort();
}
return result;
}

canonical_decompiled_code:
int __fastcall func2(pthread_mutex_t *a1)
{
int result; // eax
int v2; // ebx
char *v3; // rax
int *v4; // rbp
int v5; // er12
char *v6; // rax

a1[1].__align = -1LL;
result = pthread_mutex_unlock(a1);
if ( result )
{
v2 = result;
if ( zunkfs_log_fp && zunkfs_log_level >= 0 )
{
v4 = _errno_location();
v5 = *v4;
v6 = strerror(v2);
_zprintf(0LL, "unlock", 27LL, "pthread_mutex_lock: %s\n", v6);
*v4 = v5;
}
else
{
v3 = strerror(result);
fprintf(stderr, "pthread_mutex_lock: %s\n", v3);
}
abort();
}
return result;
}

original_code:
void unlock(struct mutex *m)
{
 int err;
 m->owner = (pthread_t)-1;
 err = pthread_mutex_unlock(&m->mutex);
 if (err)
  do { if (!({ int ___ret = 0; if (zunkfs_log_fp && (0) <= zunkfs_log_level) { int ___saved_errno = (*__errno_location ()); __zprintf(0, __FUNCTION__, 27, "pthread_mutex_lock: %s\n", strerror(err)); (*__errno_location ()) = ___saved_errno; ___ret = 1; } ___ret; })) fprintf(stderr, "pthread_mutex_lock: %s\n", strerror(err)); abort(); } while(0);
}


trylock

decompiled_code:
_BOOL8 __fastcall trylock(pthread_mutex_t *a1)
{
int v1; // eax
int v2; // ebx
char *v4; // rax
int *v5; // rbp
int v6; // er12
char *v7; // rax

v1 = pthread_mutex_trylock(a1);
v2 = v1;
if ( (v1 & 0xFFFFFFEF) != 0 )
{
if ( zunkfs_log_fp && zunkfs_log_level >= 0 )
{
v5 = _errno_location();
v6 = *v5;
v7 = strerror(v2);
_zprintf(0LL, "trylock", 34LL, "pthread_mutex_lock: %s\n", v7);
*v5 = v6;
}
else
{
v4 = strerror(v1);
fprintf(stderr, "pthread_mutex_lock: %s\n", v4);
}
abort();
}
if ( !v1 )
a1[1].__align = pthread_self();
return v2 == 0;
}

canonical_decompiled_code:
_BOOL8 __fastcall func3(pthread_mutex_t *a1)
{
int v1; // eax
int v2; // ebx
char *v4; // rax
int *v5; // rbp
int v6; // er12
char *v7; // rax

v1 = pthread_mutex_trylock(a1);
v2 = v1;
if ( (v1 & 0xFFFFFFEF) != 0 )
{
if ( zunkfs_log_fp && zunkfs_log_level >= 0 )
{
v5 = _errno_location();
v6 = *v5;
v7 = strerror(v2);
_zprintf(0LL, "trylock", 34LL, "pthread_mutex_lock: %s\n", v7);
*v5 = v6;
}
else
{
v4 = strerror(v1);
fprintf(stderr, "pthread_mutex_lock: %s\n", v4);
}
abort();
}
if ( !v1 )
a1[1].__align = pthread_self();
return v2 == 0;
}

original_code:
int trylock(struct mutex *m)
{
 int err = pthread_mutex_trylock(&m->mutex);
 if (err && err != 16)
  do { if (!({ int ___ret = 0; if (zunkfs_log_fp && (0) <= zunkfs_log_level) { int ___saved_errno = (*__errno_location ()); __zprintf(0, __FUNCTION__, 34, "pthread_mutex_lock: %s\n", strerror(err)); (*__errno_location ()) = ___saved_errno; ___ret = 1; } ___ret; })) fprintf(stderr, "pthread_mutex_lock: %s\n", strerror(err)); abort(); } while(0);
 if (!err)
  m->owner = pthread_self();
 return !err;
}

return_type: int


decompiled_code:
_BOOL8 __fastcall IS_ERR(unsigned __int64 a1)
{
_BOOL8 result; // rax

result = 0LL;
if ( _errptr <= a1 )
result = a1 < _errptr + 256LL;
return result;
}

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

result = 0LL;
if ( _errptr <= a1 )
result = a1 < _errptr + 256LL;
return result;
}

original_code:
static inline int IS_ERR(const void *ptr)
{
 return ptr >= __errptr && ptr < __errptr + 256;
}

canonical_original_code:
static inline int IS_ERR(void *ptr)
{
 return ptr >= __errptr && ptr < __errptr + 256;
}

variable_types:
ptr
void *


decompiled_code:
__int64 __fastcall htole16(unsigned int a1)
{
return a1;
}

canonical_decompiled_code:
__int64 __fastcall func1(unsigned int a1)
{
return a1;
}

original_code: static inline le16_t htole16(uint16_t x) { return (le16_t){ x }; }

canonical_original_code: static inline struct le16_t htole16(unsigned short x) { return (struct le16_t){ x }; }

variable_types:
x
unsigned short

return_type: struct le16_t { unsigned short v; }


decompiled_code:
__int64 __fastcall htole64(__int64 a1)
{
return a1;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1)
{
return a1;
}

original_code: static inline le64_t htole64(uint64_t x) { return (le64_t){ x }; }

canonical_original_code: static inline struct le64_t htole64(unsigned long x) { return (struct le64_t){ x }; }

variable_types:
x
unsigned long

return_type: struct le64_t { unsigned long v; }


decompiled_code:
__int64 __fastcall le64toh(__int64 a1)
{
return a1;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1)
{
return a1;
}

original_code: static inline uint64_t le64toh(le64_t x) { return x.v; }

canonical_original_code: static inline unsigned long le64toh(struct le64_t x) { return x.v; }

variable_types:
x
struct le64_t { unsigned long v; }

return_type: unsigned long


decompiled_code:
__int64 str2digest()
{
unsigned __int64 v0; // rax
int v1; // ebx
__int64 result; // rax

v0 = _string_digest();
v1 = v0;
result = IS_ERR(v0);
if ( (_DWORD)result )
result = _PTR_ERR(v1, (__int64)"str2digest", 0x32u);
return result;
}

canonical_decompiled_code:
__int64 func7()
{
unsigned __int64 v0; // rax
int v1; // ebx
__int64 result; // rax

v0 = _string_digest();
v1 = v0;
result = func0(v0);
if ( (_DWORD)result )
result = func5(v1, (__int64)"str2digest", 0x32u);
return result;
}

original_code:
static inline int str2digest(const char *str, unsigned char *digest)
{
 unsigned char *d;
 d = __string_digest(str, digest);
 if (IS_ERR(d))
  return __PTR_ERR(d, __FUNCTION__, 50);
 return 0;
}

canonical_original_code:
static inline int str2digest(char *str, unsigned char *digest)
{
 unsigned char *d;
 d = __string_digest(str, digest);
 if (IS_ERR(d))
  return __PTR_ERR(d, __FUNCTION__, 50);
 return 0;
}

variable_types:
str
char *

variable_types:
d
unsigned char *


decompiled_code:
__int64 __fastcall write_dentry(int fd, __int64 a2)
{
unsigned int v2; // ebx
int v3; // eax
int v4; // eax

v2 = 0;
while ( 1 )
{
v3 = write(fd, (const void *)(a2 + (int)v2), 256LL - (int)v2);
if ( v3 < 0 )
break;
v2 += v3;
LABEL_3:
if ( v2 > 0xFF )
return v2;
}
v4 = *_errno_location();
if ( v4 == 4 )
goto LABEL_3;
return (unsigned int)-v4;
}

canonical_decompiled_code:
__int64 __fastcall func8(int fd, __int64 a2)
{
unsigned int v2; // ebx
int v3; // eax
int v4; // eax

v2 = 0;
while ( 1 )
{
v3 = write(fd, (const void *)(a2 + (int)v2), 256LL - (int)v2);
if ( v3 < 0 )
break;
v2 += v3;
LABEL_3:
if ( v2 > 0xFF )
return v2;
}
v4 = *_errno_location();
if ( v4 == 4 )
goto LABEL_3;
return (unsigned int)-v4;
}

original_code:
static int write_dentry(int fd, struct disk_dentry *de)
{
 void *ptr = de;
 int len;
 for (len = 0; len < sizeof(struct disk_dentry); ) {
  int n = write(fd, ptr + len, sizeof(struct disk_dentry) - len);
  if (n < 0) {
   if ((*__errno_location ()) == 4)
    continue;
   return -(*__errno_location ());
  }
  len += n;
 }
 return len;
}

variable_types: fd int

variable_types: struct disk_dentry { unsigned char digest[20]; unsigned char secret_digest[20]; struct le16_t { unsigned short v; } mode; unsigned char flags; unsigned char mtime_csec; struct le64_t { unsigned long v; } size; struct le32_t { unsigned int v; } ctime; struct le32_t mtime; unsigned char name[-1]; } *

variable_types: len int

user_defined_types: struct disk_dentry { unsigned char digest[20]; unsigned char secret_digest[20]; struct le16_t mode; unsigned char flags; unsigned char mtime_csec; struct le64_t size; struct le32_t ctime; struct le32_t mtime; unsigned char name[-1]; }


decompiled_code:
__int64 __fastcall test_write_chunk(__int64 a1, __int64 a2)
{
void *v2; // rax
unsigned __int8 v3; // r12
const char *v4; // rax
__int64 v6; // [rsp-Eh] [rbp-10050h] BYREF
char v7[65552]; // [rsp+32h] [rbp-10010h] BYREF

v2 = 0LL;
do
{
v7[(_QWORD)v2] = rand_chunk[(_QWORD)v2] ^ *((_BYTE *)v2 + a1);
v2 = (char *)v2 + 1;
}
while ( v2 != &unk_10000 );
v3 = write_chunk(v7, a2);
v4 = (const char *)_digest_string(a2, &v6);
printf("test_write_chunk: %s\n", v4);
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, __int64 a2)
{
void *v2; // rax
unsigned __int8 v3; // r12
const char *v4; // rax
__int64 v6; // [rsp-Eh] [rbp-10050h] BYREF
char v7[65552]; // [rsp+32h] [rbp-10010h] BYREF

v2 = 0LL;
do
{
v7[(_QWORD)v2] = rand_chunk[(_QWORD)v2] ^ *((_BYTE *)v2 + a1);
v2 = (char *)v2 + 1;
}
while ( v2 != &unk_10000 );
v3 = write_chunk(v7, a2);
v4 = (const char *)_digest_string(a2, &v6);
printf("test_write_chunk: %s\n", v4);
return v3;
}

original_code:
static int test_write_chunk(const unsigned char *chunk, unsigned char *digest)
{
 unsigned char real_chunk[(1UL << 16)];
 int i, err;
 for (i = 0; i < (1UL << 16); i ++)
  real_chunk[i] = chunk[i] ^ rand_chunk[i];
 err = write_chunk(real_chunk, digest);
 if (err < 0)
  return err;
 printf("test_write_chunk: %s\n", __digest_string(digest, __builtin_alloca ((20 * 2) + 1)));
 return err;
}

canonical_original_code:
static int test_write_chunk(unsigned char *chunk, unsigned char *digest)
{
 unsigned char real_chunk[-1];
 int i; int err;
 for (i = 0; i < (1UL << 16); i ++)
  real_chunk[i] = chunk[i] ^ rand_chunk[i];
 err = write_chunk(real_chunk, digest);
 if (err < 0)
  return err;
 printf("test_write_chunk: %s\n", __digest_string(digest, __builtin_alloca ((20 * 2) + 1)));
 return err;
}

variable_types:
chunk
unsigned char *

variable_types:
digest
unsigned char *

variable_types: i int

variable_types: err int


decompiled_code:
__int64 __fastcall test_read_chunk(__int64 a1, __int64 a2)
{
const char *v2; // rax
unsigned int v3; // ecx
void *v4; // rax
__int64 v6; // [rsp+0h] [rbp-50h] BYREF

v2 = (const char *)_digest_string(a2, &v6);
printf("test_read_chunk: %s\n", v2);
v3 = (unsigned __int8)read_chunk(a1, a2);
v4 = 0LL;
do
{
*((_BYTE *)v4 + a1) ^= rand_chunk[(_QWORD)v4];
v4 = (char *)v4 + 1;
}
while ( v4 != &unk_10000 );
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, __int64 a2)
{
const char *v2; // rax
unsigned int v3; // ecx
void *v4; // rax
__int64 v6; // [rsp+0h] [rbp-50h] BYREF

v2 = (const char *)_digest_string(a2, &v6);
printf("test_read_chunk: %s\n", v2);
v3 = (unsigned __int8)read_chunk(a1, a2);
v4 = 0LL;
do
{
*((_BYTE *)v4 + a1) ^= rand_chunk[(_QWORD)v4];
v4 = (char *)v4 + 1;
}
while ( v4 != &unk_10000 );
return v3;
}

original_code:
static int test_read_chunk(unsigned char *chunk, const unsigned char *digest)
{
 int i, err;
 printf("test_read_chunk: %s\n", __digest_string(digest, __builtin_alloca ((20 * 2) + 1)));
 err = read_chunk(chunk, digest);
 if (err < 0)
  return err;
 for (i = 0; i < (1UL << 16); i ++)
  chunk[i] ^= rand_chunk[i];
 return err;
}

canonical_original_code:
static int test_read_chunk(unsigned char *chunk, unsigned char *digest)
{
 int i; int err;
 printf("test_read_chunk: %s\n", __digest_string(digest, __builtin_alloca ((20 * 2) + 1)));
 err = read_chunk(chunk, digest);
 if (err < 0)
  return err;
 for (i = 0; i < (1UL << 16); i ++)
  chunk[i] ^= rand_chunk[i];
 return err;
}


decompiled_code:
__int64 __fastcall do_store(int fd)
{
unsigned int v2; // ebx
int v3; // edi
int v4; // eax
char *v5; // rax
const char *v7; // rax
__int64 v8; // [rsp-Eh] [rbp-10080h] BYREF
char v9[32]; // [rsp+32h] [rbp-10040h] BYREF
__int64 buf[2]; // [rsp+52h] [rbp-10020h] BYREF
char s[65520]; // [rsp+62h] [rbp-10010h] BYREF

buf[0] = 0LL;
buf[1] = 0LL;
memset(s, 0, sizeof(s));
v2 = 0;
while ( 1 )
{
v4 = read(fd, (char *)buf + (int)v2, 0x10000LL - (int)v2);
if ( v4 < 0 )
{
v3 = *_errno_location();
if ( v3 != 4 )
{
v5 = strerror(v3);
fprintf(stderr, "read: %s\n", v5);
exit(-1);
}
goto LABEL_3;
}
if ( !v4 )
break;
v2 += v4;
LABEL_3:
if ( v2 > 0xFFFF )
goto LABEL_10;
}
if ( !v2 )
return v2;
LABEL_10:
write_chunk(buf, v9);
v7 = (const char *)_digest_string(v9, &v8);
printf("Stored chunk %s\n", v7);
return 1;
}

canonical_decompiled_code:
__int64 __fastcall func3(int fd)
{
unsigned int v2; // ebx
int v3; // edi
int v4; // eax
char *v5; // rax
const char *v7; // rax
__int64 v8; // [rsp-Eh] [rbp-10080h] BYREF
char v9[32]; // [rsp+32h] [rbp-10040h] BYREF
__int64 buf[2]; // [rsp+52h] [rbp-10020h] BYREF
char s[65520]; // [rsp+62h] [rbp-10010h] BYREF

buf[0] = 0LL;
buf[1] = 0LL;
memset(s, 0, sizeof(s));
v2 = 0;
while ( 1 )
{
v4 = read(fd, (char *)buf + (int)v2, 0x10000LL - (int)v2);
if ( v4 < 0 )
{
v3 = *_errno_location();
if ( v3 != 4 )
{
v5 = strerror(v3);
fprintf(stderr, "read: %s\n", v5);
exit(-1);
}
goto LABEL_3;
}
if ( !v4 )
break;
v2 += v4;
LABEL_3:
if ( v2 > 0xFFFF )
goto LABEL_10;
}
if ( !v2 )
return v2;
LABEL_10:
write_chunk(buf, v9);
v7 = (const char *)_digest_string(v9, &v8);
printf("Stored chunk %s\n", v7);
return 1;
}

original_code:
static int do_store(int fd)
{
 unsigned char chunk[(1UL << 16)] = {0};
 unsigned char digest[20];
 int err, n, size = 0;
 while (size < (1UL << 16)) {
  n = read(fd, chunk + size, (1UL << 16) - size);
  if (n < 0) {
   if ((*__errno_location ()) == 4)
    continue;
   fprintf(stderr, "read: %s\n", strerror((*__errno_location ())));
   exit(-1);
  }
  if (!n)
   break;
  size += n;
 }
 if (!size)
  return 0;
 err = write_chunk(chunk, digest);
 if (err < 0) {
  fprintf(stderr, "write_chunk: %s\n", strerror(-err));
  exit(-1);
 }
 printf("Stored chunk %s\n", __digest_string(digest, __builtin_alloca ((20 * 2) + 1)));
 return 1;
}

canonical_original_code:
static int do_store(int fd)
{
 unsigned char chunk[-1] = {0};
 unsigned char digest[20];
 int err; int n; int size = 0;
 while (size < (1UL << 16)) {
  n = read(fd, chunk + size, (1UL << 16) - size);
  if (n < 0) {
   if ((*__errno_location ()) == 4)
    continue;
   fprintf(stderr, "read: %s\n", strerror((*__errno_location ())));
   exit(-1);
  }
  if (!n)
   break;
  size += n;
 }
 if (!size)
  return 0;
 err = write_chunk(chunk, digest);
 if (err < 0) {
  fprintf(stderr, "write_chunk: %s\n", strerror(-err));
  exit(-1);
 }
 printf("Stored chunk %s\n", __digest_string(digest, __builtin_alloca ((20 * 2) + 1)));
 return 1;
}

variable_types:
chunk
unsigned char [-1]

variable_types:
digest
unsigned char [20]

variable_types: n int

variable_types: size int


decompiled_code:
__int64 __fastcall verify_chunk(__int64 a1, __int64 a2)
{
return verify_digest(a2, a1, 0x10000LL);
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1, __int64 a2)
{
return verify_digest(a2, a1, 0x10000LL);
}

original_code:
static inline int verify_chunk(const unsigned char *chunk,
  const unsigned char *digest)
{
 return verify_digest(digest, chunk, (1UL << 16));
}

canonical_original_code:
static inline int verify_chunk(unsigned char *chunk, unsigned char *digest)
{
 return verify_digest(digest, chunk, (1UL << 16));
}


decompiled_code:
int __fastcall do_find(__int64 a1)
{
const char *v2; // rax
__int64 v3; // [rsp-Eh] [rbp-10050h] BYREF
__int64 v4[2]; // [rsp+32h] [rbp-10010h] BYREF
char s[65520]; // [rsp+42h] [rbp-10000h] BYREF

v4[0] = 0LL;
v4[1] = 0LL;
memset(s, 0, sizeof(s));
read_chunk(v4, a1);
if ( !(unsigned int)verify_chunk((__int64)v4, a1) )
return fwrite("Failed to verify received chunk.\n", 1uLL, 0x21uLL, stderr);
v2 = (const char *)_digest_string(a1, &v3);
return printf("Found chunk %s\n", v2);
}

canonical_decompiled_code:
int __fastcall func6(__int64 a1)
{
const char *v2; // rax
__int64 v3; // [rsp-Eh] [rbp-10050h] BYREF
__int64 v4[2]; // [rsp+32h] [rbp-10010h] BYREF
char s[65520]; // [rsp+42h] [rbp-10000h] BYREF

v4[0] = 0LL;
v4[1] = 0LL;
memset(s, 0, sizeof(s));
read_chunk(v4, a1);
if ( !(unsigned int)func5((__int64)v4, a1) )
return fwrite("Failed to verify received chunk.\n", 1uLL, 0x21uLL, stderr);
v2 = (const char *)_digest_string(a1, &v3);
return printf("Found chunk %s\n", v2);
}

original_code:
static void do_find(const unsigned char *digest)
{
 unsigned char chunk[(1UL << 16)] = {0};
 int err;
 err = read_chunk(chunk, digest);
 if (err < 0)
  fprintf(stderr, "read_chunk: %s\n", strerror(-err));
 else if (!verify_chunk(chunk, digest))
  fprintf(stderr, "Failed to verify received chunk.\n");
 else
  printf("Found chunk %s\n", __digest_string(digest, __builtin_alloca ((20 * 2) + 1)));
}

canonical_original_code:
static void do_find(unsigned char *digest)
{
 unsigned char chunk[-1] = {0};
 int err;
 err = read_chunk(chunk, digest);
 if (err < 0)
  fprintf(stderr, "read_chunk: %s\n", strerror(-err));
 else if (!verify_chunk(chunk, digest))
  fprintf(stderr, "Failed to verify received chunk.\n");
 else
  printf("Found chunk %s\n", __digest_string(digest, __builtin_alloca ((20 * 2) + 1)));
}


decompiled_code:
__int64 __fastcall read_chunk_from_file(const char *a1, unsigned int a2, __int64 a3)
{
int v4; // eax
int v5; // ebp
unsigned int v6; // ebx
int v7; // eax

v4 = open64(a1, 0);
if ( v4 < 0 )
return (unsigned int)-5;
v5 = v4;
if ( lseek64(v4, (unsigned __int64)a2 << 16, 0) != -1 )
{
v6 = 0;
while ( 1 )
{
v7 = read(v5, (void *)(a3 + (int)v6), 0x10000LL - (int)v6);
if ( v7 < 0 )
{
if ( *_errno_location() != 4 )
break;
}
else
{
if ( !v7 )
{
LABEL_11:
close(v5);
return v6;
}
v6 += v7;
}
if ( v6 > 0xFFFF )
goto LABEL_11;
}
}
close(v5);
return (unsigned int)-5;
}

canonical_decompiled_code:
__int64 __fastcall func0(const char *a1, unsigned int a2, __int64 a3)
{
int v4; // eax
int v5; // ebp
unsigned int v6; // ebx
int v7; // eax

v4 = open64(a1, 0);
if ( v4 < 0 )
return (unsigned int)-5;
v5 = v4;
if ( lseek64(v4, (unsigned __int64)a2 << 16, 0) != -1 )
{
v6 = 0;
while ( 1 )
{
v7 = read(v5, (void *)(a3 + (int)v6), 0x10000LL - (int)v6);
if ( v7 < 0 )
{
if ( *_errno_location() != 4 )
break;
}
else
{
if ( !v7 )
{
LABEL_11:
close(v5);
return v6;
}
v6 += v7;
}
if ( v6 > 0xFFFF )
goto LABEL_11;
}
}
close(v5);
return (unsigned int)-5;
}

original_code:
static int read_chunk_from_file(const char *path, unsigned nr,
  unsigned char *chunk)
{
 int len, n, fd;
 off_t offset;
 fd = open(path, 00);
 if (fd < 0)
  return -5;
 offset = (off_t)nr * (1UL << 16);
 if (lseek(fd, offset, 0) == (off_t)-1) {
  close(fd);
  return -5;
 }
 for (len = 0; len < (1UL << 16); ) {
  n = read(fd, chunk + len, (1UL << 16) - len);
  if (n < 0) {
   if ((*__errno_location ()) == 4)
    continue;
   close(fd);
   return -5;
  }
  if (!n)
   break;
  len += n;
 }
 close(fd);
 return len;
}

canonical_original_code:
static int read_chunk_from_file(char *path, unsigned int nr, unsigned char *chunk)
{
 int len; int n; int fd;
 long offset;
 fd = open(path, 00);
 if (fd < 0)
  return -5;
 offset = (long)nr * (1UL << 16);
 if (lseek(fd, offset, 0) == (off_t)-1) {
  close(fd);
  return -5;
 }
 for (len = 0; len < (1UL << 16); ) {
  n = read(fd, chunk + len, (1UL << 16) - len);
  if (n < 0) {
   if ((*__errno_location ()) == 4)
    continue;
   close(fd);
   return -5;
  }
  if (!n)
   break;
  len += n;
 }
 close(fd);
 return len;
}

variable_types:
path
char *

variable_types:
nr
unsigned int

variable_types: offset long


decompiled_code:
__int64 __fastcall sqlite3_query_callback(__int64 a1, unsigned int a2, const char **a3)
{
__int64 result; // rax
int *v5; // rbp
int v6; // er12

result = a2;
if ( a2 )
{
if ( a2 == 2 )
{
snprintf((char *)a1, 0x1000uLL, "%s", *a3);
*(_DWORD *)(a1 + 4096) = atoi(a3[1]);
result = 0LL;
}
else
{
result = 1LL;
if ( zunkfs_log_fp )
{
if ( zunkfs_log_level >= 0 )
{
v5 = _errno_location();
v6 = *v5;
_zprintf(0LL, "sqlite3_query_callback", 92LL, "Unexpected number of results: %d\n", a2);
*v5 = v6;
result = 1LL;
}
}
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1, unsigned int a2, const char **a3)
{
__int64 result; // rax
int *v5; // rbp
int v6; // er12

result = a2;
if ( a2 )
{
if ( a2 == 2 )
{
snprintf((char *)a1, 0x1000uLL, "%s", *a3);
*(_DWORD *)(a1 + 4096) = atoi(a3[1]);
result = 0LL;
}
else
{
result = 1LL;
if ( zunkfs_log_fp )
{
if ( zunkfs_log_level >= 0 )
{
v5 = _errno_location();
v6 = *v5;
_zprintf(0LL, "sqlite3_query_callback", 92LL, "Unexpected number of results: %d\n", a2);
*v5 = v6;
result = 1LL;
}
}
}
}
return result;
}

original_code:
static int sqlite3_query_callback(void *user_data, int argc, char **argv,
  char **column_names)
{
 struct chunk_map *cmap = user_data;
 if (argc == 0)
  return 0;
 if (argc != 2) {
  ({ int ___ret = 0; if (zunkfs_log_fp && (0) <= zunkfs_log_level) { int ___saved_errno = (*__errno_location ()); __zprintf(0, __FUNCTION__, 92, "Unexpected number of results: %d\n", argc); (*__errno_location ()) = ___saved_errno; ___ret = 1; } ___ret; });
  return 1;
 }
 snprintf(cmap->path, 4096, "%s", argv[0]);
 cmap->chunk_nr = atoi(argv[1]);
 return 0;
}

variable_types: argc int

variable_types:
argv
char **

variable_types: struct chunk_map { char path[4096]; int chunk_nr; } *


decompiled_code:
__int64 register_chunkdb_map_chunkdb_type()
{
return register_chunkdb(&map_chunkdb_type);
}

canonical_decompiled_code:
__int64 func5()
{
return register_chunkdb(&map_chunkdb_type);
}

original_code: static void __attribute__((constructor)) register_chunkdb_map_chunkdb_type(void) { register_chunkdb(&map_chunkdb_type); }

canonical_original_code: static void register_chunkdb_map_chunkdb_type() { register_chunkdb(&map_chunkdb_type); }


decompiled_code:
void __fastcall list_add(_QWORD *a1, __int64 a2)
{
_list_add(a1, a2, *(_QWORD **)(a2 + 8));
}

canonical_decompiled_code:
void __fastcall func2(_QWORD *a1, __int64 a2)
{
func1(a1, a2, *(_QWORD **)(a2 + 8));
}

original_code:
static inline void list_add(struct list_head *new, struct list_head *head)
{
 __list_add(new, head, head->next);
}

variable_types: struct list_head { struct list_head *prev; } *

variable_types:
head
struct list_head *


decompiled_code:
void __fastcall list_move(__int64 *a1, __int64 a2)
{
list_del(a1);
list_add(a1, a2);
}

canonical_decompiled_code:
void __fastcall func4(__int64 *a1, __int64 a2)
{
func3(a1);
func2(a1, a2);
}

original_code:
static inline void list_move(struct list_head *item, struct list_head *head)
{
 list_del(item);
 list_add(item, head);
}

user_defined_types: struct list_head { struct list_head *prev; }


decompiled_code:
__int64 register_chunkdb_sqlite_chunkdb_type()
{
return register_chunkdb(&sqlite_chunkdb_type);
}

canonical_decompiled_code:
__int64 func3()
{
return register_chunkdb(&sqlite_chunkdb_type);
}

original_code: static void __attribute__((constructor)) register_chunkdb_sqlite_chunkdb_type(void) { register_chunkdb(&sqlite_chunkdb_type); }

canonical_original_code: static void register_chunkdb_sqlite_chunkdb_type() { register_chunkdb(&sqlite_chunkdb_type); }


decompiled_code:
_BOOL8 __fastcall verify_digest(void *s2, __int64 a2, __int64 a3)
{
_BYTE v4[40]; // [rsp+0h] [rbp-28h] BYREF

SHA1(a2, a3, v4);
return memcmp(v4, s2, 0x14uLL) == 0;
}

canonical_decompiled_code:
_BOOL8 __fastcall func1(void *s2, __int64 a2, __int64 a3)
{
_BYTE v4[40]; // [rsp+0h] [rbp-28h] BYREF

SHA1(a2, a3, v4);
return memcmp(v4, s2, 0x14uLL) == 0;
}

original_code:
int verify_digest(const unsigned char *digest, const unsigned char *data,
  size_t data_size)
{
 unsigned char tmp_digest[20];
 SHA1(data, data_size, tmp_digest);
 return !memcmp(tmp_digest, digest, 20);
}

canonical_original_code:
int verify_digest(unsigned char *digest, unsigned char *data, unsigned long data_size)
{
 unsigned char tmp_digest[20];
 SHA1(data, data_size, tmp_digest);
 return !memcmp(tmp_digest, digest, 20);
}

variable_types:
data
unsigned char *


decompiled_code:
__int64 __fastcall digest_distance(__int64 a1, __int64 a2)
{
__int64 v2; // rdx
int v4; // eax

v2 = 0LL;
while ( 1 )
{
if ( !_BitScanForward((unsigned int *)&v4, *(_DWORD *)(a2 + 4 * v2) ^ *(_DWORD *)(a1 + 4 * v2)) )
v4 = -1;
if ( v4 != -1 )
break;
if ( ++v2 == 5 )
return 0xFFFFFFFFLL;
}
return (unsigned int)(160 - (v4 + 1) - 32 * v2);
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1, __int64 a2)
{
__int64 v2; // rdx
int v4; // eax

v2 = 0LL;
while ( 1 )
{
if ( !_BitScanForward((unsigned int *)&v4, *(_DWORD *)(a2 + 4 * v2) ^ *(_DWORD *)(a1 + 4 * v2)) )
v4 = -1;
if ( v4 != -1 )
break;
if ( ++v2 == 5 )
return 0xFFFFFFFFLL;
}
return (unsigned int)(160 - (v4 + 1) - 32 * v2);
}

original_code:
int digest_distance(const unsigned char *a, const unsigned char *b)
{
 const unsigned *ia = (void *)a;
 const unsigned *ib = (void *)b;
 int i;
 for (i = 0; i < (20 / sizeof(int)); i ++) {
  unsigned bit = ffs(ia[i] ^ ib[i]);
  if (bit)
   return (20 * 8) - (bit + i * 32);
 }
 return -1;
}

canonical_original_code:
int digest_distance(unsigned char *a, unsigned char *b)
{
 unsigned int *ia = (void *)a;
 unsigned int *ib = (void *)b;
 int i;
 for (i = 0; i < (20 / sizeof(int)); i ++) {
  unsigned int bit = ffs(ia[i] ^ ib[i]);
  if (bit)
   return (20 * 8) - (bit + i * 32);
 }
 return -1;
}

variable_types:
a
unsigned char *

variable_types:
b
unsigned char *

variable_types:
ia
unsigned int *

variable_types:
ib
unsigned int *

variable_types:
bit
unsigned int


decompiled_code:
_BOOL8 __fastcall IS_ERR(unsigned __int64 a1)
{
_BOOL8 result; // rax

result = 0LL;
if ( _errptr <= a1 )
result = a1 < _errptr + 256LL;
return result;
}

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

result = 0LL;
if ( _errptr <= a1 )
result = a1 < _errptr + 256LL;
return result;
}

original_code:
static inline int IS_ERR(const void *ptr)
{
 return ptr >= __errptr && ptr < __errptr + 256;
}

variable_types:
ptr
void *


decompiled_code:
__int64 __fastcall htole32(unsigned int a1)
{
return a1;
}

canonical_decompiled_code:
__int64 __fastcall func2(unsigned int a1)
{
return a1;
}

original_code: static inline le32_t htole32(uint32_t x) { return (le32_t){ x }; }

canonical_original_code: static inline struct le32_t htole32(unsigned int x) { return (struct le32_t){ x }; }

variable_types:
x
unsigned int

return_type: struct le32_t { unsigned int v; }


decompiled_code:
void __fastcall list_add_tail(_QWORD *a1, __int64 *a2)
{
_list_add(a1, *a2, a2);
}

canonical_decompiled_code:
void __fastcall func1(_QWORD *a1, __int64 *a2)
{
func0(a1, *a2, a2);
}

original_code:
static inline void list_add_tail(struct list_head *new, struct list_head *head)
{
 __list_add(new, head->prev, head);
}


main

canonical_name: main

original_code:
int main( int argc, char **argv )
{
  srand(time(((void *)0)));
 for( int n = 101; n < 102; n = n+1+n/3 )
 {
  for( int m = 10001; m < 10002; m = m+1+m/3 )
  {
    float *A = (float*) malloc( m * n * sizeof(float) );
    float *B = (float*) malloc( n * m * sizeof(float) );
    float *C = (float*) malloc( m * m * sizeof(float) );
    for( int i = 0; i < m*n; i++ ) A[i] = 2 * drand48() - 1;
    for( int i = 0; i < n*m; i++ ) B[i] = 2 * drand48() - 1;
    for( int i = 0; i < m*m; i++ ) C[i] = 2 * drand48() - 1;
    double Gflop_s, seconds = -1.0;
    for( int n_iterations = 1; seconds < 0.1; n_iterations *= 2 )
    {
 sgemm( m, n, A, B, C );
      struct timeval start, end;
      gettimeofday( &start, ((void *)0) );
      for( int i = 0; i < n_iterations; i++ )
   sgemm( m,n, A, B, C );
      gettimeofday( &end, ((void *)0) );
      seconds = (end.tv_sec - start.tv_sec) + 1.0e-6 * (end.tv_usec - start.tv_usec);
      Gflop_s = 2e-9 * n_iterations * m * m * n / seconds;
    }
    printf( "%d by %d matrix \t %g Gflop/s\n", m, n, Gflop_s );
    memset( C, 0, sizeof( float ) * m * m );
    if(0){
    for (int x = 0; x<m; x++){
      printf("|");
      for (int y = 0; y<m; y++){
        printf("%.2f|", C[y*m+x]);
      }
      printf("\n");
    }
    }
    sgemm( m,n, A, B, C );
    if(0){
    for (int x = 0; x<m; x++){
      printf("|");
      for (int y = 0; y<m; y++){
        printf("%.2f|", C[y*m+x]);
      }
      printf("\n");
    }
    }
    cblas_sgemm( CblasColMajor,CblasNoTrans,CblasTrans, m,m,n, -1, A,m, B,m, 1, C,m );
    for( int i = 0; i < m*n; i++ ) A[i] = fabs( A[i] );
    for( int i = 0; i < m*n; i++ ) B[i] = fabs( B[i] );
    for( int i = 0; i < m*m; i++ ) C[i] = fabs( C[i] );
    cblas_sgemm( CblasColMajor,CblasNoTrans,CblasTrans, m,m,n, -3.0*1.19209289550781250000000000000000000e-7F*n, A,m, B,m, 1, C,m );
    for( int i = 0; i < m * m; i++ )
      if( C[i] > 0 ) {
 printf( "FAILURE: error in matrix multiply exceeds an acceptable margin\n" );
 return -1;
      }
    free( C );
    free( B );
    free( A );
  }
 }
  return 0;
}

canonical_original_code:
int main(int argc, char **argv)
{
  srand(time(((void *)0)));
 for( int n = 101; n < 102; n = n+1+n/3 )
 {
  for( int m = 10001; m < 10002; m = m+1+m/3 )
  {
    float *A = (float*) malloc( m * n * sizeof(float) );
    float *B = (float*) malloc( n * m * sizeof(float) );
    float *C = (float*) malloc( m * m * sizeof(float) );
    for( int i = 0; i < m*n; i++ ) A[i] = 2 * drand48() - 1;
    for( int i = 0; i < n*m; i++ ) B[i] = 2 * drand48() - 1;
    for( int i = 0; i < m*m; i++ ) C[i] = 2 * drand48() - 1;
    double Gflop_s; double seconds = -1.0;
    for( int n_iterations = 1; seconds < 0.1; n_iterations *= 2 )
    {
 sgemm( m, n, A, B, C );
      struct timeval start; struct timeval end;
      gettimeofday( &start, ((void *)0) );
      for( int i = 0; i < n_iterations; i++ )
   sgemm( m,n, A, B, C );
      gettimeofday( &end, ((void *)0) );
      seconds = (end.tv_sec - start.tv_sec) + 1.0e-6 * (end.tv_usec - start.tv_usec);
      Gflop_s = 2e-9 * n_iterations * m * m * n / seconds;
    }
    printf( "%d by %d matrix \t %g Gflop/s\n", m, n, Gflop_s );
    memset( C, 0, sizeof( float ) * m * m );
    if(0){
    for (int x = 0; x<m; x++){
      printf("|");
      for (int y = 0; y<m; y++){
        printf("%.2f|", C[y*m+x]);
      }
      printf("\n");
    }
    }
    sgemm( m,n, A, B, C );
    if(0){
    for (int x = 0; x<m; x++){
      printf("|");
      for (int y = 0; y<m; y++){
        printf("%.2f|", C[y*m+x]);
      }
      printf("\n");
    }
    }
    cblas_sgemm( CblasColMajor,CblasNoTrans,CblasTrans, m,m,n, -1, A,m, B,m, 1, C,m );
    for( int i = 0; i < m*n; i++ ) A[i] = fabs( A[i] );
    for( int i = 0; i < m*n; i++ ) B[i] = fabs( B[i] );
    for( int i = 0; i < m*m; i++ ) C[i] = fabs( C[i] );
    cblas_sgemm( CblasColMajor,CblasNoTrans,CblasTrans, m,m,n, -3.0*1.19209289550781250000000000000000000e-7F*n, A,m, B,m, 1, C,m );
    for( int i = 0; i < m * m; i++ )
      if( C[i] > 0 ) {
 printf( "FAILURE: error in matrix multiply exceeds an acceptable margin\n" );
 return -1;
      }
    free( C );
    free( B );
    free( A );
  }
 }
  return 0;
}

variable_types: n int

variable_types: m int

variable_types:
A
float *

variable_types:
B
float *

variable_types:
C
float *

variable_types: i int

variable_types: seconds double

variable_types: struct timeval { long tv_sec; long tv_usec; }

variable_types: x int

variable_types: y int


repo: dbacarel/Dplan

decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
const char *v3; // rbx
__int64 v4; // rbx
int v5; // er12
void **v6; // rbp
__int64 v7; // rax
__int64 i; // rbx
__int64 j; // rbx
DIR *v10; // r13
int v11; // er14
void *v12; // r15
struct dirent *v13; // rax
__int64 v14; // rcx
char *v15; // rdi
const char *v16; // rbx
FILE *v17; // rbp
void *ptr; // [rsp+8h] [rbp-1F0h]
void *thread_return; // [rsp+18h] [rbp-1E0h] BYREF
char s[120]; // [rsp+20h] [rbp-1D8h] BYREF
pthread_t newthread; // [rsp+98h] [rbp-160h] BYREF
sigset_t set; // [rsp+A0h] [rbp-158h] BYREF
struct sigaction v23; // [rsp+120h] [rbp-D8h] BYREF

memset(&v23, 0, sizeof(v23));
if ( sigemptyset(&set) >= 0 )
{
if ( sigaddset(&set, 15) >= 0 )
{
if ( pthread_sigmask(0, &set, 0LL) >= 0 )
{
v23.sa_handler = (__sighandler_t)(main + 1);
if ( sigaction(13, &v23, 0LL) >= 0 )
{
if ( argc != 1 )
{
v3 = argv[1];
if ( strlen(v3) > 0x6C )
exit(1);
strcpy(path_dir_agende, v3);
agende = 0LL;
thread_return = 0LL;
a_size = 10;
offset = 0;
tid_disp = -1LL;
nomi_agende = malloc(0x50uLL);
v4 = 0LL;
if ( nomi_agende )
{
while ( 1 )
{
v5 = v4;
v6 = (void **)((char *)nomi_agende + 8 * v4);
*v6 = malloc(0x15uLL);
if ( !*((_QWORD *)nomi_agende + v4) )
break;
if ( a_size <= (int)++v4 )
{
agende = malloc(8LL * a_size);
v7 = 0LL;
if ( !agende )
{
puts("Problemi durante il settaggio delle strutture dati");
free(nomi_agende);
for ( i = 0LL; a_size > (int)i; ++i )
free(*((void **)nomi_agende + i));
free(nomi_agende);
exit(1);
}
while ( a_size > (int)v7 )
*((_QWORD *)agende + v7++) = 0LL;
v10 = opendir(path_dir_agende);
if ( !v10 && *_errno_location() == 2 && mkdir(path_dir_agende, 0x1C0u) )
{
perror(&byte_632);
exit(1);
}
v11 = 0;
while ( 1 )
{
v13 = readdir(v10);
if ( !v13 )
break;
if ( v13->d_type == 8 )
{
v14 = 27LL;
v15 = s;
while ( v14 )
{
*(_DWORD *)v15 = 0;
v15 += 4;
--v14;
}
v16 = v13->d_name;
sprintf(s, "%s/%s", path_dir_agende, v13->d_name);
v17 = fopen(s, "r");
if ( v17 )
{
if ( a_size == v11 )
{
v12 = agende;
ptr = nomi_agende;
agende = (void *)enlarge_array(65LL);
if ( !agende )
{
puts("Problemi durante l'allocazione di mem");
cleanup();
exit(1);
}
nomi_agende = (void *)enlarge_array(78LL);
if ( !nomi_agende )
{
puts("Problemi durante l'allocazione di mem");
free(agende);
cleanup();
exit(1);
}
a_size += 10;
free(v12);
free(ptr);
}
if ( (int)loadAgenda(v17, (char *)agende + 8 * v11) >= 0 && strlen(v16) <= 0x14 )
{
strncpy(*((char **)nomi_agende + v11), v16, 0x15uLL);
++offset;
++v11;
}
fclose(v17);
}
}
}
closedir(v10);
thread_return = 0LL;
if ( pthread_create(&tid_disp, 0LL, (void *(*)(void *))&thread_dispatcher, 0LL) )
perror("Errore durante la creazione del thread dispatcher");
sleep(1u);
if ( pthread_create(&newthread, 0LL, (void *(*)(void *))&thread_sigHandler, 0LL) )
perror("Errore durante la creazione del thread dispatcher");
pthread_join(newthread, &thread_return);
exit(0);
}
}
puts("Problemi durante il settaggio delle strutture dati");
for ( j = 0LL; v5 > (int)j; ++j )
free(*((void **)nomi_agende + j));
free(nomi_agende);
exit(1);
}
puts("Problemi durante il settaggio delle strutture dati");
exit(1);
}
puts("Usage: dserver PATH_DIR_AGENDE");
exit(1);
}
exit(1);
}
exit(1);
}
exit(1);
}
exit(1);
}

original_code:
int main(int argc, char **argv)
{
    int arg, tmp, tipo;
    short int flags[7];
    char *args[7];
    char *agenda;
    channel_t chan;
    message_t *mess;
    for (tmp = 0; tmp < 7; tmp++)
 flags[tmp] = 0;
    for (tmp = 0; tmp < 7; tmp++)
 args[tmp] = ((void *)0);
    if (argc == 1 || argc == 2) {
 printHelp();
 exit(0);
    }
    while ((arg = getopt(argc, argv, ":cqd:u:g:m:r:")) != -1) {
 switch (arg) {
 case 'c':
     if (checkOpts(flags, 2))
  { printf("dplan: Formato scorretto del comando\n"); exit(1);}
      else
  setInfo(flags, 2, &tipo, 'C', args, ((void *)0));
     break;
 case 'd':
     if (checkOpts(flags, 0))
  { printf("dplan: Formato scorretto del comando\n"); exit(1);}
      else
  setInfo(flags, 0, &tipo, 'D', args, optarg);
     break;
 case 'q':
     if (checkOpts(flags, 3))
  { printf("dplan: Formato scorretto del comando\n"); exit(1);}
      else
  setInfo(flags, 3, &tipo, 'Q', args, ((void *)0));
     break;
 case 'r':
     if (checkOpts(flags, 4))
  { printf("dplan: Formato scorretto del comando\n"); exit(1);}
      else
  setInfo(flags, 4, &tipo, 'R', args, optarg);
     break;
 case 'g':
     if (checkOpts(flags, 5))
  { printf("dplan: Formato scorretto del comando\n"); exit(1);}
      else
  setInfo(flags, 5, &tipo, 'G', args, optarg);
     break;
 case 'm':
     if (checkOpts(flags, 6))
  { printf("dplan: Formato scorretto del comando\n"); exit(1);}
      else
  setInfo(flags, 6, &tipo, 'M', args, optarg);
     break;
 case 'u':
     if (checkOpts(flags, 1))
  { printf("dplan: Formato scorretto del comando\n"); exit(1);}
      else
  setInfo(flags, 1, &tipo, 'D', args, optarg);
     break;
 default:
     printf("dplan: -%c: Opzione errata\n", optopt);
     exit(1);
     ;
 }
    }
    if (flags[0] || flags[1]) {
 if (!(flags[0] && flags[1])) {
     printf("dplan: Formato scorretto del comando\n");
     exit(1);
 }
    }
    if (checkArgs(flags, argc, argv, args, &agenda))
 exit(1);
    chan = -1;
    tmp = -1;
    while (chan < 0 && (++tmp < 5)) {
 chan = openConnection("./tmp/");
 sleep(1);
    }
    if (tmp == 5)
 exit(1);
    mess = (message_t *) calloc(1, sizeof(message_t));
    mess->type = tipo;
    mess->buffer = getBufferString(tipo, agenda, args, &(mess->length));
    sendMessage(chan, mess);
    free(mess->buffer);
    mess->buffer = ((void *)0);
    mess->length = 0;
    mess->type = '0';
    receiveMessage(chan, mess);
    if (tipo == 'G' || tipo == 'M') {
 if (mess->type == '0') {
     printf("dplan: %s: %s\n", agenda, mess->buffer);
     free(mess->buffer);
     while (receiveMessage(chan, mess) >= 0) {
  printf("dplan: %s: %s\n", agenda, mess->buffer);
  free(mess->buffer);
     }
 } else {
     printf("dplan: %s: %s\n", agenda, mess->buffer);
     free(mess->buffer);
 }
    } else {
 if (tipo == 'R') {
     if (mess->type == '0')
  printf("dplan: %s: %s\n", args[4], mess->buffer);
     else
  printf("dplan: %s: %s\n", agenda, mess->buffer);
 } else if (tipo == 'D')
     printf("dplan: %s: %s\n", args[0], mess->buffer);
 else
     printf("dplan: %s: %s\n", agenda, mess->buffer);
 free(mess->buffer);
    }
    free(mess);
    closeConnection(chan);
    exit(0);
}

canonical_original_code:
int main(int argc, char **argv)
{
    int arg; int tmp; int tipo;
    short flags[7];
    char *args[7];
    char *agenda;
    int chan;
    struct message_t *mess;
    for (tmp = 0; tmp < 7; tmp++)
 flags[tmp] = 0;
    for (tmp = 0; tmp < 7; tmp++)
 args[tmp] = ((void *)0);
    if (argc == 1 || argc == 2) {
 printHelp();
 exit(0);
    }
    while ((arg = getopt(argc, argv, ":cqd:u:g:m:r:")) != -1) {
 switch (arg) {
 case 'c':
     if (checkOpts(flags, 2))
  { printf("dplan: Formato scorretto del comando\n"); exit(1);}
      else
  setInfo(flags, 2, &tipo, 'C', args, ((void *)0));
     break;
 case 'd':
     if (checkOpts(flags, 0))
  { printf("dplan: Formato scorretto del comando\n"); exit(1);}
      else
  setInfo(flags, 0, &tipo, 'D', args, optarg);
     break;
 case 'q':
     if (checkOpts(flags, 3))
  { printf("dplan: Formato scorretto del comando\n"); exit(1);}
      else
  setInfo(flags, 3, &tipo, 'Q', args, ((void *)0));
     break;
 case 'r':
     if (checkOpts(flags, 4))
  { printf("dplan: Formato scorretto del comando\n"); exit(1);}
      else
  setInfo(flags, 4, &tipo, 'R', args, optarg);
     break;
 case 'g':
     if (checkOpts(flags, 5))
  { printf("dplan: Formato scorretto del comando\n"); exit(1);}
      else
  setInfo(flags, 5, &tipo, 'G', args, optarg);
     break;
 case 'm':
     if (checkOpts(flags, 6))
  { printf("dplan: Formato scorretto del comando\n"); exit(1);}
      else
  setInfo(flags, 6, &tipo, 'M', args, optarg);
     break;
 case 'u':
     if (checkOpts(flags, 1))
  { printf("dplan: Formato scorretto del comando\n"); exit(1);}
      else
  setInfo(flags, 1, &tipo, 'D', args, optarg);
     break;
 default:
     printf("dplan: -%c: Opzione errata\n", optopt);
     exit(1);
     ;
 }
    }
    if (flags[0] || flags[1]) {
 if (!(flags[0] && flags[1])) {
     printf("dplan: Formato scorretto del comando\n");
     exit(1);
 }
    }
    if (checkArgs(flags, argc, argv, args, &agenda))
 exit(1);
    chan = -1;
    tmp = -1;
    while (chan < 0 && (++tmp < 5)) {
 chan = openConnection("./tmp/");
 sleep(1);
    }
    if (tmp == 5)
 exit(1);
    mess = (struct message_t *) calloc(1, sizeof(message_t));
    mess->type = tipo;
    mess->buffer = getBufferString(tipo, agenda, args, &(mess->length));
    sendMessage(chan, mess);
    free(mess->buffer);
    mess->buffer = ((void *)0);
    mess->length = 0;
    mess->type = '0';
    receiveMessage(chan, mess);
    if (tipo == 'G' || tipo == 'M') {
 if (mess->type == '0') {
     printf("dplan: %s: %s\n", agenda, mess->buffer);
     free(mess->buffer);
     while (receiveMessage(chan, mess) >= 0) {
  printf("dplan: %s: %s\n", agenda, mess->buffer);
  free(mess->buffer);
     }
 } else {
     printf("dplan: %s: %s\n", agenda, mess->buffer);
     free(mess->buffer);
 }
    } else {
 if (tipo == 'R') {
     if (mess->type == '0')
  printf("dplan: %s: %s\n", args[4], mess->buffer);
     else
  printf("dplan: %s: %s\n", agenda, mess->buffer);
 } else if (tipo == 'D')
     printf("dplan: %s: %s\n", args[0], mess->buffer);
 else
     printf("dplan: %s: %s\n", agenda, mess->buffer);
 free(mess->buffer);
    }
    free(mess);
    closeConnection(chan);
    exit(0);
}

variable_types: argc int

variable_types:
argv
char **

variable_types: arg int

variable_types: tmp int

variable_types: tipo int

variable_types:
flags
short [7]

variable_types:
args
char *[7]

variable_types:
agenda
char *

variable_types: chan int

variable_types: struct message_t { char type; unsigned int length; char *buffer; } *


createServerChannel

decompiled_code:
__int64 __fastcall createServerChannel(char *src)
{
size_t v1; // rax
int v2; // eax
unsigned int v3; // ebx

if ( strlen(src) > 0x6C )
return (unsigned int)-11;
strcpy(sockadr.sa_data, src);
v1 = strlen(sockadr.sa_data);
*(_DWORD *)&sockadr.sa_data[v1] = 1668248420;
*(_WORD *)&sockadr.sa_data[v1 + 4] = 107;
sockadr.sa_family = 1;
unlink(sockadr.sa_data);
v2 = socket(1, 1, 0);
v3 = v2;
if ( v2 < 0 )
return (unsigned int)-1;
if ( bind(v2, &sockadr, 0x6Eu) < 0 )
return (unsigned int)-1;
if ( listen(v3, 128) < 0 )
v3 = -1;
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func0(char *src)
{
size_t v1; // rax
int v2; // eax
unsigned int v3; // ebx

if ( strlen(src) > 0x6C )
return (unsigned int)-11;
strcpy(sockadr.sa_data, src);
v1 = strlen(sockadr.sa_data);
*(_DWORD *)&sockadr.sa_data[v1] = 1668248420;
*(_WORD *)&sockadr.sa_data[v1 + 4] = 107;
sockadr.sa_family = 1;
unlink(sockadr.sa_data);
v2 = socket(1, 1, 0);
v3 = v2;
if ( v2 < 0 )
return (unsigned int)-1;
if ( bind(v2, &sockadr, 0x6Eu) < 0 )
return (unsigned int)-1;
if ( listen(v3, 128) < 0 )
v3 = -1;
return v3;
}

original_code:
serverChannel_t createServerChannel(const char *path)
{
    serverChannel_t fd_sock;
    if (strlen(path) > 108)
 return -11;
    strcpy(sockadr.sun_path, path);
    strncat(sockadr.sun_path, "dsock", strlen("dsock"));
    sockadr.sun_family = 1;
    (void) unlink(sockadr.sun_path);
    fd_sock = socket(1, SOCK_STREAM, 0);
    if (fd_sock < 0)
 return -1;
    if (bind(fd_sock, (struct sockaddr *) &sockadr, sizeof(sockadr)) < 0)
 return -1;
    if (listen(fd_sock, 128) < 0)
 return -1;
    return fd_sock;
}

canonical_original_code:
int createServerChannel(char *path)
{
    int fd_sock;
    if (strlen(path) > 108)
 return -11;
    strcpy(sockadr.sun_path, path);
    strncat(sockadr.sun_path, "dsock", strlen("dsock"));
    sockadr.sun_family = 1;
    (void) unlink(sockadr.sun_path);
    fd_sock = socket(1, SOCK_STREAM, 0);
    if (fd_sock < 0)
 return -1;
    if (bind(fd_sock, (struct sockaddr *) &sockadr, sizeof(sockadr)) < 0)
 return -1;
    if (listen(fd_sock, 128) < 0)
 return -1;
    return fd_sock;
}

variable_types:
path
char *

user_defined_types: struct sockaddr { unsigned short sa_family; char sa_data[14]; }


closeSocket

decompiled_code:
__int64 __fastcall closeSocket(int a1)
{
unsigned int v1; // ebx

v1 = close(a1);
unlink(sockadr.sa_data);
return v1;
}

canonical_decompiled_code:
__int64 __fastcall func1(int a1)
{
unsigned int v1; // ebx

v1 = close(a1);
unlink(sockadr.sa_data);
return v1;
}

original_code:
int closeSocket(serverChannel_t s)
{
    int i;
    i = close(s);
    (void) unlink(sockadr.sun_path);
    return i;
}

canonical_original_code:
int closeSocket(int s)
{
    int i;
    i = close(s);
    (void) unlink(sockadr.sun_path);
    return i;
}

variable_types: s int


acceptConnection

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

if ( a1 < 0 )
{
*_errno_location() = 22;
result = -1;
}
else
{
result = accept(a1, 0LL, 0LL);
if ( result < 0 )
result = -1;
}
return result;
}

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

if ( a1 < 0 )
{
*_errno_location() = 22;
result = -1;
}
else
{
result = accept(a1, 0LL, 0LL);
if ( result < 0 )
result = -1;
}
return result;
}

original_code:
channel_t acceptConnection(serverChannel_t s)
{
    channel_t fd_client;
    if (s < 0) {
 (*__errno_location ()) = 22;
 return -1;
    }
    fd_client = accept(s, ((void *)0), 0);
    if (fd_client < 0)
 return -1;
    return fd_client;
}

canonical_original_code:
int acceptConnection(int s)
{
    int fd_client;
    if (s < 0) {
 (*__errno_location ()) = 22;
 return -1;
    }
    fd_client = accept(s, ((void *)0), 0);
    if (fd_client < 0)
 return -1;
    return fd_client;
}


receiveMessage

decompiled_code:
__int64 __fastcall receiveMessage(int fd, _QWORD *a2)
{
int v3; // eax
int v4; // eax
size_t v5; // r12
void *v6; // rsi
int v7; // eax
__int64 result; // rax

if ( a2 )
{
v3 = read(fd, a2, 8uLL);
if ( v3 < 0 )
{
result = 0xFFFFFFFFLL;
}
else if ( v3 )
{
v4 = read(fd, (char *)a2 + 4, 8uLL);
if ( v4 < 0 )
{
result = 0xFFFFFFFFLL;
}
else if ( v4 )
{
v5 = *((unsigned int *)a2 + 1);
v6 = malloc(v5);
a2[1] = v6;
if ( v6 )
{
v7 = read(fd, v6, v5);
if ( v7 < 0 )
{
result = 0xFFFFFFFFLL;
}
else if ( v7 )
{
result = *((unsigned int *)a2 + 1);
}
else
{
result = 4294967294LL;
}
}
else
{
*_errno_location() = 12;
perror("LCSCOM: Allocating memory for message's buffer ");
result = 0xFFFFFFFFLL;
}
}
else
{
result = 4294967294LL;
}
}
else
{
result = 4294967294LL;
}
}
else
{
*_errno_location() = 22;
result = 0xFFFFFFFFLL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(int fd, _QWORD *a2)
{
int v3; // eax
int v4; // eax
size_t v5; // r12
void *v6; // rsi
int v7; // eax
__int64 result; // rax

if ( a2 )
{
v3 = read(fd, a2, 8uLL);
if ( v3 < 0 )
{
result = 0xFFFFFFFFLL;
}
else if ( v3 )
{
v4 = read(fd, (char *)a2 + 4, 8uLL);
if ( v4 < 0 )
{
result = 0xFFFFFFFFLL;
}
else if ( v4 )
{
v5 = *((unsigned int *)a2 + 1);
v6 = malloc(v5);
a2[1] = v6;
if ( v6 )
{
v7 = read(fd, v6, v5);
if ( v7 < 0 )
{
result = 0xFFFFFFFFLL;
}
else if ( v7 )
{
result = *((unsigned int *)a2 + 1);
}
else
{
result = 4294967294LL;
}
}
else
{
*_errno_location() = 12;
perror("LCSCOM: Allocating memory for message's buffer ");
result = 0xFFFFFFFFLL;
}
}
else
{
result = 4294967294LL;
}
}
else
{
result = 4294967294LL;
}
}
else
{
*_errno_location() = 22;
result = 0xFFFFFFFFLL;
}
return result;
}

original_code:
int receiveMessage(channel_t sc, message_t * msg)
{
    int c;
    if (msg == ((void *)0)) {
 (*__errno_location ()) = 22;
 return -1;
    }
    c = read(sc, &(msg->type), sizeof(&(msg->type)));
    if(c < 0 ) {return -1;};
    if(c == 0 ) {return -2;};
    c = read(sc, &(msg->length), sizeof(&(msg->length)));
    if(c < 0 ) {return -1;};
    if(c == 0 ) {return -2;};
    msg->buffer = (char *) malloc(sizeof(char) * msg->length);
    if (msg->buffer == ((void *)0)) {
 (*__errno_location ()) = 12;
 perror("LCSCOM: Allocating memory for message's buffer ");
 return -1;
    }
    c = read(sc, msg->buffer, msg->length);
    if(c < 0 ) {return -1;};
    if(c == 0 ) {return -2;};
    return msg->length;
}

canonical_original_code:
int receiveMessage(int sc, struct message_t *msg)
{
    int c;
    if (msg == ((void *)0)) {
 (*__errno_location ()) = 22;
 return -1;
    }
    c = read(sc, &(msg->type), sizeof(&(msg->type)));
    if(c < 0 ) {return -1;};
    if(c == 0 ) {return -2;};
    c = read(sc, &(msg->length), sizeof(&(msg->length)));
    if(c < 0 ) {return -1;};
    if(c == 0 ) {return -2;};
    msg->buffer = (char *) malloc(sizeof(char) * msg->length);
    if (msg->buffer == ((void *)0)) {
 (*__errno_location ()) = 12;
 perror("LCSCOM: Allocating memory for message's buffer ");
 return -1;
    }
    c = read(sc, msg->buffer, msg->length);
    if(c < 0 ) {return -1;};
    if(c == 0 ) {return -2;};
    return msg->length;
}

variable_types: sc int

variable_types: c int

user_defined_types: struct message_t { char type; unsigned int length; char *buffer; }


sendMessage

decompiled_code:
ssize_t __fastcall sendMessage(int fd, void *buf)
{
ssize_t result; // rax

if ( buf || *(_QWORD *)((char *)&loc_4 + 4) )
{
if ( (int)write(fd, buf, 8uLL) < 0 )
{
result = 0xFFFFFFFFLL;
}
else if ( (int)write(fd, (char *)buf + 4, 8uLL) < 0 )
{
result = 0xFFFFFFFFLL;
}
else
{
result = write(fd, *((const void **)buf + 1), *((unsigned int *)buf + 1));
if ( (int)result < 0 )
result = 0xFFFFFFFFLL;
}
}
else
{
*_errno_location() = 22;
result = 0xFFFFFFFFLL;
}
return result;
}

canonical_decompiled_code:
ssize_t __fastcall func4(int fd, void *buf)
{
ssize_t result; // rax

if ( buf || *(_QWORD *)((char *)&loc_4 + 4) )
{
if ( (int)write(fd, buf, 8uLL) < 0 )
{
result = 0xFFFFFFFFLL;
}
else if ( (int)write(fd, (char *)buf + 4, 8uLL) < 0 )
{
result = 0xFFFFFFFFLL;
}
else
{
result = write(fd, *((const void **)buf + 1), *((unsigned int *)buf + 1));
if ( (int)result < 0 )
result = 0xFFFFFFFFLL;
}
}
else
{
*_errno_location() = 22;
result = 0xFFFFFFFFLL;
}
return result;
}

original_code:
int sendMessage(channel_t sc, message_t * msg)
{
    int c;
    if (msg == ((void *)0) && msg->buffer == ((void *)0)) {
 (*__errno_location ()) = 22;
 return -1;
    }
    c = write(sc, &(msg->type), sizeof(&(msg->type)));
    if(c < 0 ) {return -1;};
    c = write(sc, &(msg->length), sizeof(&(msg->length)));
    if(c < 0 ) {return -1;};
    c = write(sc, msg->buffer, msg->length);
    if(c < 0 ) {return -1;};
    return c;
}

canonical_original_code:
int sendMessage(int sc, struct message_t *msg)
{
    int c;
    if (msg == ((void *)0) && msg->buffer == ((void *)0)) {
 (*__errno_location ()) = 22;
 return -1;
    }
    c = write(sc, &(msg->type), sizeof(&(msg->type)));
    if(c < 0 ) {return -1;};
    c = write(sc, &(msg->length), sizeof(&(msg->length)));
    if(c < 0 ) {return -1;};
    c = write(sc, msg->buffer, msg->length);
    if(c < 0 ) {return -1;};
    return c;
}


closeConnection

decompiled_code:
int __fastcall closeConnection(int a1)
{
return close(a1);
}

canonical_decompiled_code:
int __fastcall func5(int a1)
{
return close(a1);
}

original_code:
int closeConnection(channel_t sc)
{
    return close(sc);
}

canonical_original_code:
int closeConnection(int sc)
{
    return close(sc);
}


openConnection

decompiled_code:
__int64 __fastcall openConnection(const char *a1)
{
int v1; // eax
unsigned int v2; // ebx
struct sockaddr v4[7]; // [rsp+0h] [rbp-78h] BYREF

if ( strlen(a1) > 0x6C )
{
*_errno_location() = 36;
v2 = -11;
}
else
{
strcpy(v4[0].sa_data, "./tmp/");
strcat(v4[0].sa_data, "dsock");
v4[0].sa_family = 1;
v1 = socket(1, 1, 0);
v2 = v1;
if ( v1 < 0 )
{
v2 = -1;
}
else if ( connect(v1, v4, 0x6Eu) < 0 )
{
v2 = -1;
}
}
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func6(const char *a1)
{
int v1; // eax
unsigned int v2; // ebx
struct sockaddr v4[7]; // [rsp+0h] [rbp-78h] BYREF

if ( strlen(a1) > 0x6C )
{
*_errno_location() = 36;
v2 = -11;
}
else
{
strcpy(v4[0].sa_data, "./tmp/");
strcat(v4[0].sa_data, "dsock");
v4[0].sa_family = 1;
v1 = socket(1, 1, 0);
v2 = v1;
if ( v1 < 0 )
{
v2 = -1;
}
else if ( connect(v1, v4, 0x6Eu) < 0 )
{
v2 = -1;
}
}
return v2;
}

original_code:
channel_t openConnection(const char *path)
{
    struct sockaddr_un sock;
    channel_t fd_sock;
    if (strlen(path) > 108) {
 (*__errno_location ()) = 36;
 return -11;
    }
    strcpy(sock.sun_path, "./tmp/");
    strncat(sock.sun_path, "dsock", strlen("dsock"));
    sock.sun_family = 1;
    fd_sock = socket(1, SOCK_STREAM, 0);
    if(fd_sock < 0 ) {return -1;};
    if(connect(fd_sock, (struct sockaddr *) &sock, sizeof(sockadr)) < 0 ) {return -1;};
    return fd_sock;
}

canonical_original_code:
int openConnection(char *path)
{
    struct sockaddr_un sock;
    int fd_sock;
    if (strlen(path) > 108) {
 (*__errno_location ()) = 36;
 return -11;
    }
    strcpy(sock.sun_path, "./tmp/");
    strncat(sock.sun_path, "dsock", strlen("dsock"));
    sock.sun_family = 1;
    fd_sock = socket(1, SOCK_STREAM, 0);
    if(fd_sock < 0 ) {return -1;};
    if(connect(fd_sock, (struct sockaddr *) &sock, sizeof(sockadr)) < 0 ) {return -1;};
    return fd_sock;
}

variable_types: struct sockaddr_un { unsigned short sun_family; char sun_path[108]; }


printHelp

decompiled_code:
int printHelp()
{
puts(
"Usage: dplan [ agenda [ -d gg-mm-aaaa -u utente#descrizione] [ -g gg-mm-aaaa ] [ -m mm-aaaa ] [ -r pattern ] ] [-cq aname]");
puts(aCCreaUnaNuovaA);
puts(aQRimuoveUnaAge);
puts("\t-d\tspecifica la data");
puts(aUSpecificaL);
puts(aGRichiedeGliEv);
puts(aMRichiedeGliEv);
return puts(aREliminaTuttiG);
}

canonical_decompiled_code:
int func0()
{
puts(
"Usage: dplan [ agenda [ -d gg-mm-aaaa -u utente#descrizione] [ -g gg-mm-aaaa ] [ -m mm-aaaa ] [ -r pattern ] ] [-cq aname]");
puts(aCCreaUnaNuovaA);
puts(aQRimuoveUnaAge);
puts("\t-d\tspecifica la data");
puts(aUSpecificaL);
puts(aGRichiedeGliEv);
puts(aMRichiedeGliEv);
return puts(aREliminaTuttiG);
}

original_code:
void printHelp(void)
{
    printf
 ("Usage:  dplan [ agenda [ -d gg-mm-aaaa -u utente#descrizione] [ -g gg-mm-aaaa ] [ -m mm-aaaa ] [ -r pattern ]  ] [-cq aname]\n");
    printf("\t-c\tcrea una nuova agenda di nome ‘‘aname’’\n");
    printf
 ("\t-q\trimuove una agenda di nome ‘‘aname’’ (solo se vuota)\n");
    printf("\t-d\tspecifica la data\n");
    printf
 ("\t-u\tspecifica l’utente che sta effettuando la registrazione e la descrizione dell’evento\n");
    printf
 ("\t-g\trichiede gli eventi registrati per un certo giorno su ‘‘agenda’’ e li stampa sullo stdout\n");
    printf
 ("\t-m\trichiede gli eventi registrati su ‘‘agenda’’ per un certo mese e li stampa sullo stdout\n");
    printf
 ("\t-r\telimina tutti gli eventi di ‘‘agenda’’ che contengono ‘‘pattern’’ come sottostringa in un qualsiasi campo\n");
}

canonical_original_code:
void printHelp()
{
    printf
 ("Usage:  dplan [ agenda [ -d gg-mm-aaaa -u utente#descrizione] [ -g gg-mm-aaaa ] [ -m mm-aaaa ] [ -r pattern ]  ] [-cq aname]\n");
    printf("\t-c\tcrea una nuova agenda di nome ‘‘aname’’\n");
    printf
 ("\t-q\trimuove una agenda di nome ‘‘aname’’ (solo se vuota)\n");
    printf("\t-d\tspecifica la data\n");
    printf
 ("\t-u\tspecifica l’utente che sta effettuando la registrazione e la descrizione dell’evento\n");
    printf
 ("\t-g\trichiede gli eventi registrati per un certo giorno su ‘‘agenda’’ e li stampa sullo stdout\n");
    printf
 ("\t-m\trichiede gli eventi registrati su ‘‘agenda’’ per un certo mese e li stampa sullo stdout\n");
    printf
 ("\t-r\telimina tutti gli eventi di ‘‘agenda’’ che contengono ‘‘pattern’’ come sottostringa in un qualsiasi campo\n");
}


getBufferString

decompiled_code:
char *__fastcall getBufferString(int a1, const char *a2, __int64 a3, _DWORD *a4)
{
char *v6; // rbx
size_t v7; // rax
size_t v9; // rax
size_t v10; // rax
int v11; // er12
char *v12; // r13
const char *v13; // r14
size_t v14; // rax
size_t v15; // rax
size_t v16; // rax
int v17; // er13
char *v18; // r14
const char *v19; // r12
size_t v20; // rax
size_t v21; // rax
char *v22; // r14
char *v23; // r15
size_t v24; // rax
char *v25; // r15
char *v26; // r14
size_t v27; // rax
size_t v28; // rax
size_t v29; // rax
int v30; // er12
char *v31; // r13
const char *v32; // r14
size_t v33; // rax
size_t v34; // rax
size_t v35; // rax
int v36; // er12
char *v37; // r13
const char *v38; // r14
size_t v39; // rax
size_t v40; // [rsp+8h] [rbp-40h]

v6 = (char *)malloc(0x7AuLL);
switch ( a1 )
{
case 'C':
case 'Q':
v7 = strlen(a2);
strncpy(v6, a2, v7 + 1);
*a4 = strlen(a2) + 1;
break;
case 'D':
v15 = strlen(a2);
strncpy(v6, a2, v15 + 1);
v16 = strlen(v6);
v17 = v16;
v18 = &v6[v16 + 1];
v19 = *(const char **)a3;
v20 = strlen(*(const char **)a3);
strncpy(v18, v19, v20 + 1);
v21 = strlen(v18);
LODWORD(v19) = v21;
v22 = &v18[v21 + 1];
v23 = strtok(*(char **)(a3 + 8), "#");
v24 = strlen(v23);
strncpy(v22, v23, v24 + 1);
v40 = strlen(v22);
v25 = &v22[v40 + 1];
v26 = strtok(0LL, "#");
v27 = strlen(v26);
strncpy(v25, v26, v27 + 1);
*a4 = strlen(v25) + v40 + v17 + (_DWORD)v19 + 4;
break;
case 'G':
v28 = strlen(a2);
strncpy(v6, a2, v28 + 1);
v29 = strlen(v6);
v30 = v29;
v31 = &v6[v29 + 1];
v32 = *(const char **)(a3 + 40);
v33 = strlen(v32);
strncpy(v31, v32, v33 + 1);
*a4 = v30 + strlen(v31) + 2;
break;
case 'M':
v34 = strlen(a2);
strncpy(v6, a2, v34 + 1);
v35 = strlen(v6);
v36 = v35;
v37 = &v6[v35 + 1];
v38 = *(const char **)(a3 + 48);
v39 = strlen(v38);
strncpy(v37, v38, v39 + 1);
*a4 = v36 + strlen(v37) + 2;
break;
case 'R':
v9 = strlen(a2);
strncpy(v6, a2, v9 + 1);
v10 = strlen(v6);
v11 = v10;
v12 = &v6[v10 + 1];
v13 = *(const char **)(a3 + 32);
v14 = strlen(v13);
strncpy(v12, v13, v14 + 1);
*a4 = v11 + strlen(v12) + 2;
break;
default:
return v6;
}
return v6;
}

original_code:
char *getBufferString(int tipo, char *agenda, char **args,
        unsigned int *length)
{
    char *stringa, *tmp, *g;
    int i;
    i = 0;
    stringa = (char *) malloc(sizeof(char) * (20 + 100 + 2));
    switch (tipo) {
    case 'C':
 strncpy(stringa, agenda, strlen(agenda) + 1);
 *length = strlen(agenda) + 1;
 break;
    case 'Q':
 strncpy(stringa, agenda, strlen(agenda) + 1);
 *length = strlen(agenda) + 1;
 break;
    case 'R':
 tmp = stringa;
 strncpy(tmp, agenda, strlen(agenda) + 1);
 i += strlen(tmp) + 1;
 tmp = &(tmp[strlen(tmp) + 1]);
 strncpy(tmp, args[4], strlen(args[4]) + 1);
 i += strlen(tmp) + 1;
 *length = i;
 break;
    case 'D':
 tmp = stringa;
 strncpy(tmp, agenda, strlen(agenda) + 1);
 i += strlen(tmp) + 1;
 tmp = &(tmp[strlen(tmp) + 1]);
 strncpy(tmp, args[0], strlen(args[0]) + 1);
 i += strlen(tmp) + 1;
 tmp = &(tmp[strlen(tmp) + 1]);
 g = strtok(args[1], "#");
 strncpy(tmp, g, strlen(g) + 1);
 i += strlen(tmp) + 1;
 tmp = &(tmp[strlen(tmp) + 1]);
 g = strtok(((void *)0), "#");
 strncpy(tmp, g, strlen(g) + 1);
 i += strlen(tmp) + 1;
 *length = i;
 return stringa;
 break;
    case 'G':
 tmp = stringa;
 strncpy(tmp, agenda, strlen(agenda) + 1);
 i += strlen(tmp) + 1;
 tmp = &(tmp[strlen(tmp) + 1]);
 strncpy(tmp, args[5], strlen(args[5]) + 1);
 i += strlen(tmp) + 1;
 *length = i;
 break;
    case 'M':
 tmp = stringa;
 strncpy(tmp, agenda, strlen(agenda) + 1);
 i += strlen(tmp) + 1;
 tmp = &(tmp[strlen(tmp) + 1]);
 strncpy(tmp, args[6], strlen(args[6]) + 1);
 i += strlen(tmp) + 1;
 *length = i;
 break;
    }
    return stringa;
}

canonical_original_code:
char *getBufferString(int tipo, char *agenda, char **args, unsigned int *length)
{
    char *stringa; char *tmp; char *g;
    int i;
    i = 0;
    stringa = (char *) malloc(sizeof(char) * (20 + 100 + 2));
    switch (tipo) {
    case 'C':
 strncpy(stringa, agenda, strlen(agenda) + 1);
 *length = strlen(agenda) + 1;
 break;
    case 'Q':
 strncpy(stringa, agenda, strlen(agenda) + 1);
 *length = strlen(agenda) + 1;
 break;
    case 'R':
 tmp = stringa;
 strncpy(tmp, agenda, strlen(agenda) + 1);
 i += strlen(tmp) + 1;
 tmp = &(tmp[strlen(tmp) + 1]);
 strncpy(tmp, args[4], strlen(args[4]) + 1);
 i += strlen(tmp) + 1;
 *length = i;
 break;
    case 'D':
 tmp = stringa;
 strncpy(tmp, agenda, strlen(agenda) + 1);
 i += strlen(tmp) + 1;
 tmp = &(tmp[strlen(tmp) + 1]);
 strncpy(tmp, args[0], strlen(args[0]) + 1);
 i += strlen(tmp) + 1;
 tmp = &(tmp[strlen(tmp) + 1]);
 g = strtok(args[1], "#");
 strncpy(tmp, g, strlen(g) + 1);
 i += strlen(tmp) + 1;
 tmp = &(tmp[strlen(tmp) + 1]);
 g = strtok(((void *)0), "#");
 strncpy(tmp, g, strlen(g) + 1);
 i += strlen(tmp) + 1;
 *length = i;
 return stringa;
 break;
    case 'G':
 tmp = stringa;
 strncpy(tmp, agenda, strlen(agenda) + 1);
 i += strlen(tmp) + 1;
 tmp = &(tmp[strlen(tmp) + 1]);
 strncpy(tmp, args[5], strlen(args[5]) + 1);
 i += strlen(tmp) + 1;
 *length = i;
 break;
    case 'M':
 tmp = stringa;
 strncpy(tmp, agenda, strlen(agenda) + 1);
 i += strlen(tmp) + 1;
 tmp = &(tmp[strlen(tmp) + 1]);
 strncpy(tmp, args[6], strlen(args[6]) + 1);
 i += strlen(tmp) + 1;
 *length = i;
 break;
    }
    return stringa;
}

variable_types:
args
char **

variable_types:
length
unsigned int *

variable_types:
stringa
char *

variable_types:
tmp
char *

variable_types:
g
char *

variable_types: i int


checkOpts

original_code:
int checkOpts(short int *flags, int indice)
{
    if (flags[indice])
 return 0;
    if (indice == 0 || indice == 1)
 return (flags[2] || flags[3] || flags[4] || flags[5] || flags[6]);
    else
 return (flags[0] || flags[1] || flags[2] || flags[3] || flags[4]
  || flags[5] || flags[6]);
}

canonical_original_code:
int checkOpts(short *flags, int indice)
{
    if (flags[indice])
 return 0;
    if (indice == 0 || indice == 1)
 return (flags[2] || flags[3] || flags[4] || flags[5] || flags[6]);
    else
 return (flags[0] || flags[1] || flags[2] || flags[3] || flags[4]
  || flags[5] || flags[6]);
}

variable_types:
flags
short *

variable_types: indice int


checkDate

decompiled_code:
__int64 __fastcall checkDate(int a1, const char *a2)
{
__int64 result; // rax
char v3[3]; // [rsp+6h] [rbp-22h] BYREF
char nptr[3]; // [rsp+9h] [rbp-1Fh] BYREF
int v5; // [rsp+Ch] [rbp-1Ch] BYREF

nptr[2] = 0;
nptr[0] = 0;
if ( a1 )
{
if ( (unsigned int)_isoc99_sscanf(a2, "%2c-%2c-%d", nptr, v3, &v5) != 3
|| (unsigned int)(atoi(nptr) - 1) > 0x1E && strcmp(nptr, "**")
|| (unsigned int)(atoi(v3) - 1) > 0xB
|| (result = 0LL, v5 <= 1999) )
{
printf("dplan: %s: Data non corretta\n", a2);
result = 1LL;
}
}
else if ( (unsigned int)_isoc99_sscanf(a2, "%2c-%d", nptr, &v5) != 2
|| (unsigned int)(atoi(nptr) - 1) > 0xB
|| (result = 0LL, v5 <= 1999) )
{
printf("dplan: %s: Data non corretta\n", a2);
result = 1LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(int a1, const char *a2)
{
__int64 result; // rax
char v3[3]; // [rsp+6h] [rbp-22h] BYREF
char nptr[3]; // [rsp+9h] [rbp-1Fh] BYREF
int v5; // [rsp+Ch] [rbp-1Ch] BYREF

nptr[2] = 0;
nptr[0] = 0;
if ( a1 )
{
if ( (unsigned int)_isoc99_sscanf(a2, "%2c-%2c-%d", nptr, v3, &v5) != 3
|| (unsigned int)(atoi(nptr) - 1) > 0x1E && strcmp(nptr, "**")
|| (unsigned int)(atoi(v3) - 1) > 0xB
|| (result = 0LL, v5 <= 1999) )
{
printf("dplan: %s: Data non corretta\n", a2);
result = 1LL;
}
}
else if ( (unsigned int)_isoc99_sscanf(a2, "%2c-%d", nptr, &v5) != 2
|| (unsigned int)(atoi(nptr) - 1) > 0xB
|| (result = 0LL, v5 <= 1999) )
{
printf("dplan: %s: Data non corretta\n", a2);
result = 1LL;
}
return result;
}

original_code:
int checkDate(int type, char *date)
{
    int a, tmp;
    char g[3], m[3];
    g[2] = '\0';
    m[3] = '\0';
    if (type) {
 if ((tmp = sscanf(date, "%2c-%2c-%d", g, m, &a)) == 3) {
     if (((atoi(g) > 0 && atoi(g) < 32) || strcmp(g, "**") == 0)
  && (atoi(m)
      > 0 && atoi(m) < 13) && (a >= 2000))
  return 0;
     else
  printf("dplan: %s: Data non corretta\n", date);
 } else
     printf("dplan: %s: Data non corretta\n", date);
    } else {
 if ((tmp = sscanf(date, "%2c-%d", g, &a)) == 2) {
     if ((atoi(g) > 0 && atoi(g) < 13) && (a >= 2000))
  return 0;
     else
  printf("dplan: %s: Data non corretta\n", date);
 } else
     printf("dplan: %s: Data non corretta\n", date);
    }
    return 1;
}

canonical_original_code:
int checkDate(int type, char *date)
{
    int a; int tmp;
    char g[3]; char m[3];
    g[2] = '\0';
    m[3] = '\0';
    if (type) {
 if ((tmp = sscanf(date, "%2c-%2c-%d", g, m, &a)) == 3) {
     if (((atoi(g) > 0 && atoi(g) < 32) || strcmp(g, "**") == 0)
  && (atoi(m)
      > 0 && atoi(m) < 13) && (a >= 2000))
  return 0;
     else
  printf("dplan: %s: Data non corretta\n", date);
 } else
     printf("dplan: %s: Data non corretta\n", date);
    } else {
 if ((tmp = sscanf(date, "%2c-%d", g, &a)) == 2) {
     if ((atoi(g) > 0 && atoi(g) < 13) && (a >= 2000))
  return 0;
     else
  printf("dplan: %s: Data non corretta\n", date);
 } else
     printf("dplan: %s: Data non corretta\n", date);
    }
    return 1;
}

variable_types: type int

variable_types:
date
char *

variable_types: a int

variable_types: tmp int

variable_types:
g
char [3]

variable_types:
m
char [3]


checkArgs

decompiled_code:
__int64 __fastcall checkArgs(_WORD *a1, int a2, __int64 a3, const char **a4, const char **a5)
{
_WORD *v5; // rbp
int i; // ebx
const char *v9; // rbx
const char **v11; // r12
int v12; // ebx
char *v13; // r12
char *v14; // rdi
char dest[168]; // [rsp+10h] [rbp-A8h] BYREF

*a5 = 0LL;
if ( a2 <= 1 )
goto LABEL_12;
v5 = a1;
for ( i = 1; i < a2; ++i )
{
v11 = (const char **)(a3 + 8LL * i);
if ( !(unsigned int)_isoc99_sscanf(*v11, "-%c", &dest[111]) )
{
v9 = *v11;
if ( strlen(*v11) <= 0x14 )
{
*a5 = v9;
goto LABEL_11;
}
printf("dplan: %s: Agenda max 20 caratteri\n", v9);
return 0xFFFFFFFFLL;
}
if ( !a1[2] )
i += a1[3] == 0;
}
if ( !*a5 )
{
LABEL_12:
puts("dplan: Formato scorretto del comando");
exit(1);
}
LABEL_11:
v12 = 1;
while ( *v5 )
{
switch ( v12 )
{
case 1:
if ( !(unsigned int)checkDate(1, *a4) )
goto LABEL_27;
return 0xFFFFFFFFLL;
case 2:
strncpy(dest, a4[1], 0x6EuLL);
v13 = strtok(dest, "#");
if ( strlen(v13) > 8 )
{
printf("dplan: %s: Formato evento non corretto (Utente max 8 caratteri)\n", v13);
return 0xFFFFFFFFLL;
}
v14 = strtok(0LL, "#");
if ( !v14 )
{
printf("dplan: %s: Formato evento non corretto (manca #)\n", a4[1]);
return 0xFFFFFFFFLL;
}
if ( strlen(v14) > 0x50 )
{
printf("dplan: %s: Formato evento non corretto (Descrizione max 80 caratteri)\n", a4[1]);
return 0xFFFFFFFFLL;
}
if ( strtok(0LL, "#") )
return 0xFFFFFFFFLL;
LABEL_27:
++v5;
++v12;
break;
case 3:
case 4:
return 0LL;
case 6:
if ( !(unsigned int)checkDate(1, a4[5]) )
goto LABEL_27;
return 0xFFFFFFFFLL;
case 7:
return (unsigned int)-((unsigned int)checkDate(0, a4[6]) != 0);
default:
goto LABEL_26;
}
}
LABEL_26:
if ( v12 <= 6 )
goto LABEL_27;
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func4(_WORD *a1, int a2, __int64 a3, const char **a4, const char **a5)
{
_WORD *v5; // rbp
int i; // ebx
const char *v9; // rbx
const char **v11; // r12
int v12; // ebx
char *v13; // r12
char *v14; // rdi
char dest[168]; // [rsp+10h] [rbp-A8h] BYREF

*a5 = 0LL;
if ( a2 <= 1 )
goto LABEL_12;
v5 = a1;
for ( i = 1; i < a2; ++i )
{
v11 = (const char **)(a3 + 8LL * i);
if ( !(unsigned int)_isoc99_sscanf(*v11, "-%c", &dest[111]) )
{
v9 = *v11;
if ( strlen(*v11) <= 0x14 )
{
*a5 = v9;
goto LABEL_11;
}
printf("dplan: %s: Agenda max 20 caratteri\n", v9);
return 0xFFFFFFFFLL;
}
if ( !a1[2] )
i += a1[3] == 0;
}
if ( !*a5 )
{
LABEL_12:
puts("dplan: Formato scorretto del comando");
exit(1);
}
LABEL_11:
v12 = 1;
while ( *v5 )
{
switch ( v12 )
{
case 1:
if ( !(unsigned int)func3(1, *a4) )
goto LABEL_27;
return 0xFFFFFFFFLL;
case 2:
strncpy(dest, a4[1], 0x6EuLL);
v13 = strtok(dest, "#");
if ( strlen(v13) > 8 )
{
printf("dplan: %s: Formato evento non corretto (Utente max 8 caratteri)\n", v13);
return 0xFFFFFFFFLL;
}
v14 = strtok(0LL, "#");
if ( !v14 )
{
printf("dplan: %s: Formato evento non corretto (manca #)\n", a4[1]);
return 0xFFFFFFFFLL;
}
if ( strlen(v14) > 0x50 )
{
printf("dplan: %s: Formato evento non corretto (Descrizione max 80 caratteri)\n", a4[1]);
return 0xFFFFFFFFLL;
}
if ( strtok(0LL, "#") )
return 0xFFFFFFFFLL;
LABEL_27:
++v5;
++v12;
break;
case 3:
case 4:
return 0LL;
case 6:
if ( !(unsigned int)func3(1, a4[5]) )
goto LABEL_27;
return 0xFFFFFFFFLL;
case 7:
return (unsigned int)-((unsigned int)func3(0, a4[6]) != 0);
default:
goto LABEL_26;
}
}
LABEL_26:
if ( v12 <= 6 )
goto LABEL_27;
return 0LL;
}

original_code:
int checkArgs(short int *flags, int argc, char **argv, char **args,
       char **agenda)
{
    int i;
    char *buf;
    char tmp;
    char tmp2[110];
    *agenda = ((void *)0);
    buf = ((void *)0);
    for (i = 1; i < argc; i++) {
 if (sscanf(argv[i], "-%c", &tmp)) {
     if (flags[2] || flags[3]);
     else
  i += 1;
 } else {
     if (strlen(argv[i]) > 20) {
  printf("dplan: %s: Agenda max 20 caratteri\n", argv[i]);
  return -1;
     } else {
  *agenda = argv[i];
  break;
     }
 }
    }
    if (*agenda == ((void *)0)) {
 { printf("dplan: Formato scorretto del comando\n"); exit(1);};
    }
    for (i = 0; i < 7; i++) {
 if (flags[i]) {
     switch (i) {
     case 2:
  return 0;
  break;
     case 0:
  if (checkDate(1, args[i]))
      return -1;
  break;
     case 3:
  return 0;
  break;
     case 4:
  break;
     case 5:
  if (checkDate(1, args[i]))
      return -1;
  break;
     case 6:
  if (checkDate(0, args[i]))
      return -1;
  break;
     case 1:
  strncpy(tmp2, args[i], 110);
  buf = strtok(tmp2, "#");
  if (strlen(buf) <= 8) {
      buf = strtok(((void *)0), "#");
      if (!buf) {
   printf
       ("dplan: %s: Formato evento non corretto (manca #)\n",
        args[i]);
   return -1;
      }
      if (!(strlen(buf) <= 80)) {
   printf
       ("dplan: %s: Formato evento non corretto (Descrizione max 80 caratteri)\n",
        args[i]);
   return -1;
      }
      if (strtok(((void *)0), "#"))
   return -1;
  } else {
      printf
   ("dplan: %s: Formato evento non corretto (Utente max 8 caratteri)\n",
    buf);
      return -1;
  }
  break;
     }
 }
    }
    return 0;
}

canonical_original_code:
int checkArgs(short *flags, int argc, char **argv, char **args, char **agenda)
{
    int i;
    char *buf;
    char tmp;
    char tmp2[110];
    *agenda = ((void *)0);
    buf = ((void *)0);
    for (i = 1; i < argc; i++) {
 if (sscanf(argv[i], "-%c", &tmp)) {
     if (flags[2] || flags[3]);
     else
  i += 1;
 } else {
     if (strlen(argv[i]) > 20) {
  printf("dplan: %s: Agenda max 20 caratteri\n", argv[i]);
  return -1;
     } else {
  *agenda = argv[i];
  break;
     }
 }
    }
    if (*agenda == ((void *)0)) {
 { printf("dplan: Formato scorretto del comando\n"); exit(1);};
    }
    for (i = 0; i < 7; i++) {
 if (flags[i]) {
     switch (i) {
     case 2:
  return 0;
  break;
     case 0:
  if (checkDate(1, args[i]))
      return -1;
  break;
     case 3:
  return 0;
  break;
     case 4:
  break;
     case 5:
  if (checkDate(1, args[i]))
      return -1;
  break;
     case 6:
  if (checkDate(0, args[i]))
      return -1;
  break;
     case 1:
  strncpy(tmp2, args[i], 110);
  buf = strtok(tmp2, "#");
  if (strlen(buf) <= 8) {
      buf = strtok(((void *)0), "#");
      if (!buf) {
   printf
       ("dplan: %s: Formato evento non corretto (manca #)\n",
        args[i]);
   return -1;
      }
      if (!(strlen(buf) <= 80)) {
   printf
       ("dplan: %s: Formato evento non corretto (Descrizione max 80 caratteri)\n",
        args[i]);
   return -1;
      }
      if (strtok(((void *)0), "#"))
   return -1;
  } else {
      printf
   ("dplan: %s: Formato evento non corretto (Utente max 8 caratteri)\n",
    buf);
      return -1;
  }
  break;
     }
 }
    }
    return 0;
}

variable_types: argc int

variable_types:
argv
char **

variable_types:
agenda
char **

variable_types:
buf
char *

variable_types: tmp char


decompiled_code:
__int64 __fastcall is_cardinal(char a1)
{
char v1; // al

v1 = 1;
if ( (unsigned __int8)(a1 - 69) <= 0x12u )
v1 = ((0x44201uLL >> (a1 - 69)) ^ 1) & 1;
return (unsigned __int8)v1 ^ 1u;
}

original_code:
static inline int is_cardinal(char a) {
 return a == 'N' || a == 'S' || a == 'E' || a == 'W';
}

variable_types: a char


decompiled_code:
__int64 __fastcall compare_delim(char *a1, char *a2)
{
char v3; // di
__int64 result; // rax
char v5; // al
char v6; // al
char v7; // r12

if ( !a1 )
return 0LL;
if ( !a2 )
return 0LL;
v3 = *a1;
if ( v3 )
{
do
{
v7 = *a2;
if ( !*a2 )
break;
if ( v7 != v3 )
{
result = is_cardinal(v3);
if ( !(_DWORD)result )
return result;
result = is_cardinal(v7);
if ( !(_DWORD)result )
return result;
}
v5 = *a1;
do
++v5;
while ( v5 == 32 );
*a1 = v5;
v6 = *a2;
do
++v6;
while ( v6 == 32 );
*a2 = v6;
v3 = *a1;
}
while ( *a1 );
}
return *a2 == v3;
}

canonical_decompiled_code:
__int64 __fastcall func8(char *a1, char *a2)
{
char v3; // di
__int64 result; // rax
char v5; // al
char v6; // al
char v7; // r12

if ( !a1 )
return 0LL;
if ( !a2 )
return 0LL;
v3 = *a1;
if ( v3 )
{
do
{
v7 = *a2;
if ( !*a2 )
break;
if ( v7 != v3 )
{
result = func7(v3);
if ( !(_DWORD)result )
return result;
result = func7(v7);
if ( !(_DWORD)result )
return result;
}
v5 = *a1;
do
++v5;
while ( v5 == 32 );
*a1 = v5;
v6 = *a2;
do
++v6;
while ( v6 == 32 );
*a2 = v6;
v3 = *a1;
}
while ( *a1 );
}
return *a2 == v3;
}

original_code:
static int compare_delim(char* a, char* b) {
 if (a == ((void *)0) || b == ((void *)0)) {
  return 0;
 }
 while (*a != '\0' && *b != '\0') {
  if (*a == *b || (is_cardinal(*a) && is_cardinal(*b))) {
   while( ++*a == ' ') {};
   while( ++*b == ' ') {};
  } else {
   return 0;
  }
 }
 return *a == *b;
}

canonical_original_code:
static int compare_delim(char *a, char *b) {
 if (a == ((void *)0) || b == ((void *)0)) {
  return 0;
 }
 while (*a != '\0' && *b != '\0') {
  if (*a == *b || (is_cardinal(*a) && is_cardinal(*b))) {
   while( ++*a == ' ') {};
   while( ++*b == ' ') {};
  } else {
   return 0;
  }
 }
 return *a == *b;
}

variable_types:
a
char *

variable_types:
b
char *


decompiled_code:
double __fastcall get_timestamp(double a1)
{
struct timeval v2; // [rsp+0h] [rbp-18h] BYREF

if ( !gettimeofday(&v2, 0LL) )
return (double)SLODWORD(v2.tv_usec) * 0.000001 + (double)SLODWORD(v2.tv_sec) - a1;
printf("Failed to get time stamp");
return -1.0;
}

canonical_decompiled_code:
double __fastcall func8(double a1)
{
struct timeval v2; // [rsp+0h] [rbp-18h] BYREF

if ( !gettimeofday(&v2, 0LL) )
return (double)SLODWORD(v2.tv_usec) * 0.000001 + (double)SLODWORD(v2.tv_sec) - a1;
printf("Failed to get time stamp");
return -1.0;
}

original_code:
double get_timestamp(double start_time) {
  struct timeval tp;
  if (gettimeofday(&tp, ((void *)0)) == 0) {
    return (double)tp.tv_sec + (double)tp.tv_usec * 1e-6 - start_time;
  } else {
    printf("Failed to get time stamp");
    return -1.0f;
  }
}

variable_types: struct timeval { long tv_sec; long tv_usec; }

return_type: double


createData

original_code:
char * createData(double selectivity, char * data) {
  int i;
  double r;
  for(i = 0; i < 3000; i++) {
    r = ((double)rand() / ((double)(2147483647) + (double)(1)));
    if(r < selectivity) {
      *data = 1;
    } else {
      *data = 0;
    }
    data++;
  }
  *data = '\0';
  return data;
}

canonical_original_code:
char *createData(double selectivity, char *data) {
  int i;
  double r;
  for(i = 0; i < 3000; i++) {
    r = ((double)rand() / ((double)(2147483647) + (double)(1)));
    if(r < selectivity) {
      *data = 1;
    } else {
      *data = 0;
    }
    data++;
  }
  *data = '\0';
  return data;
}

variable_types: selectivity double

variable_types:
data
char *

variable_types: i int

variable_types: r double


createOffsets

original_code:
int createOffsets(int * off) {
  int i;
  for(i = 0; i < 100000000; i++) {
    double r = ((double)rand() / ((double)(2147483647) + (double)(1)));
    off[i] = (int)(r * (double)3000);
  }
  return 0;
}

canonical_original_code:
int createOffsets(int *off) {
  int i;
  for(i = 0; i < 100000000; i++) {
    double r = ((double)rand() / ((double)(2147483647) + (double)(1)));
    off[i] = (int)(r * (double)3000);
  }
  return 0;
}

variable_types:
off
int *