decompiled_code:
__int64 __fastcall at_eq_ptr(__int64 a1, const char *a2, const void *a3, const void *a4)
{
__int64 v4; // rsi
__int64 result; // rax

if ( a3 == a4 )
{
at_make_success(a1, a2, a3, a4, a3);
result = a1;
}
else
{
v4 = at_allocf("Expression (%s) expected to have value %p but found to have value %p.", a2, a4, a3);
if ( v4 )
at_make_failure(a1, v4, &at_freef);
else
at_make_error(a1, "Allocation error during failed check", 0LL);
result = a1;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, const char *a2, const void *a3, const void *a4)
{
__int64 v4; // rsi
__int64 result; // rax

if ( a3 == a4 )
{
at_make_success(a1, a2, a3, a4, a3);
result = a1;
}
else
{
v4 = at_allocf("Expression (%s) expected to have value %p but found to have value %p.", a2, a4, a3);
if ( v4 )
at_make_failure(a1, v4, &at_freef);
else
at_make_error(a1, "Allocation error during failed check", 0LL);
result = a1;
}
return result;
}

original_code:
AtCheckResult at_eq_ptr(const char* expr, const void* value,
                        const void* expected ) {
 do { if (! ((value == expected)) ) { const char* _at_msg = at_allocf("Expression (%s) expected to have value " "%p" " but found to have value " "%p" ".", expr, expected, value); if (_at_msg == ((void *)0)) { const char* _at_error_msg = "Allocation error during failed check"; return at_make_error(_at_error_msg, ((void *)0)); } return at_make_failure(_at_msg, at_freef); } return at_make_success(); } while (0);
}

canonical_original_code:
struct AtCheckResult at_eq_ptr(char *expr, void *value, void *expected) {
 do { if (! ((value == expected)) ) { char *_at_msg = at_allocf("Expression (%s) expected to have value " "%p" " but found to have value " "%p" ".", expr, expected, value); if (_at_msg == ((void *)0)) { char *_at_error_msg = "Allocation error during failed check"; return at_make_error(_at_error_msg, ((void *)0)); } return at_make_failure(_at_msg, at_freef); } return at_make_success(); } while (0);
}

variable_types:
value
void *

variable_types:
expected
void *


repo: alexandream/atest

decompiled_code:
__int64 __fastcall at_eq_str(__int64 a1, const char *a2, const char *a3, const char *a4)
{
const char *v5; // r13
__int64 v8; // rdx
__int64 v9; // rcx
__int64 v10; // r8
__int64 v11; // rsi
__int64 result; // rax

v5 = a4;
if ( !strcmp(a3, a4) )
{
at_make_success(a1, a4, v8, v9, v10);
result = a1;
}
else
{
v11 = at_allocf(
"Expression (%s) expected to have value \n \"%s\"\n but found to have value \n \"%s\"\n.",
a2,
v5,
a3);
if ( v11 )
at_make_failure(a1, v11, &at_freef);
else
at_make_error(a1, "Allocation error during failed check", 0LL);
result = a1;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, const char *a2, const char *a3, const char *a4)
{
const char *v5; // r13
__int64 v8; // rdx
__int64 v9; // rcx
__int64 v10; // r8
__int64 v11; // rsi
__int64 result; // rax

v5 = a4;
if ( !strcmp(a3, a4) )
{
at_make_success(a1, a4, v8, v9, v10);
result = a1;
}
else
{
v11 = at_allocf(
"Expression (%s) expected to have value \n \"%s\"\n but found to have value \n \"%s\"\n.",
a2,
v5,
a3);
if ( v11 )
at_make_failure(a1, v11, &at_freef);
else
at_make_error(a1, "Allocation error during failed check", 0LL);
result = a1;
}
return result;
}

original_code:
AtCheckResult at_eq_str(const char* expr, const char* value,
                        const char* expected) {
 do { if (! ((!strcmp(value, expected))) ) { const char* _at_msg = at_allocf("Expression (%s) expected to have value " "\n    \"%s\"\n" " but found to have value " "\n    \"%s\"\n" ".", expr, expected, value); if (_at_msg == ((void *)0)) { const char* _at_error_msg = "Allocation error during failed check"; return at_make_error(_at_error_msg, ((void *)0)); } return at_make_failure(_at_msg, at_freef); } return at_make_success(); } while (0);
}

canonical_original_code:
struct AtCheckResult at_eq_str(char *expr, char *value, char *expected) {
 do { if (! ((!strcmp(value, expected))) ) { char *_at_msg = at_allocf("Expression (%s) expected to have value " "\n    \"%s\"\n" " but found to have value " "\n    \"%s\"\n" ".", expr, expected, value); if (_at_msg == ((void *)0)) { char *_at_error_msg = "Allocation error during failed check"; return at_make_error(_at_error_msg, ((void *)0)); } return at_make_failure(_at_msg, at_freef); } return at_make_success(); } while (0);
}

variable_types:
expr
char *

variable_types:
value
char *

variable_types:
expected
char *

return_type: struct AtCheckResult { int status; int check_number; char *message; char *file_name; int line_number; void (*clean_up)(char *); }


decompiled_code:
__int64 __fastcall at_is_true(__int64 a1, const char *a2, __int64 a3, __int64 a4, __int64 a5)
{
__int64 v5; // rsi
__int64 result; // rax

if ( (_DWORD)a3 )
{
at_make_success(a1, a2, a3, a4, a5);
result = a1;
}
else
{
v5 = at_allocf("Expression (%s) expected to be true, but found to be false.", a2);
if ( v5 )
at_make_failure(a1, v5, &at_freef);
else
at_make_error(a1, "Allocation error during failed check", 0LL);
result = a1;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1, const char *a2, __int64 a3, __int64 a4, __int64 a5)
{
__int64 v5; // rsi
__int64 result; // rax

if ( (_DWORD)a3 )
{
at_make_success(a1, a2, a3, a4, a5);
result = a1;
}
else
{
v5 = at_allocf("Expression (%s) expected to be true, but found to be false.", a2);
if ( v5 )
at_make_failure(a1, v5, &at_freef);
else
at_make_error(a1, "Allocation error during failed check", 0LL);
result = a1;
}
return result;
}

original_code:
AtCheckResult at_is_true(const char* expr, int value) {
 if (! value ) {
  const char* _at_msg =
   at_allocf("Expression (%s) expected to be true, but found "
          "to be false.",
       expr);
  if (_at_msg == ((void *)0)) {
   const char* _at_error_msg =
    "Allocation error during failed check";
   return
    at_make_error(_at_error_msg, ((void *)0));
  }
  return at_make_failure(_at_msg, at_freef);
 }
 return at_make_success();
}

canonical_original_code:
struct AtCheckResult at_is_true(char *expr, int value) {
 if (! value ) {
  char *_at_msg = at_allocf("Expression (%s) expected to be true, but found "
          "to be false.",
       expr);
  if (_at_msg == ((void *)0)) {
   char *_at_error_msg = "Allocation error during failed check";
   return
    at_make_error(_at_error_msg, ((void *)0));
  }
  return at_make_failure(_at_msg, at_freef);
 }
 return at_make_success();
}

variable_types: value int

user_defined_types: struct AtCheckResult { int status; int check_number; char *message; char *file_name; int line_number; void (*clean_up)(char *); }


decompiled_code:
__int64 __fastcall compute_format_length(char *a1, void *a2)
{
unsigned int v2; // er12
int v3; // eax
char *src; // [rsp+8h] [rbp-20h] BYREF

if ( !*a1 )
return 0;
v2 = 0;
while ( 1 )
{
src = 0LL;
v3 = get_part_length_constprop_0(a1, a2, &src);
if ( v3 < 0 )
break;
a1 = src;
v2 += v3;
if ( !*src )
return v2;
}
return (unsigned int)-1;
}

canonical_decompiled_code:
__int64 __fastcall func1(char *a1, void *a2)
{
unsigned int v2; // er12
int v3; // eax
char *src; // [rsp+8h] [rbp-20h] BYREF

if ( !*a1 )
return 0;
v2 = 0;
while ( 1 )
{
src = 0LL;
v3 = func0(a1, a2, &src);
if ( v3 < 0 )
break;
a1 = src;
v2 += v3;
if ( !*src )
return v2;
}
return (unsigned int)-1;
}

original_code:
static
int compute_format_length(const char* format, va_list ap) {
 int result = 0;
 const char* part = format;
 while(*part) {
  const char* next_part = ((void *)0);
  int part_len;
  part_len = get_part_length(part, ap, &next_part);
  if (part_len < 0) {
   return -1;
  }
  result += part_len;
  part = next_part;
 }
 return result;
}

canonical_original_code:
static int compute_format_length(char *format, __builtin_va_list ap) {
 int result = 0;
 char *part = format;
 while(*part) {
  char *next_part = ((void *)0);
  int part_len;
  part_len = get_part_length(part, ap, &next_part);
  if (part_len < 0) {
   return -1;
  }
  result += part_len;
  part = next_part;
 }
 return result;
}

variable_types:
format
char *

variable_types: result int

variable_types:
part
char *

return_type: int


decompiled_code:
int __fastcall do_vasprintf(char **a1, char *a2, void *a3, void *a4)
{
int result; // eax
char *v6; // rax
char *v7; // r13

result = compute_format_length(a2, a3);
if ( result >= 0 )
{
v6 = (char *)malloc(result + 1);
v7 = v6;
if ( v6 )
{
result = vsprintf(v6, a2, a4);
if ( result < 0 )
{
free(v7);
result = -12;
}
else
{
*a1 = v7;
}
}
else
{
result = -11;
}
}
return result;
}

canonical_decompiled_code:
int __fastcall func2(char **a1, char *a2, void *a3, void *a4)
{
int result; // eax
char *v6; // rax
char *v7; // r13

result = func1(a2, a3);
if ( result >= 0 )
{
v6 = (char *)malloc(result + 1);
v7 = v6;
if ( v6 )
{
result = vsprintf(v6, a2, a4);
if ( result < 0 )
{
free(v7);
result = -12;
}
else
{
*a1 = v7;
}
}
else
{
result = -11;
}
}
return result;
}

original_code:
static
int do_vasprintf(char** dest, const char* fmt, va_list ap1, va_list ap2) {
 int length;
 char* buf;
 int expected_length;
 expected_length = compute_format_length(fmt, ap1);
 if (expected_length < 0) {
  return expected_length;
 }
 buf = malloc(sizeof(char) * (expected_length + 1));
 if (buf == ((void *)0)) {
  return -11;
 }
 length = vsprintf(buf, fmt, ap2);
 if (length < 0) {
  free(buf);
  return -12;
 }
 *dest = buf;
 return length;
}

canonical_original_code:
static int do_vasprintf(char **dest, char *fmt, __builtin_va_list ap1, __builtin_va_list ap2) {
 int length;
 char *buf;
 int expected_length;
 expected_length = compute_format_length(fmt, ap1);
 if (expected_length < 0) {
  return expected_length;
 }
 buf = malloc(sizeof(char) * (expected_length + 1));
 if (buf == ((void *)0)) {
  return -11;
 }
 length = vsprintf(buf, fmt, ap2);
 if (length < 0) {
  free(buf);
  return -12;
 }
 *dest = buf;
 return length;
}

variable_types:
dest
char **

variable_types:
fmt
char *

variable_types: length int

variable_types:
buf
char *


decompiled_code:
int at_asprintf(char **a1, char *a2, ...)
{
gcc_va_list va; // [rsp+0h] [rbp-E8h] BYREF
gcc_va_list va1; // [rsp+18h] [rbp-D0h] BYREF

va_start(va1, a2);
va_start(va, a2);
return do_vasprintf(a1, a2, va, va1);
}

canonical_decompiled_code:
int func3(char **a1, char *a2, ...)
{
gcc_va_list va; // [rsp+0h] [rbp-E8h] BYREF
gcc_va_list va1; // [rsp+18h] [rbp-D0h] BYREF

va_start(va1, a2);
va_start(va, a2);
return func2(a1, a2, va, va1);
}

original_code:
int at_asprintf(char** dest, const char* fmt, ...) {
 int length;
 va_list ap1;
 va_list ap2;
 __builtin_va_start(ap1,fmt);
 __builtin_va_start(ap2,fmt);
 length = do_vasprintf(dest, fmt, ap1, ap2);
 __builtin_va_end(ap2);
 __builtin_va_end(ap1);
 return length;
}

canonical_original_code:
int at_asprintf(char **dest, char *fmt, ...) {
 int length;
 __builtin_va_list ap1;
 __builtin_va_list ap2;
 __builtin_va_start(ap1,fmt);
 __builtin_va_start(ap2,fmt);
 length = do_vasprintf(dest, fmt, ap1, ap2);
 __builtin_va_end(ap2);
 __builtin_va_end(ap1);
 return length;
}


decompiled_code:
char *at_allocf(char *a1, ...)
{
bool v1; // sf
char *result; // rax
char *v3; // [rsp+8h] [rbp-F0h] BYREF
gcc_va_list va; // [rsp+10h] [rbp-E8h] BYREF
gcc_va_list va1; // [rsp+28h] [rbp-D0h] BYREF

va_start(va1, a1);
va_start(va, a1);
v3 = 0LL;
v1 = do_vasprintf(&v3, a1, va, va1) < 0;
result = 0LL;
if ( !v1 )
result = v3;
return result;
}

canonical_decompiled_code:
char *func4(char *a1, ...)
{
bool v1; // sf
char *result; // rax
char *v3; // [rsp+8h] [rbp-F0h] BYREF
gcc_va_list va; // [rsp+10h] [rbp-E8h] BYREF
gcc_va_list va1; // [rsp+28h] [rbp-D0h] BYREF

va_start(va1, a1);
va_start(va, a1);
v3 = 0LL;
v1 = func2(&v3, a1, va, va1) < 0;
result = 0LL;
if ( !v1 )
result = v3;
return result;
}

original_code:
char* at_allocf(const char* fmt, ...) {
 char* result = ((void *)0);
 int length;
 va_list ap1;
 va_list ap2;
 __builtin_va_start(ap1,fmt);
 __builtin_va_start(ap2,fmt);
 length = do_vasprintf(&result, fmt, ap1, ap2);
 __builtin_va_end(ap2);
 __builtin_va_end(ap1);
 return (length >= 0) ? result : ((void *)0);
}

canonical_original_code:
char *at_allocf(char *fmt, ...) {
 char *result = ((void *)0);
 int length;
 __builtin_va_list ap1;
 __builtin_va_list ap2;
 __builtin_va_start(ap1,fmt);
 __builtin_va_start(ap2,fmt);
 length = do_vasprintf(&result, fmt, ap1, ap2);
 __builtin_va_end(ap2);
 __builtin_va_end(ap1);
 return (length >= 0) ? result : ((void *)0);
}

variable_types:
result
char *

return_type: char *


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

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

original_code:
void at_freef(const char* msg) {
 free((void*) msg);
}

canonical_original_code:
void at_freef(char *msg) {
 free((void *) msg);
}

variable_types:
msg
char *

return_type: void


repo: alexisduque/prs

decompiled_code:
_BOOL8 __fastcall test_delim(char a1)
{
return a1 == 58;
}

canonical_decompiled_code:
_BOOL8 __fastcall func0(char a1)
{
return a1 == 58;
}

original_code:
int test_delim(char c) {
    return (c == ':');
}

variable_types: c char


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

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

original_code:
void p2p_addr_delete(p2p_addr addr) {
    free(addr);
}

canonical_original_code:
void p2p_addr_delete(struct p2p_addr_struct *addr) {
    free(addr);
}

variable_types: struct p2p_addr_struct { struct in_addr { unsigned int s_addr; } ip; unsigned short tcp_port; unsigned short udp_port; } *

user_defined_types: struct p2p_addr_struct { struct in_addr ip; unsigned short tcp_port; unsigned short udp_port; }


decompiled_code:
_BOOL8 __fastcall p2p_addr_is_equal(_DWORD *a1, _DWORD *a2)
{
_BOOL8 result; // rax

result = 0LL;
if ( *a1 == *a2 )
result = a1[1] == a2[1];
return result;
}

canonical_decompiled_code:
_BOOL8 __fastcall func4(_DWORD *a1, _DWORD *a2)
{
_BOOL8 result; // rax

result = 0LL;
if ( *a1 == *a2 )
result = a1[1] == a2[1];
return result;
}

original_code:
int p2p_addr_is_equal(const p2p_addr addr1, const p2p_addr addr2) {
    return ((addr1->ip.s_addr == addr2->ip.s_addr) &&
            (addr1->tcp_port == addr2->tcp_port) &&
            (addr1->udp_port == addr2->udp_port));
}

canonical_original_code:
int p2p_addr_is_equal(struct p2p_addr_struct *addr1, struct p2p_addr_struct *addr2) {
    return ((addr1->ip.s_addr == addr2->ip.s_addr) &&
            (addr1->tcp_port == addr2->tcp_port) &&
            (addr1->udp_port == addr2->udp_port));
}


decompiled_code:
__int64 __fastcall p2p_addr_set(struct in_addr *inp, char *cp, __int16 a3, __int16 a4)
{
if ( !inet_aton(cp, inp) )
return 0xFFFFFFFFLL;
LOWORD(inp[1].s_addr) = _bswap_16(a3);
HIWORD(inp[1].s_addr) = _bswap_16(a4);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func5(struct in_addr *inp, char *cp, __int16 a3, __int16 a4)
{
if ( !inet_aton(cp, inp) )
return 0xFFFFFFFFLL;
LOWORD(inp[1].s_addr) = func1(a3);
HIWORD(inp[1].s_addr) = func1(a4);
return 0LL;
}

original_code:
int p2p_addr_set(p2p_addr dst, const char* ip_str,
        unsigned short tcp, unsigned short udp) {
    if (inet_aton(ip_str, & dst->ip) == 0) {
        return -1;
    }
    dst->tcp_port = htons(tcp);
    dst->udp_port = htons(udp);
    return 0;
}

canonical_original_code:
int p2p_addr_set(struct p2p_addr_struct *dst, char *ip_str, unsigned short tcp, unsigned short udp) {
    if (inet_aton(ip_str, & dst->ip) == 0) {
        return -1;
    }
    dst->tcp_port = htons(tcp);
    dst->udp_port = htons(udp);
    return 0;
}

variable_types:
tcp
unsigned short

variable_types:
udp
unsigned short


decompiled_code:
__int64 __fastcall p2p_addr_setstr(struct in_addr *inp, __int64 a2)
{
__int16 v2; // bx
__int16 v3; // ax
char v5[30]; // [rsp+0h] [rbp-78h] BYREF
char v6[30]; // [rsp+1Eh] [rbp-5Ah] BYREF
char nptr[60]; // [rsp+3Ch] [rbp-3Ch] BYREF

if ( (unsigned int)get_tokens(a2, v5, test_delim) != 3 )
return 0xFFFFFFFFLL;
v2 = atoi(nptr);
v3 = atoi(v6);
return p2p_addr_set(inp, v5, v3, v2);
}

canonical_decompiled_code:
__int64 __fastcall func6(struct in_addr *inp, __int64 a2)
{
__int16 v2; // bx
__int16 v3; // ax
char v5[30]; // [rsp+0h] [rbp-78h] BYREF
char v6[30]; // [rsp+1Eh] [rbp-5Ah] BYREF
char nptr[60]; // [rsp+3Ch] [rbp-3Ch] BYREF

if ( (unsigned int)get_tokens(a2, v5, test_delim) != 3 )
return 0xFFFFFFFFLL;
v2 = atoi(nptr);
v3 = atoi(v6);
return func5(inp, v5, v3, v2);
}

original_code:
int p2p_addr_setstr(p2p_addr dst, const char* p2p_str) {
    char tokens[3][30];
    if (get_tokens(p2p_str, tokens, test_delim) == 3) {
        return p2p_addr_set(dst, tokens[0], atoi(tokens[1]), atoi(tokens[2]));
    } else {
        return -1;
    }
}

canonical_original_code:
int p2p_addr_setstr(struct p2p_addr_struct *dst, char *p2p_str) {
    char tokens[3][30];
    if (get_tokens(p2p_str, tokens, test_delim) == 3) {
        return p2p_addr_set(dst, tokens[0], atoi(tokens[1]), atoi(tokens[2]));
    } else {
        return -1;
    }
}

variable_types:
tokens
char [3][30]


decompiled_code:
__int64 __fastcall p2p_addr_set_undefined(struct in_addr *a1)
{
return p2p_addr_set(a1, "0.0.0.0", 0, 0);
}

canonical_decompiled_code:
__int64 __fastcall func7(struct in_addr *a1)
{
return func5(a1, "0.0.0.0", 0, 0);
}

original_code:
void p2p_addr_set_undefined(p2p_addr addr) {
    p2p_addr_set(addr, "0.0.0.0", 0, 0);
}

canonical_original_code:
void p2p_addr_set_undefined(struct p2p_addr_struct *addr) {
    p2p_addr_set(addr, "0.0.0.0", 0, 0);
}


decompiled_code:
struct in_addr *p2p_addr_create()
{
struct in_addr *v0; // r12

v0 = (struct in_addr *)malloc(8uLL);
p2p_addr_set_undefined(v0);
return v0;
}

canonical_decompiled_code:
struct in_addr *func8()
{
struct in_addr *v0; // r12

v0 = (struct in_addr *)malloc(8uLL);
func7(v0);
return v0;
}

original_code:
p2p_addr p2p_addr_create() {
    p2p_addr a;
    a = (p2p_addr) malloc(sizeof (struct p2p_addr_struct));
    p2p_addr_set_undefined(a);
    return a;
}

canonical_original_code:
struct p2p_addr_struct *p2p_addr_create() {
    struct p2p_addr_struct *a;
    a = (struct p2p_addr_struct *) malloc(sizeof (struct p2p_addr_struct));
    p2p_addr_set_undefined(a);
    return a;
}

return_type: struct p2p_addr_struct { struct in_addr { unsigned int s_addr; } ip; unsigned short tcp_port; unsigned short udp_port; } *


decompiled_code:
_BOOL8 __fastcall p2p_addr_is_undefined(_DWORD *a1)
{
struct in_addr v2[4]; // [rsp+8h] [rbp-10h] BYREF

p2p_addr_set_undefined(v2);
return p2p_addr_is_equal(a1, v2);
}

canonical_decompiled_code:
_BOOL8 __fastcall func10(_DWORD *a1)
{
struct in_addr v2[4]; // [rsp+8h] [rbp-10h] BYREF

func7(v2);
return func4(a1, v2);
}

original_code:
int p2p_addr_is_undefined(const p2p_addr addr) {
    struct p2p_addr_struct u;
    p2p_addr_set_undefined(&u);
    return p2p_addr_is_equal(addr, &u);
}

canonical_original_code:
int p2p_addr_is_undefined(struct p2p_addr_struct *addr) {
    struct p2p_addr_struct u;
    p2p_addr_set_undefined(&u);
    return p2p_addr_is_equal(addr, &u);
}

variable_types: struct p2p_addr_struct { struct in_addr { unsigned int s_addr; } ip; unsigned short tcp_port; unsigned short udp_port; }


decompiled_code:
void *p2p_addr_undefined()
{
p2p_addr_set_undefined((struct in_addr *)&a_1);
return &a_1;
}

canonical_decompiled_code:
void *func11()
{
func7((struct in_addr *)&a_1);
return &a_1;
}

original_code:
p2p_addr p2p_addr_undefined() {
    static struct p2p_addr_struct a;
    p2p_addr_set_undefined(&a);
    return &a;
}

canonical_original_code:
struct p2p_addr_struct *p2p_addr_undefined() {
    static struct p2p_addr_struct a;
    p2p_addr_set_undefined(&a);
    return &a;
}


decompiled_code:
__int64 __fastcall p2p_addr_set_broadcast(struct in_addr *a1)
{
return p2p_addr_set(a1, "255.255.255.255", 0, 0);
}

original_code:
void p2p_addr_set_broadcast(p2p_addr addr) {
    p2p_addr_set(addr, "255.255.255.255", 0, 0);
}

canonical_original_code:
void p2p_addr_set_broadcast(struct p2p_addr_struct *addr) {
    p2p_addr_set(addr, "255.255.255.255", 0, 0);
}


decompiled_code:
_BOOL8 __fastcall p2p_addr_is_broadcast(_DWORD *a1)
{
struct in_addr v2[4]; // [rsp+8h] [rbp-10h] BYREF

p2p_addr_set_broadcast(v2);
return p2p_addr_is_equal(a1, v2);
}

canonical_decompiled_code:
_BOOL8 __fastcall func13(_DWORD *a1)
{
struct in_addr v2[4]; // [rsp+8h] [rbp-10h] BYREF

func12(v2);
return func4(a1, v2);
}

original_code:
int p2p_addr_is_broadcast(const p2p_addr addr) {
    struct p2p_addr_struct b;
    p2p_addr_set_broadcast(&b);
    return p2p_addr_is_equal(addr, &b);
}

canonical_original_code:
int p2p_addr_is_broadcast(struct p2p_addr_struct *addr) {
    struct p2p_addr_struct b;
    p2p_addr_set_broadcast(&b);
    return p2p_addr_is_equal(addr, &b);
}


decompiled_code:
void *p2p_addr_broadcast()
{
p2p_addr_set_broadcast((struct in_addr *)&a_2);
return &a_2;
}

canonical_decompiled_code:
void *func14()
{
func12((struct in_addr *)&a_2);
return &a_2;
}

original_code:
p2p_addr p2p_addr_broadcast() {
    static struct p2p_addr_struct a;
    p2p_addr_set_broadcast(&a);
    return &a;
}

canonical_original_code:
struct p2p_addr_struct *p2p_addr_broadcast() {
    static struct p2p_addr_struct a;
    p2p_addr_set_broadcast(&a);
    return &a;
}


decompiled_code:
char *__fastcall p2p_addr_get_ip_str(struct in_addr *a1)
{
return inet_ntoa((struct in_addr)a1->s_addr);
}

canonical_decompiled_code:
char *__fastcall func15(struct in_addr *a1)
{
return inet_ntoa((struct in_addr)a1->s_addr);
}

original_code:
char* p2p_addr_get_ip_str(p2p_addr addr) {
    return inet_ntoa(addr->ip);
}

canonical_original_code:
char *p2p_addr_get_ip_str(struct p2p_addr_struct *addr) {
    return inet_ntoa(addr->ip);
}


decompiled_code:
__int16 __fastcall p2p_addr_get_tcp_port(__int64 a1)
{
return _bswap_16(*(_WORD *)(a1 + 4));
}

canonical_decompiled_code:
__int16 __fastcall func16(__int64 a1)
{
return func1(*(_WORD *)(a1 + 4));
}

original_code:
unsigned short p2p_addr_get_tcp_port(p2p_addr addr) {
    return ntohs(addr->tcp_port);
}

canonical_original_code:
unsigned short p2p_addr_get_tcp_port(struct p2p_addr_struct *addr) {
    return ntohs(addr->tcp_port);
}

return_type: unsigned short


decompiled_code:
__int16 __fastcall p2p_addr_get_udp_port(__int64 a1)
{
return _bswap_16(*(_WORD *)(a1 + 6));
}

canonical_decompiled_code:
__int16 __fastcall func17(__int64 a1)
{
return func1(*(_WORD *)(a1 + 6));
}

original_code:
unsigned short p2p_addr_get_udp_port(p2p_addr addr) {
    return ntohs(addr->udp_port);
}

canonical_original_code:
unsigned short p2p_addr_get_udp_port(struct p2p_addr_struct *addr) {
    return ntohs(addr->udp_port);
}


decompiled_code:
char *__fastcall p2p_addr_get_str(__int64 a1)
{
unsigned __int16 v1; // bp
__int64 v2; // r9
unsigned __int16 v3; // bx
struct in_addr *v4; // r9
char *v5; // rax

v1 = p2p_addr_get_udp_port(a1);
v3 = p2p_addr_get_tcp_port(v2);
v5 = p2p_addr_get_ip_str(v4);
sprintf(str_0, "%s:%d:%d", v5, v3, v1);
return str_0;
}

canonical_decompiled_code:
char *__fastcall func18(__int64 a1)
{
unsigned __int16 v1; // bp
__int64 v2; // r9
unsigned __int16 v3; // bx
struct in_addr *v4; // r9
char *v5; // rax

v1 = func17(a1);
v3 = func16(v2);
v5 = func15(v4);
sprintf(str_0, "%s:%d:%d", v5, v3, v1);
return str_0;
}

original_code:
char* p2p_addr_get_str(p2p_addr addr) {
    static char str[15 + 1 + 5 + 1 + 5 + 1];
    sprintf(str, "%s:%d:%d",
            p2p_addr_get_ip_str(addr),
            p2p_addr_get_tcp_port(addr),
            p2p_addr_get_udp_port(addr));
    return str;
}

canonical_original_code:
char *p2p_addr_get_str(struct p2p_addr_struct *addr) {
    static char str[-1];
    sprintf(str, "%s:%d:%d",
            p2p_addr_get_ip_str(addr),
            p2p_addr_get_tcp_port(addr),
            p2p_addr_get_udp_port(addr));
    return str;
}

variable_types:
str
char [-1]


decompiled_code:
ssize_t __fastcall p2p_addr_dump(__int64 a1, int a2)
{
unsigned __int16 v2; // r12
__int64 v3; // r9
unsigned __int16 v4; // bx
struct in_addr *v5; // r9
char *v6; // rax
int v7; // eax
char v9[1048]; // [rsp+0h] [rbp-418h] BYREF

v2 = p2p_addr_get_udp_port(a1);
v4 = p2p_addr_get_tcp_port(v3);
v6 = p2p_addr_get_ip_str(v5);
v7 = sprintf(v9, "%s:%d:%d", v6, v4, v2);
return write(a2, v9, v7);
}

canonical_decompiled_code:
ssize_t __fastcall func19(__int64 a1, int a2)
{
unsigned __int16 v2; // r12
__int64 v3; // r9
unsigned __int16 v4; // bx
struct in_addr *v5; // r9
char *v6; // rax
int v7; // eax
char v9[1048]; // [rsp+0h] [rbp-418h] BYREF

v2 = func17(a1);
v4 = func16(v3);
v6 = func15(v5);
v7 = sprintf(v9, "%s:%d:%d", v6, v4, v2);
return write(a2, v9, v7);
}

original_code:
void p2p_addr_dump(const p2p_addr addr, int fd) {
    char buf[1024];
    int length;
    length = sprintf(buf, "%s:%d:%d",
            p2p_addr_get_ip_str(addr),
            p2p_addr_get_tcp_port(addr),
            p2p_addr_get_udp_port(addr));
    write(fd, buf, length);
}

canonical_original_code:
void p2p_addr_dump(struct p2p_addr_struct *addr, int fd) {
    char buf[1024];
    int length;
    length = sprintf(buf, "%s:%d:%d",
            p2p_addr_get_ip_str(addr),
            p2p_addr_get_tcp_port(addr),
            p2p_addr_get_udp_port(addr));
    write(fd, buf, length);
}

variable_types: fd int

variable_types:
buf
char [1024]


original_code:
int
get_tokens(const char *str, char tok[3][30], int (*test_delim)(char)) {
    int i = 0;
    int token = 0;
    int index = 0;
    while (str[i] && token < 3) {
        while (str[i] && test_delim(str[i])) {
            i++;
        }
        index = 0;
        while (str[i] && !test_delim(str[i]) && index < 30) {
            tok[token][index++] = str[i++];
        }
        tok[token++][index] = '\0';
    }
    return token;
}

canonical_original_code:
int get_tokens(char *str, char tok[3][30], int (*test_delim)(char)) {
    int i = 0;
    int token = 0;
    int index = 0;
    while (str[i] && token < 3) {
        while (str[i] && test_delim(str[i])) {
            i++;
        }
        index = 0;
        while (str[i] && !test_delim(str[i]) && index < 30) {
            tok[token][index++] = str[i++];
        }
        tok[token++][index] = '\0';
    }
    return token;
}

variable_types:
str
char *

variable_types:
tok
char [3][30]

variable_types: i int

variable_types: token int

variable_types: index int


decompiled_code:
int __fastcall raw_print(unsigned __int8 *a1, int a2)
{
unsigned __int8 *v2; // r12
unsigned __int8 *v3; // rbx
char v4; // bp
__int64 v5; // rsi

if ( a2 > 0 )
{
v2 = &a1[a2];
v3 = a1 + 1;
printf("%02x ", *a1);
while ( 1 )
{
v4 = (_BYTE)v3 - (_BYTE)a1;
if ( v2 == v3 )
break;
while ( 1 )
{
v5 = *v3++;
printf("%02x ", v5);
if ( (v4 & 0xF) != 15 )
break;
v4 = (_BYTE)v3 - (_BYTE)a1;
putchar(10);
if ( v2 == v3 )
return putchar(10);
}
}
}
return putchar(10);
}

canonical_decompiled_code:
int __fastcall func4(unsigned __int8 *a1, int a2)
{
unsigned __int8 *v2; // r12
unsigned __int8 *v3; // rbx
char v4; // bp
__int64 v5; // rsi

if ( a2 > 0 )
{
v2 = &a1[a2];
v3 = a1 + 1;
printf("%02x ", *a1);
while ( 1 )
{
v4 = (_BYTE)v3 - (_BYTE)a1;
if ( v2 == v3 )
break;
while ( 1 )
{
v5 = *v3++;
printf("%02x ", v5);
if ( (v4 & 0xF) != 15 )
break;
v4 = (_BYTE)v3 - (_BYTE)a1;
putchar(10);
if ( v2 == v3 )
return putchar(10);
}
}
}
return putchar(10);
}

original_code:
void raw_print(char *buf, int size) {
    int i;
    char *visitor;
    visitor = buf;
    for (i = 0; i < size; i++) {
        printf("%02x ", *visitor & 0xff);
        visitor++;
        if (i % 16 == 15) printf("\n");
    }
    printf("\n");
}

variable_types:
buf
char *

variable_types: size int

variable_types:
visitor
char *


decompiled_code:
__int64 __fastcall creer_socket(int type, unsigned __int16 a2)
{
int v2; // eax
unsigned int v3; // er12
socklen_t v4; // edx
int v6; // edi
int v7; // edi
int optval; // [rsp+Ch] [rbp-2Ch] BYREF
struct sockaddr v9[2]; // [rsp+10h] [rbp-28h] BYREF

v2 = socket(2, type, 0);
v3 = v2;
if ( v2 == -1 )
{
perror("Impossible to create the socket");
}
else
{
optval = 1;
if ( setsockopt(v2, 1, 2, &optval, 4u) < 0 )
{
perror("Could'nt setsockopt");
v6 = v3;
v3 = -1;
close(v6);
}
else
{
v9[0].sa_family = 2;
*(_DWORD *)&v9[0].sa_data[2] = _bswap_32_constprop_0(a2, v9, 16LL);
*(_WORD *)v9[0].sa_data = _bswap_16(a2);
if ( bind(v3, v9, v4) == -1 )
{
perror(" Socket attachement failed");
v7 = v3;
v3 = -1;
close(v7);
}
}
}
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func5(int type, unsigned __int16 a2)
{
int v2; // eax
unsigned int v3; // er12
socklen_t v4; // edx
int v6; // edi
int v7; // edi
int optval; // [rsp+Ch] [rbp-2Ch] BYREF
struct sockaddr v9[2]; // [rsp+10h] [rbp-28h] BYREF

v2 = socket(2, type, 0);
v3 = v2;
if ( v2 == -1 )
{
perror("Impossible to create the socket");
}
else
{
optval = 1;
if ( setsockopt(v2, 1, 2, &optval, 4u) < 0 )
{
perror("Could'nt setsockopt");
v6 = v3;
v3 = -1;
close(v6);
}
else
{
v9[0].sa_family = 2;
*(_DWORD *)&v9[0].sa_data[2] = func1(a2, v9, 16LL);
*(_WORD *)v9[0].sa_data = func0(a2);
if ( bind(v3, v9, v4) == -1 )
{
perror(" Socket attachement failed");
v7 = v3;
v3 = -1;
close(v7);
}
}
}
return v3;
}

original_code:
int creer_socket(int type, int port) {
    int desc;
    int valid;
    int longueur = sizeof (struct sockaddr_in);
    struct sockaddr_in adresse;
    if ((desc = socket(2, type, 0)) == -1) {
        perror("Impossible to create the socket");
        return -1;
    }
    valid = 1;
    if (setsockopt(desc, 1, 2, (void*) &valid, sizeof (valid)) < 0) {
        perror("Could'nt setsockopt");
        close(desc);
        return -1;
    }
    adresse.sin_family = 2;
    adresse.sin_addr.s_addr = htonl(((in_addr_t) 0x00000000));
    adresse.sin_port = htons(port);
    if (bind(desc, (struct sockaddr*) &adresse, longueur) == -1) {
        perror(" Socket attachement failed");
        close(desc);
        return -1;
    }
    return desc;
}

canonical_original_code:
int creer_socket(int type, int port) {
    int desc;
    int valid;
    int longueur = sizeof (struct sockaddr_in);
    struct sockaddr_in adresse;
    if ((desc = socket(2, type, 0)) == -1) {
        perror("Impossible to create the socket");
        return -1;
    }
    valid = 1;
    if (setsockopt(desc, 1, 2, (void *) &valid, sizeof (valid)) < 0) {
        perror("Could'nt setsockopt");
        close(desc);
        return -1;
    }
    adresse.sin_family = 2;
    adresse.sin_addr.s_addr = htonl(((unsigned int) 0x00000000));
    adresse.sin_port = htons(port);
    if (bind(desc, (struct sockaddr *) &adresse, longueur) == -1) {
        perror(" Socket attachement failed");
        close(desc);
        return -1;
    }
    return desc;
}

variable_types: type int

variable_types: port int

variable_types: desc int

variable_types: valid int

variable_types: longueur int

variable_types: struct sockaddr_in { unsigned short sin_family; unsigned short sin_port; struct in_addr { unsigned int s_addr; } sin_addr; unsigned char sin_zero[-1]; }

user_defined_types: struct sockaddr_in { unsigned short sin_family; unsigned short sin_port; struct in_addr sin_addr; unsigned char sin_zero[-1]; }

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


max

decompiled_code:
__int64 __fastcall max(signed int a1, signed int a2)
{
__int64 result; // rax

result = (unsigned int)a1;
if ( a1 < a2 )
return (unsigned int)a2;
if ( a1 <= a2 )
result = 0xFFFFFFFFLL;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func6(signed int a1, signed int a2)
{
__int64 result; // rax

result = (unsigned int)a1;
if ( a1 < a2 )
return (unsigned int)a2;
if ( a1 <= a2 )
result = 0xFFFFFFFFLL;
return result;
}

original_code:
int max(int a, int b) {
    if (a < b) {
        return b;
    } else if (a > b) {
        return a;
    } else return -1;
}

variable_types: a int

variable_types: b int


usage

decompiled_code:
int __fastcall usage(__int64 a1)
{
char v2[1016]; // [rsp+0h] [rbp-3F8h] BYREF

strcpy(
v2,
"%s: a p2p node \n"
" -c, --connect=[p2paddr] : connect to node after init \n"
" -d, --dir=[path] : directory for download files \n"
" -s, --server-name=[string] : server name \n"
" -i, --listening-ip=[ip] : listening ip address \n"
" -U, --ui-tcp-port=[port] : listening port for user interface \n"
" -t, --p2p-tcp-port=[port] : listening port for tcp p2p traffic \n"
" -u, --p2p-udp-port=[port] : listening port for udp p2p traffic \n"
" -v, --verbose=[int] : debug verbosity level \n"
" 0 - print nothing \n"
" 1 - print protocol errors \n"
" 2 - trace received msg \n"
" 3 - trace msg actions and content \n"
" 4 - trace server syscalls \n"
" -h, --help : this message \n");
return fprintf(stdout, v2, a1);
}

canonical_decompiled_code:
int __fastcall func0(__int64 a1)
{
char v2[1016]; // [rsp+0h] [rbp-3F8h] BYREF

strcpy(
v2,
"%s: a p2p node \n"
" -c, --connect=[p2paddr] : connect to node after init \n"
" -d, --dir=[path] : directory for download files \n"
" -s, --server-name=[string] : server name \n"
" -i, --listening-ip=[ip] : listening ip address \n"
" -U, --ui-tcp-port=[port] : listening port for user interface \n"
" -t, --p2p-tcp-port=[port] : listening port for tcp p2p traffic \n"
" -u, --p2p-udp-port=[port] : listening port for udp p2p traffic \n"
" -v, --verbose=[int] : debug verbosity level \n"
" 0 - print nothing \n"
" 1 - print protocol errors \n"
" 2 - trace received msg \n"
" 3 - trace msg actions and content \n"
" 4 - trace server syscalls \n"
" -h, --help : this message \n");
return fprintf(stdout, v2, a1);
}

original_code:
void
usage(char* progname) {
    char msg[] = "%s: a p2p node                                                    \n  -c, --connect=[p2paddr]    : connect to node after init         \n  -d, --dir=[path]           : directory for download files       \n  -s, --server-name=[string] : server name                        \n  -i, --listening-ip=[ip]    : listening ip address               \n  -U, --ui-tcp-port=[port]   : listening port for user interface  \n  -t, --p2p-tcp-port=[port]  : listening port for tcp p2p traffic \n  -u, --p2p-udp-port=[port]  : listening port for udp p2p traffic \n  -v, --verbose=[int]        : debug verbosity level              \n                               0 - print nothing                  \n                               1 - print protocol errors          \n                               2 - trace received msg             \n                               3 - trace msg actions and content  \n                               4 - trace server syscalls          \n  -h, --help                 : this message                       \n";
    fprintf(stdout, msg, progname);
}

canonical_original_code:
void usage(char *progname) {
    char msg[] = "%s: a p2p node                                                    \n  -c, --connect=[p2paddr]    : connect to node after init         \n  -d, --dir=[path]           : directory for download files       \n  -s, --server-name=[string] : server name                        \n  -i, --listening-ip=[ip]    : listening ip address               \n  -U, --ui-tcp-port=[port]   : listening port for user interface  \n  -t, --p2p-tcp-port=[port]  : listening port for tcp p2p traffic \n  -u, --p2p-udp-port=[port]  : listening port for udp p2p traffic \n  -v, --verbose=[int]        : debug verbosity level              \n                               0 - print nothing                  \n                               1 - print protocol errors          \n                               2 - trace received msg             \n                               3 - trace msg actions and content  \n                               4 - trace server syscalls          \n  -h, --help                 : this message                       \n";
    fprintf(stdout, msg, progname);
}

variable_types:
progname
char *

variable_types:
msg
char []


decompiled_code:
unsigned __int64 __fastcall test_ui_delim(unsigned __int8 a1)
{
unsigned __int64 result; // rax

result = 0LL;
if ( a1 <= 0x20u )
result = (0x100002600uLL >> a1) & 1;
return result;
}

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

result = 0LL;
if ( a1 <= 0x20u )
result = (0x100002600uLL >> a1) & 1;
return result;
}

variable_types: c char


fileTypeToString

repo: alexpogue/soundutils

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

if ( a2 == 1 )
{
strcpy(a1, "WAVE");
}
else if ( !a2 )
{
result = 57LL;
strcpy(a1, "CS229");
}
return result;
}

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

if ( a2 == 1 )
{
strcpy(a1, "WAVE");
}
else if ( !a2 )
{
result = 57LL;
strcpy(a1, "CS229");
}
return result;
}

original_code:
void fileTypeToString(char* str, fileType_t type) {
  if(type == WAVE) {
    strcpy(str, "WAVE");
  }
  else if(type == CS229) {
    strcpy(str, "CS229");
  }
}

canonical_original_code:
void fileTypeToString(char *str, enum fileType_t type) {
  if(type == WAVE) {
    strcpy(str, "WAVE");
  }
  else if(type == CS229) {
    strcpy(str, "CS229");
  }
}

variable_types:
str
char *

variable_types:
type
enum fileType_t { CS229=0, WAVE=1 }


printSoundDetails

decompiled_code:
int __fastcall printSoundDetails(__int64 a1)
{
unsigned int v1; // eax
float v2; // xmm0_4
char v4[14]; // [rsp+Ah] [rbp-Eh] BYREF

fileTypeToString(v4, *(_DWORD *)(a1 + 8));
printf("File name: %s\n", *(const char **)(a1 + 16));
printf("File type: %s\n", v4);
printf("Sample rate: %ld\n", *(_QWORD *)a1);
printf("Bit depth: %d\n", *(unsigned __int16 *)(a1 + 42));
printf("Number of channels: %d\n", *(unsigned __int16 *)(a1 + 40));
v1 = calculateNumSamples(a1);
printf("Number of samples: %d\n", v1);
v2 = calculateSoundLength(a1);
return printf("Sound length (seconds): %.3f\n", v2);
}

canonical_decompiled_code:
int __fastcall func3(__int64 a1)
{
unsigned int v1; // eax
float v2; // xmm0_4
char v4[14]; // [rsp+Ah] [rbp-Eh] BYREF

func2(v4, *(_DWORD *)(a1 + 8));
printf("File name: %s\n", *(const char **)(a1 + 16));
printf("File type: %s\n", v4);
printf("Sample rate: %ld\n", *(_QWORD *)a1);
printf("Bit depth: %d\n", *(unsigned __int16 *)(a1 + 42));
printf("Number of channels: %d\n", *(unsigned __int16 *)(a1 + 40));
v1 = calculateNumSamples(a1);
printf("Number of samples: %d\n", v1);
v2 = calculateSoundLength(a1);
return printf("Sound length (seconds): %.3f\n", v2);
}

original_code:
void printSoundDetails(sound_t* sound) {
  char typeStr[6];
  fileTypeToString(typeStr, sound->fileType);
  printf("File name: %s\n", sound->fileName);
  printf("File type: %s\n", typeStr);
  printf("Sample rate: %ld\n", sound->sampleRate);
  printf("Bit depth: %d\n", sound->bitDepth);
  printf("Number of channels: %d\n", sound->numChannels);
  printf("Number of samples: %d\n", calculateNumSamples(sound));
  printf("Sound length (seconds): %.3f\n", calculateSoundLength(sound));
}

canonical_original_code:
void printSoundDetails(struct sound_t *sound) {
  char typeStr[6];
  fileTypeToString(typeStr, sound->fileType);
  printf("File name: %s\n", sound->fileName);
  printf("File type: %s\n", typeStr);
  printf("Sample rate: %ld\n", sound->sampleRate);
  printf("Bit depth: %d\n", sound->bitDepth);
  printf("Number of channels: %d\n", sound->numChannels);
  printf("Number of samples: %d\n", calculateNumSamples(sound));
  printf("Sound length (seconds): %.3f\n", calculateSoundLength(sound));
}

variable_types: struct sound_t { unsigned long sampleRate; enum fileType_t { CS229=0, WAVE=1 } fileType; char *fileName; void *rawData; unsigned int dataSize; enum readError_t { NO_ERROR=0, ERROR_EOF=1, ERROR_READING=2, ERROR_MEMORY=3, ERROR_FILETYPE=4, ERROR_BIT_DEPTH=5, ERROR_INVALID_KEYWORD=6, ERROR_NO_VALUE=7, ERROR_SAMPLE_DATA=8, ERROR_ZERO_CHANNELS=9 } error; unsigned short numChannels; unsigned short bitDepth; } *

variable_types:
typeStr
char [6]

user_defined_types: struct sound_t { unsigned long sampleRate; enum fileType_t fileType; char *fileName; void *rawData; unsigned int dataSize; enum readError_t error; unsigned short numChannels; unsigned short bitDepth; }


printUsage

decompiled_code:
int __fastcall printUsage(const char *a1)
{
return printf("Usage: %s file1 [file2 ...]\n\n", a1);
}

canonical_decompiled_code:
int __fastcall func0(const char *a1)
{
return printf("Usage: %s file1 [file2 ...]\n\n", a1);
}

original_code:
void printUsage(char* exeName) {
  printf("Usage: %s file1 [file2 ...]\n\n", exeName);
}

canonical_original_code:
void printUsage(char *exeName) {
  printf("Usage: %s file1 [file2 ...]\n\n", exeName);
}

variable_types:
exeName
char *


printHelp

decompiled_code:
int __fastcall printHelp(const char *a1)
{
puts("Sndinfo Help:");
printUsage(a1);
puts("Utility:");
puts("This program reads each wav and CS229 sound file passed as");
puts("arguments and outputs their information.\n");
puts("Options: ");
return puts("-h\tdisplays this help page");
}

canonical_decompiled_code:
int __fastcall func1(const char *a1)
{
puts("Sndinfo Help:");
func0(a1);
puts("Utility:");
puts("This program reads each wav and CS229 sound file passed as");
puts("arguments and outputs their information.\n");
puts("Options: ");
return puts("-h\tdisplays this help page");
}

original_code:
void printHelp(char* exeName) {
  printf("Sndinfo Help:\n");
  printUsage(exeName);
  printf("Utility:\n");
  printf("This program reads each wav and CS229 sound file passed as\n");
  printf("arguments and outputs their information.\n\n");
  printf("Options: \n");
  printf("-h\tdisplays this help page\n");
}

canonical_original_code:
void printHelp(char *exeName) {
  printf("Sndinfo Help:\n");
  printUsage(exeName);
  printf("Utility:\n");
  printf("This program reads each wav and CS229 sound file passed as\n");
  printf("arguments and outputs their information.\n\n");
  printf("Options: \n");
  printf("-h\tdisplays this help page\n");
}


printMemoryError

decompiled_code:
size_t printMemoryError()
{
return fwrite("Could not allocate memory\n", 1uLL, 0x1AuLL, stderr);
}

canonical_decompiled_code:
size_t func0()
{
return fwrite("Could not allocate memory\n", 1uLL, 0x1AuLL, stderr);
}

original_code:
void printMemoryError() {
  fprintf(stderr, "Could not allocate memory\n");
}


printFileTypeError

decompiled_code:
size_t printFileTypeError()
{
return fwrite("Unknown file type\n", 1uLL, 0x12uLL, stderr);
}

canonical_decompiled_code:
size_t func1()
{
return fwrite("Unknown file type\n", 1uLL, 0x12uLL, stderr);
}

original_code:
void printFileTypeError() {
  fprintf(stderr, "Unknown file type\n");
}


printFileOpenError

decompiled_code:
int __fastcall printFileOpenError(const char *a1)
{
return fprintf(stderr, "Could not open file: %s\n", a1);
}

canonical_decompiled_code:
int __fastcall func2(const char *a1)
{
return fprintf(stderr, "Could not open file: %s\n", a1);
}

original_code:
void printFileOpenError(char* filePath) {
  fprintf(stderr, "Could not open file: %s\n", filePath);
}

canonical_original_code:
void printFileOpenError(char *filePath) {
  fprintf(stderr, "Could not open file: %s\n", filePath);
}

variable_types:
filePath
char *


printSoundLoadError

decompiled_code:
size_t printSoundLoadError()
{
return fwrite("Could not load sound\n", 1uLL, 0x15uLL, stderr);
}

canonical_decompiled_code:
size_t func3()
{
return fwrite("Could not load sound\n", 1uLL, 0x15uLL, stderr);
}

original_code:
void printSoundLoadError() {
  fprintf(stderr, "Could not load sound\n");
}


printEofError

decompiled_code:
size_t printEofError()
{
return fwrite("Unexpected end of file\n", 1uLL, 0x17uLL, stderr);
}

canonical_decompiled_code:
size_t func4()
{
return fwrite("Unexpected end of file\n", 1uLL, 0x17uLL, stderr);
}

original_code:
void printEofError() {
  fprintf(stderr, "Unexpected end of file\n");
}


printFileReadError

decompiled_code:
size_t printFileReadError()
{
return fwrite("Could not read file\n", 1uLL, 0x14uLL, stderr);
}

canonical_decompiled_code:
size_t func5()
{
return fwrite("Could not read file\n", 1uLL, 0x14uLL, stderr);
}

original_code:
void printFileReadError() {
  fprintf(stderr, "Could not read file\n");
}


printInvalidOptionError

decompiled_code:
int __fastcall printInvalidOptionError(char a1)
{
return fprintf(stderr, "Unknown option -%c. Use -h for help.\n", (unsigned int)a1);
}

canonical_decompiled_code:
int __fastcall func6(char a1)
{
return fprintf(stderr, "Unknown option -%c. Use -h for help.\n", (unsigned int)a1);
}

original_code:
void printInvalidOptionError(char optionChar) {
  fprintf(stderr, "Unknown option -%c. Use -h for help.\n", optionChar);
}

variable_types: optionChar char


printBitDepthError

decompiled_code:
size_t printBitDepthError()
{
return fwrite("Unsupported bit depth encountered\n", 1uLL, 0x22uLL, stderr);
}

canonical_decompiled_code:
size_t func7()
{
return fwrite("Unsupported bit depth encountered\n", 1uLL, 0x22uLL, stderr);
}

original_code:
void printBitDepthError() {
  fprintf(stderr, "Unsupported bit depth encountered\n");
}


printInvalidKeywordError

decompiled_code:
size_t printInvalidKeywordError()
{
return fwrite("Invalid keyword found in file\n", 1uLL, 0x1EuLL, stderr);
}

canonical_decompiled_code:
size_t func8()
{
return fwrite("Invalid keyword found in file\n", 1uLL, 0x1EuLL, stderr);
}

original_code:
void printInvalidKeywordError() {
  fprintf(stderr, "Invalid keyword found in file\n");
}


printNoValueError

decompiled_code:
size_t printNoValueError()
{
return fwrite("No value given for a keyword in the file\n", 1uLL, 0x29uLL, stderr);
}

canonical_decompiled_code:
size_t func9()
{
return fwrite("No value given for a keyword in the file\n", 1uLL, 0x29uLL, stderr);
}

original_code:
void printNoValueError() {
  fprintf(stderr, "No value given for a keyword in the file\n");
}


printSampleDataError

decompiled_code:
size_t printSampleDataError()
{
return fwrite("Corrupted sample data in the file\n", 1uLL, 0x22uLL, stderr);
}

canonical_decompiled_code:
size_t func10()
{
return fwrite("Corrupted sample data in the file\n", 1uLL, 0x22uLL, stderr);
}

original_code:
void printSampleDataError() {
  fprintf(stderr, "Corrupted sample data in the file\n");
}


printSampleRateError

decompiled_code:
size_t printSampleRateError()
{
return fwrite("Incompatible sample rates in sounds\n", 1uLL, 0x24uLL, stderr);
}

canonical_decompiled_code:
size_t func11()
{
return fwrite("Incompatible sample rates in sounds\n", 1uLL, 0x24uLL, stderr);
}

original_code:
void printSampleRateError() {
  fprintf(stderr, "Incompatible sample rates in sounds\n");
}


printZeroChannelsError

decompiled_code:
size_t printZeroChannelsError()
{
return fwrite("Sound is either empty or incorrectly zero channels\n", 1uLL, 0x33uLL, stderr);
}

canonical_decompiled_code:
size_t func12()
{
return fwrite("Sound is either empty or incorrectly zero channels\n", 1uLL, 0x33uLL, stderr);
}

original_code:
void printZeroChannelsError() {
  fprintf(stderr, "Sound is either empty or incorrectly zero channels\n");
}


printErrorsInSound

decompiled_code:
int __fastcall printErrorsInSound(__int64 a1)
{
int result; // eax
int v2; // eax

result = *(_DWORD *)(a1 + 36);
if ( result )
{
fprintf(stderr, "Error in file: %s\n", *(const char **)(a1 + 16));
v2 = *(_DWORD *)(a1 + 36);
switch ( v2 )
{
case 1:
result = printEofError();
break;
case 2:
result = printFileReadError();
break;
case 3:
result = printMemoryError();
break;
case 4:
result = printFileTypeError();
break;
case 5:
result = printBitDepthError();
break;
case 6:
result = printInvalidKeywordError();
break;
case 7:
result = printNoValueError();
break;
case 8:
result = printSampleDataError();
break;
case 9:
result = printZeroChannelsError();
break;
default:
result = puts("Unforeseen error occurred!");
break;
}
}
return result;
}

canonical_decompiled_code:
int __fastcall func13(__int64 a1)
{
int result; // eax
int v2; // eax

result = *(_DWORD *)(a1 + 36);
if ( result )
{
fprintf(stderr, "Error in file: %s\n", *(const char **)(a1 + 16));
v2 = *(_DWORD *)(a1 + 36);
switch ( v2 )
{
case 1:
result = func4();
break;
case 2:
result = func5();
break;
case 3:
result = func0();
break;
case 4:
result = func1();
break;
case 5:
result = func7();
break;
case 6:
result = func8();
break;
case 7:
result = func9();
break;
case 8:
result = func10();
break;
case 9:
result = func12();
break;
default:
result = puts("Unforeseen error occurred!");
break;
}
}
return result;
}

original_code:
void printErrorsInSound(sound_t* sound) {
  if(sound->error == NO_ERROR) {
    return;
  }
  fprintf(stderr, "Error in file: %s\n", sound->fileName);
  if(sound->error == ERROR_EOF) {
    printEofError();
  }
  else if(sound->error == ERROR_READING) {
    printFileReadError();
  }
  else if(sound->error == ERROR_MEMORY) {
    printMemoryError();
  }
  else if(sound->error == ERROR_FILETYPE) {
    printFileTypeError();
  }
  else if(sound->error == ERROR_BIT_DEPTH) {
    printBitDepthError();
  }
  else if(sound->error == ERROR_INVALID_KEYWORD) {
    printInvalidKeywordError();
  }
  else if(sound->error == ERROR_NO_VALUE) {
    printNoValueError();
  }
  else if(sound->error == ERROR_SAMPLE_DATA) {
    printSampleDataError();
  }
  else if(sound->error == ERROR_ZERO_CHANNELS) {
    printZeroChannelsError();
  }
  else {
    printf("Unforeseen error occurred!\n");
  }
}

canonical_original_code:
void printErrorsInSound(struct sound_t *sound) {
  if(sound->error == NO_ERROR) {
    return;
  }
  fprintf(stderr, "Error in file: %s\n", sound->fileName);
  if(sound->error == ERROR_EOF) {
    printEofError();
  }
  else if(sound->error == ERROR_READING) {
    printFileReadError();
  }
  else if(sound->error == ERROR_MEMORY) {
    printMemoryError();
  }
  else if(sound->error == ERROR_FILETYPE) {
    printFileTypeError();
  }
  else if(sound->error == ERROR_BIT_DEPTH) {
    printBitDepthError();
  }
  else if(sound->error == ERROR_INVALID_KEYWORD) {
    printInvalidKeywordError();
  }
  else if(sound->error == ERROR_NO_VALUE) {
    printNoValueError();
  }
  else if(sound->error == ERROR_SAMPLE_DATA) {
    printSampleDataError();
  }
  else if(sound->error == ERROR_ZERO_CHANNELS) {
    printZeroChannelsError();
  }
  else {
    printf("Unforeseen error occurred!\n");
  }
}

user_defined_types: enum readError_t { NO_ERROR=0, ERROR_EOF=1, ERROR_READING=2, ERROR_MEMORY=3, ERROR_FILETYPE=4, ERROR_BIT_DEPTH=5, ERROR_INVALID_KEYWORD=6, ERROR_NO_VALUE=7, ERROR_SAMPLE_DATA=8, ERROR_ZERO_CHANNELS=9 }


distributeIntoChannels

decompiled_code:
unsigned __int64 __fastcall distributeIntoChannels(__int64 a1, __int64 a2)
{
unsigned __int64 result; // rax
__int64 v3; // rbp
__int64 v4; // rbx
int v5; // er12
int v6; // er11
int v7; // er10
int v8; // er9
int v9; // er8
__int64 v10; // rsi
unsigned __int64 v11; // rdx

result = (unsigned __int64)realloc(*(void **)(a1 + 24), *(unsigned int *)(a1 + 32));
if ( result )
{
*(_QWORD *)(a1 + 24) = result;
v3 = *(_QWORD *)(a2 + 24);
addZeroedChannels(*(unsigned __int16 *)(a2 + 40), a1);
v4 = *(_QWORD *)(a1 + 24);
v5 = calculateNumSamples(a1);
result = *(unsigned __int16 *)(a2 + 42);
v6 = (int)(result * *(unsigned __int16 *)(a1 + 40)) >> 3;
v7 = (int)(result * *(unsigned __int16 *)(a2 + 40)) >> 3;
if ( v5 > 0 )
{
result = v7;
v8 = 0;
v9 = 0;
v10 = v4 + v6 - (__int64)v7;
do
{
++v9;
if ( v7 )
{
result = 0LL;
do
{
*(_BYTE *)(v10 + result) = *(_BYTE *)(v3 + v8 + result);
v11 = result++;
}
while ( v7 - 1 != v11 );
}
v8 += v7;
v10 += v6;
}
while ( v9 != v5 );
}
}
else
{
*(_DWORD *)(a1 + 36) = 3;
}
return result;
}

canonical_decompiled_code:
unsigned __int64 __fastcall func0(__int64 a1, __int64 a2)
{
unsigned __int64 result; // rax
__int64 v3; // rbp
__int64 v4; // rbx
int v5; // er12
int v6; // er11
int v7; // er10
int v8; // er9
int v9; // er8
__int64 v10; // rsi
unsigned __int64 v11; // rdx

result = (unsigned __int64)realloc(*(void **)(a1 + 24), *(unsigned int *)(a1 + 32));
if ( result )
{
*(_QWORD *)(a1 + 24) = result;
v3 = *(_QWORD *)(a2 + 24);
addZeroedChannels(*(unsigned __int16 *)(a2 + 40), a1);
v4 = *(_QWORD *)(a1 + 24);
v5 = calculateNumSamples(a1);
result = *(unsigned __int16 *)(a2 + 42);
v6 = (int)(result * *(unsigned __int16 *)(a1 + 40)) >> 3;
v7 = (int)(result * *(unsigned __int16 *)(a2 + 40)) >> 3;
if ( v5 > 0 )
{
result = v7;
v8 = 0;
v9 = 0;
v10 = v4 + v6 - (__int64)v7;
do
{
++v9;
if ( v7 )
{
result = 0LL;
do
{
*(_BYTE *)(v10 + result) = *(_BYTE *)(v3 + v8 + result);
v11 = result++;
}
while ( v7 - 1 != v11 );
}
v8 += v7;
v10 += v6;
}
while ( v9 != v5 );
}
}
else
{
*(_DWORD *)(a1 + 36) = 3;
}
return result;
}

original_code:
void distributeIntoChannels(sound_t* dest, sound_t* append) {
  int i, j, numSamples, bytesPerDestSample, bytesPerAppendSample;
  void* newData = realloc(dest->rawData, dest->dataSize);
  char *destCharData, *appendCharData;
  if(!newData) {
    dest->error = ERROR_MEMORY;
    return;
  }
  dest->rawData = newData;
  appendCharData = (char*)append->rawData;
  addZeroedChannels(append->numChannels, dest);
  destCharData = (char*)dest->rawData;
  numSamples = calculateNumSamples(dest);
  bytesPerDestSample = dest->numChannels * append->bitDepth / 8;
  bytesPerAppendSample = append->numChannels * append->bitDepth / 8;
  for(i = 0; i < numSamples; i++) {
    int firstNewData = bytesPerDestSample * (i + 1) - bytesPerAppendSample;
    for(j = 0; j < bytesPerAppendSample; j++) {
      destCharData[firstNewData + j] = appendCharData[i * bytesPerAppendSample + j];
    }
  }
}

canonical_original_code:
void distributeIntoChannels(struct sound_t *dest, struct sound_t *append) {
  int i; int j; int numSamples; int bytesPerDestSample; int bytesPerAppendSample;
  void *newData = realloc(dest->rawData, dest->dataSize);
  char *destCharData; char *appendCharData;
  if(!newData) {
    dest->error = ERROR_MEMORY;
    return;
  }
  dest->rawData = newData;
  appendCharData = (char *)append->rawData;
  addZeroedChannels(append->numChannels, dest);
  destCharData = (char *)dest->rawData;
  numSamples = calculateNumSamples(dest);
  bytesPerDestSample = dest->numChannels * append->bitDepth / 8;
  bytesPerAppendSample = append->numChannels * append->bitDepth / 8;
  for(i = 0; i < numSamples; i++) {
    int firstNewData = bytesPerDestSample * (i + 1) - bytesPerAppendSample;
    for(j = 0; j < bytesPerAppendSample; j++) {
      destCharData[firstNewData + j] = appendCharData[i * bytesPerAppendSample + j];
    }
  }
}

variable_types:
append
struct sound_t *

variable_types: i int

variable_types: j int

variable_types: numSamples int

variable_types: bytesPerDestSample int

variable_types: bytesPerAppendSample int

variable_types:
newData
void *

variable_types:
destCharData
char *

variable_types:
appendCharData
char *

variable_types: firstNewData int


combineChannels

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

if ( (unsigned int)ensureSoundChannelsCombinable() == -1 )
result = printSampleRateError();
else
result = distributeIntoChannels(a1, a2);
return result;
}

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

if ( (unsigned int)ensureSoundChannelsCombinable() == -1 )
result = printSampleRateError();
else
result = func0(a1, a2);
return result;
}

original_code:
void combineChannels(sound_t* s1, sound_t* s2, fileType_t resultType) {
  if(ensureSoundChannelsCombinable(s1, s2, resultType) == -1) {
    printSampleRateError();
    return;
  }
  distributeIntoChannels(s1, s2);
}

canonical_original_code:
void combineChannels(struct sound_t *s1, struct sound_t *s2, enum fileType_t resultType) {
  if(ensureSoundChannelsCombinable(s1, s2, resultType) == -1) {
    printSampleRateError();
    return;
  }
  distributeIntoChannels(s1, s2);
}

variable_types:
resultType
enum fileType_t { CS229=0, WAVE=1 }


combineChannelsSoundArray

decompiled_code:
unsigned __int64 __fastcall combineChannelsSoundArray(__int64 a1, _QWORD *a2, int a3)
{
_QWORD *v3; // r14
__int64 *v4; // rbx
__int64 *v6; // rbp
__int64 v7; // r15
__int64 v8; // rsi
unsigned __int64 result; // rax
__int64 v10; // rsi

v3 = a2;
if ( a3 <= 0 )
return deepCopySound(a1, *a2);
v4 = a2 + 1;
v6 = a2;
v7 = (__int64)&a2[(unsigned int)(a3 - 1) + 1];
do
{
v8 = *v6++;
convertToFileType(*(unsigned int *)(a1 + 8), v8);
}
while ( v6 != (__int64 *)v7 );
result = deepCopySound(a1, *v3);
if ( a3 > 1 )
{
do
{
v10 = *v4++;
result = combineChannels(a1, v10);
}
while ( v4 != &v3[(unsigned int)(a3 - 2) + 2] );
}
return result;
}

canonical_decompiled_code:
unsigned __int64 __fastcall func2(__int64 a1, _QWORD *a2, int a3)
{
_QWORD *v3; // r14
__int64 *v4; // rbx
__int64 *v6; // rbp
__int64 v7; // r15
__int64 v8; // rsi
unsigned __int64 result; // rax
__int64 v10; // rsi

v3 = a2;
if ( a3 <= 0 )
return deepCopySound(a1, *a2);
v4 = a2 + 1;
v6 = a2;
v7 = (__int64)&a2[(unsigned int)(a3 - 1) + 1];
do
{
v8 = *v6++;
convertToFileType(*(unsigned int *)(a1 + 8), v8);
}
while ( v6 != (__int64 *)v7 );
result = deepCopySound(a1, *v3);
if ( a3 > 1 )
{
do
{
v10 = *v4++;
result = func1(a1, v10);
}
while ( v4 != &v3[(unsigned int)(a3 - 2) + 2] );
}
return result;
}

original_code:
void combineChannelsSoundArray(sound_t* dest, sound_t** sounds, int numSounds) {
  int i;
  for(i = 0; i < numSounds; i++) {
    convertToFileType(dest->fileType, sounds[i]);
  }
  deepCopySound(dest, sounds[0]);
  for(i = 1; i < numSounds; i++) {
    combineChannels(dest, sounds[i], dest->fileType);
  }
}

canonical_original_code:
void combineChannelsSoundArray(struct sound_t *dest, struct sound_t **sounds, int numSounds) {
  int i;
  for(i = 0; i < numSounds; i++) {
    convertToFileType(dest->fileType, sounds[i]);
  }
  deepCopySound(dest, sounds[0]);
  for(i = 1; i < numSounds; i++) {
    combineChannels(dest, sounds[i], dest->fileType);
  }
}

variable_types:
sounds
struct sound_t **

variable_types: numSounds int


printHelp

decompiled_code:
int __fastcall printHelp(const char *a1)
{
puts("Sndchan Help:");
printf("Usage: %s file1 [file2 ...] [options]\n\n", a1);
puts("Utility:");
puts("This program reads the files passed as arguments and combines the channels of");
puts("them into a single sound. The resulting sound will be the \"overlay\" of the");
puts("source sounds. \n");
puts("Defaults:");
puts("Default output is in CS229 format (see -w option to change). ");
puts("Default output is to stdout unless another file is given (with -o)");
puts("If no source files are given, tries to read file from stdin\n");
puts("Options:");
puts("-c [n]\t\tOnly include channel n in output (1st channel = 0, etc.)");
puts("-h\t\tPrint this screen");
puts("-o [fileName]\tOutput file to fileName");
return puts("-w\t\tOutput in WAVE format");
}

canonical_decompiled_code:
int __fastcall func3(const char *a1)
{
puts("Sndchan Help:");
printf("Usage: %s file1 [file2 ...] [options]\n\n", a1);
puts("Utility:");
puts("This program reads the files passed as arguments and combines the channels of");
puts("them into a single sound. The resulting sound will be the \"overlay\" of the");
puts("source sounds. \n");
puts("Defaults:");
puts("Default output is in CS229 format (see -w option to change). ");
puts("Default output is to stdout unless another file is given (with -o)");
puts("If no source files are given, tries to read file from stdin\n");
puts("Options:");
puts("-c [n]\t\tOnly include channel n in output (1st channel = 0, etc.)");
puts("-h\t\tPrint this screen");
puts("-o [fileName]\tOutput file to fileName");
return puts("-w\t\tOutput in WAVE format");
}

original_code:
void printHelp(char* cmd) {
  printf("Sndchan Help:\n");
  printf("Usage: %s file1 [file2 ...] [options]\n\n", cmd);
  printf("Utility:\n");
  printf("This program reads the files passed as arguments and combines the channels of\n");
  printf("them into a single sound. The resulting sound will be the \"overlay\" of the\n");
  printf("source sounds. \n\n");
  printf("Defaults:\n");
  printf("Default output is in CS229 format (see -w option to change). \n");
  printf("Default output is to stdout unless another file is given (with -o)\n");
  printf("If no source files are given, tries to read file from stdin\n\n");
  printf("Options:\n");
  printf("-c [n]\t\tOnly include channel n in output (1st channel = 0, etc.)\n");
  printf("-h\t\tPrint this screen\n");
  printf("-o [fileName]\tOutput file to fileName\n");
  printf("-w\t\tOutput in WAVE format\n");
}

canonical_original_code:
void printHelp(char *cmd) {
  printf("Sndchan Help:\n");
  printf("Usage: %s file1 [file2 ...] [options]\n\n", cmd);
  printf("Utility:\n");
  printf("This program reads the files passed as arguments and combines the channels of\n");
  printf("them into a single sound. The resulting sound will be the \"overlay\" of the\n");
  printf("source sounds. \n\n");
  printf("Defaults:\n");
  printf("Default output is in CS229 format (see -w option to change). \n");
  printf("Default output is to stdout unless another file is given (with -o)\n");
  printf("If no source files are given, tries to read file from stdin\n\n");
  printf("Options:\n");
  printf("-c [n]\t\tOnly include channel n in output (1st channel = 0, etc.)\n");
  printf("-h\t\tPrint this screen\n");
  printf("-o [fileName]\tOutput file to fileName\n");
  printf("-w\t\tOutput in WAVE format\n");
}

variable_types:
cmd
char *


handleCommandLineArgs

decompiled_code:
__int64 __fastcall handleCommandLineArgs(int a1, const char **a2, __int64 a3, __int64 a4, int *a5, _DWORD *a6, _QWORD *a7)
{
int v11; // ebx
__int64 v12; // rax
const char *v13; // rdx
__int64 v14; // rsi
char v15; // al
unsigned int v17; // [rsp+Ch] [rbp-3Ch]

*a6 = -1;
if ( a1 <= 1 )
return 0;
v17 = 0;
v11 = 1;
while ( 1 )
{
while ( 1 )
{
v13 = a2[v11];
v14 = v11;
if ( *v13 == 45 )
break;
v12 = *a5;
*a5 = v12 + 1;
*(_QWORD *)(a3 + 8 * v12) = v13;
LABEL_4:
if ( a1 <= ++v11 )
return v17;
}
v15 = v13[1];
switch ( v15 )
{
case 'h':
printHelp(*a2);
*a5 = -1;
return v17;
case 'o':
++v11;
*a7 = a2[v14 + 1];
goto LABEL_4;
case 'w':
v17 = 1;
goto LABEL_4;
}
if ( v15 != 99 )
break;
v11 += 2;
*a6 = strtol(a2[v14 + 1], 0LL, 10);
if ( a1 <= v11 )
return v17;
}
printInvalidOptionError((unsigned int)v15, v14 * 8);
*a5 = -1;
return v17;
}

original_code:
fileType_t handleCommandLineArgs(int argc, char** argv, char** fileNames, int capacity, int* numFilesRead, int* outputChannel, char** outputFileName) {
  int i;
  fileType_t outputType = CS229;
  *outputChannel = -1;
  for(i = 1; i < argc; i++) {
    if(argv[i][0] == '-') {
      if(argv[i][1] == 'h') {
        printHelp(argv[0]);
        *numFilesRead = -1;
        return outputType;
      }
      else if(argv[i][1] == 'o') {
        *outputFileName = argv[i+1];
        ++i;
      }
      else if(argv[i][1] == 'w') {
        outputType = WAVE;
      }
      else if(argv[i][1] == 'c') {
        *outputChannel = strtol(argv[i+1], ((void *)0), 10);
        ++i;
      }
      else {
        printInvalidOptionError(argv[i][1]);
        *numFilesRead = -1;
        return outputType;
      }
    }
    else {
      fileNames[(*numFilesRead)++] = argv[i];
    }
  }
  return outputType;
}

canonical_original_code:
enum fileType_t handleCommandLineArgs(int argc, char **argv, char **fileNames, int capacity, int *numFilesRead, int *outputChannel, char **outputFileName) {
  int i;
  enum fileType_t outputType = CS229;
  *outputChannel = -1;
  for(i = 1; i < argc; i++) {
    if(argv[i][0] == '-') {
      if(argv[i][1] == 'h') {
        printHelp(argv[0]);
        *numFilesRead = -1;
        return outputType;
      }
      else if(argv[i][1] == 'o') {
        *outputFileName = argv[i+1];
        ++i;
      }
      else if(argv[i][1] == 'w') {
        outputType = WAVE;
      }
      else if(argv[i][1] == 'c') {
        *outputChannel = strtol(argv[i+1], ((void *)0), 10);
        ++i;
      }
      else {
        printInvalidOptionError(argv[i][1]);
        *numFilesRead = -1;
        return outputType;
      }
    }
    else {
      fileNames[(*numFilesRead)++] = argv[i];
    }
  }
  return outputType;
}

variable_types: argc int

variable_types:
argv
char **

variable_types:
fileNames
char **

variable_types: capacity int

variable_types:
numFilesRead
int *

variable_types:
outputChannel
int *

variable_types:
outputFileName
char **

variable_types:
outputType
enum fileType_t { CS229=0, WAVE=1 }

return_type: enum fileType_t { CS229=0, WAVE=1 }


concatenateData

decompiled_code:
__int64 __fastcall concatenateData(__int64 a1, __int64 a2)
{
int v4; // er12
_BYTE *v5; // rax
_BYTE *v6; // rsi
__int64 result; // rax
__int64 v8; // rdi
char v9; // cl
__int64 v10; // rdx

v4 = *(_DWORD *)(a1 + 32) + *(_DWORD *)(a2 + 32);
v5 = realloc(*(void **)(a1 + 24), v4);
if ( v5 )
{
*(_QWORD *)(a1 + 24) = v5;
v6 = v5;
result = *(unsigned int *)(a2 + 32);
v8 = *(_QWORD *)(a2 + 24);
if ( (_DWORD)result )
{
result = 0LL;
do
{
v9 = *(_BYTE *)(v8 + result);
v10 = (unsigned int)(*(_DWORD *)(a1 + 32) + result++);
v6[v10] = v9;
}
while ( *(_DWORD *)(a2 + 32) > (unsigned int)result );
}
*(_DWORD *)(a1 + 32) = v4;
}
else
{
result = printMemoryError();
*(_DWORD *)(a1 + 36) = 3;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, __int64 a2)
{
int v4; // er12
_BYTE *v5; // rax
_BYTE *v6; // rsi
__int64 result; // rax
__int64 v8; // rdi
char v9; // cl
__int64 v10; // rdx

v4 = *(_DWORD *)(a1 + 32) + *(_DWORD *)(a2 + 32);
v5 = realloc(*(void **)(a1 + 24), v4);
if ( v5 )
{
*(_QWORD *)(a1 + 24) = v5;
v6 = v5;
result = *(unsigned int *)(a2 + 32);
v8 = *(_QWORD *)(a2 + 24);
if ( (_DWORD)result )
{
result = 0LL;
do
{
v9 = *(_BYTE *)(v8 + result);
v10 = (unsigned int)(*(_DWORD *)(a1 + 32) + result++);
v6[v10] = v9;
}
while ( *(_DWORD *)(a2 + 32) > (unsigned int)result );
}
*(_DWORD *)(a1 + 32) = v4;
}
else
{
result = printMemoryError();
*(_DWORD *)(a1 + 36) = 3;
}
return result;
}

original_code:
void concatenateData(sound_t* dest, sound_t* append) {
  int i;
  char *destCharData, *appendCharData;
  int newDataSize = dest->dataSize + append->dataSize;
  char* newData = (char*)realloc(dest->rawData, newDataSize);
  if(!newData) {
    printMemoryError();
    dest->error = ERROR_MEMORY;
    return;
  }
  dest->rawData = newData;
  destCharData = (char*)dest->rawData;
  appendCharData = (char*)append->rawData;
  for(i = 0; i < append->dataSize; i++) {
    destCharData[dest->dataSize + i] = appendCharData[i];
  }
  dest->dataSize = newDataSize;
}

canonical_original_code:
void concatenateData(struct sound_t *dest, struct sound_t *append) {
  int i;
  char *destCharData; char *appendCharData;
  int newDataSize = dest->dataSize + append->dataSize;
  char *newData = (char*)realloc(dest->rawData, newDataSize);
  if(!newData) {
    printMemoryError();
    dest->error = ERROR_MEMORY;
    return;
  }
  dest->rawData = newData;
  destCharData = (char *)dest->rawData;
  appendCharData = (char *)append->rawData;
  for(i = 0; i < append->dataSize; i++) {
    destCharData[dest->dataSize + i] = appendCharData[i];
  }
  dest->dataSize = newDataSize;
}

variable_types: struct sound_t { unsigned long sampleRate; enum fileType_t { CS229=0, WAVE=1 } fileType; char *fileName; void *rawData; unsigned int dataSize; enum readError_t { NO_ERROR=0, ERROR_EOF=1, ERROR_READING=2, ERROR_MEMORY=3, ERROR_FILETYPE=4, ERROR_BIT_DEPTH=5, ERROR_INVALID_KEYWORD=6, ERROR_NO_VALUE=7, ERROR_SAMPLE_DATA=8, ERROR_ZERO_CHANNELS=9 } error; unsigned short numChannels; unsigned short bitDepth; } *

variable_types:
append
struct sound_t *

variable_types: i int

variable_types: newDataSize int

variable_types:
newData
char *


concatenateSounds

decompiled_code:
__int64 __fastcall concatenateSounds(__int64 a1, __int64 a2)
{
__int64 result; // rax

if ( (unsigned int)ensureSoundsCanConcatenate() == -1 )
result = printSampleRateError();
else
result = concatenateData(a1, a2);
return result;
}

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

if ( (unsigned int)ensureSoundsCanConcatenate() == -1 )
result = printSampleRateError();
else
result = func2(a1, a2);
return result;
}

original_code:
void concatenateSounds(sound_t* dest, sound_t* src, fileType_t resultType) {
  if(ensureSoundsCanConcatenate(dest, src, resultType) == -1) {
    printSampleRateError();
    return;
  }
  concatenateData(dest, src);
}

canonical_original_code:
void concatenateSounds(struct sound_t *dest, struct sound_t *src, enum fileType_t resultType) {
  if(ensureSoundsCanConcatenate(dest, src, resultType) == -1) {
    printSampleRateError();
    return;
  }
  concatenateData(dest, src);
}

variable_types:
src
struct sound_t *

variable_types:
resultType
enum fileType_t { CS229=0, WAVE=1 }


concatenateSoundArray

decompiled_code:
__int64 __fastcall concatenateSoundArray(__int64 a1, _QWORD *a2, int a3)
{
_QWORD *v4; // r13
__int64 result; // rax
unsigned int v6; // er8
__int64 *v7; // rbx
__int64 *v8; // rbp
__int64 v9; // rsi
__int64 v10; // rsi
unsigned int v11; // [rsp+Ch] [rbp-3Ch]

v4 = a2;
convertToFileType(*(unsigned int *)(a1 + 8), *a2);
v11 = *(_DWORD *)(a1 + 8);
result = deepCopySound(a1, *a2);
v6 = v11;
*(_DWORD *)(a1 + 8) = v11;
if ( a3 > 0 )
{
v7 = a2 + 1;
v8 = a2;
while ( 1 )
{
v9 = *v8++;
result = convertToFileType(v6, v9);
if ( v8 == &v4[(unsigned int)(a3 - 1) + 1] )
break;
v6 = *(_DWORD *)(a1 + 8);
}
if ( a3 > 1 )
{
do
{
v10 = *v7++;
result = concatenateSounds(a1, v10);
}
while ( v7 != &v4[(unsigned int)(a3 - 2) + 2] );
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1, _QWORD *a2, int a3)
{
_QWORD *v4; // r13
__int64 result; // rax
unsigned int v6; // er8
__int64 *v7; // rbx
__int64 *v8; // rbp
__int64 v9; // rsi
__int64 v10; // rsi
unsigned int v11; // [rsp+Ch] [rbp-3Ch]

v4 = a2;
convertToFileType(*(unsigned int *)(a1 + 8), *a2);
v11 = *(_DWORD *)(a1 + 8);
result = deepCopySound(a1, *a2);
v6 = v11;
*(_DWORD *)(a1 + 8) = v11;
if ( a3 > 0 )
{
v7 = a2 + 1;
v8 = a2;
while ( 1 )
{
v9 = *v8++;
result = convertToFileType(v6, v9);
if ( v8 == &v4[(unsigned int)(a3 - 1) + 1] )
break;
v6 = *(_DWORD *)(a1 + 8);
}
if ( a3 > 1 )
{
do
{
v10 = *v7++;
result = func3(a1, v10);
}
while ( v7 != &v4[(unsigned int)(a3 - 2) + 2] );
}
}
return result;
}

original_code:
void concatenateSoundArray(sound_t* dest, sound_t** sounds, int numSounds) {
  int i;
  fileType_t oldType;
  convertToFileType(dest->fileType, sounds[0]);
  oldType = dest->fileType;
  deepCopySound(dest, sounds[0]);
  dest->fileType = oldType;
  for(i = 0; i < numSounds; i++) {
    convertToFileType(dest->fileType, sounds[i]);
  }
  for(i = 1; i < numSounds; i++) {
    concatenateSounds(dest, sounds[i], dest->fileType);
  }
}

canonical_original_code:
void concatenateSoundArray(struct sound_t *dest, struct sound_t **sounds, int numSounds) {
  int i;
  enum fileType_t oldType;
  convertToFileType(dest->fileType, sounds[0]);
  oldType = dest->fileType;
  deepCopySound(dest, sounds[0]);
  dest->fileType = oldType;
  for(i = 0; i < numSounds; i++) {
    convertToFileType(dest->fileType, sounds[i]);
  }
  for(i = 1; i < numSounds; i++) {
    concatenateSounds(dest, sounds[i], dest->fileType);
  }
}

variable_types:
sounds
struct sound_t **

variable_types: numSounds int

variable_types:
oldType
enum fileType_t { CS229=0, WAVE=1 }


printHelp

decompiled_code:
int __fastcall printHelp(const char *a1)
{
puts("Sndcat Help:");
printf("Usage: %s file1 [file2 ...] [options]\n\n", a1);
puts("Utility:");
puts("This program reads the CS229/WAVE file(s) passed as arguments, concatenates them,");
puts("and writes the result to a file (default:stdout , see -o option). Outputs in the");
puts("requested format (default:CS229, see -w option)\n");
puts("Defaults:");
puts("Default output file type is CS229 (see -w option)");
puts("Default output file is stdout unless another file is provided with -o.");
puts("If no source file(s) are provided by the arguments, input is read from stdin.");
puts("If only one source file is provided, the file is rewritten as-is in the desired");
puts("format. (useful for converting between formats)\n");
puts("Options:");
puts("-h\t\tdisplays this help page");
puts("-o [file]\toutput to a file rather than standard out");
return puts("-w\t\toutput in the WAVE format rather than CS229");
}

canonical_decompiled_code:
int __fastcall func0(const char *a1)
{
puts("Sndcat Help:");
printf("Usage: %s file1 [file2 ...] [options]\n\n", a1);
puts("Utility:");
puts("This program reads the CS229/WAVE file(s) passed as arguments, concatenates them,");
puts("and writes the result to a file (default:stdout , see -o option). Outputs in the");
puts("requested format (default:CS229, see -w option)\n");
puts("Defaults:");
puts("Default output file type is CS229 (see -w option)");
puts("Default output file is stdout unless another file is provided with -o.");
puts("If no source file(s) are provided by the arguments, input is read from stdin.");
puts("If only one source file is provided, the file is rewritten as-is in the desired");
puts("format. (useful for converting between formats)\n");
puts("Options:");
puts("-h\t\tdisplays this help page");
puts("-o [file]\toutput to a file rather than standard out");
return puts("-w\t\toutput in the WAVE format rather than CS229");
}

original_code:
void printHelp(char* cmd) {
  printf("Sndcat Help:\n");
  printf("Usage: %s file1 [file2 ...] [options]\n\n", cmd);
  printf("Utility:\n");
  printf("This program reads the CS229/WAVE file(s) passed as arguments, concatenates them,\n");
  printf("and writes the result to a file (default:stdout , see -o option). Outputs in the\n");
  printf("requested format (default:CS229, see -w option)\n\n");
  printf("Defaults:\n");
  printf("Default output file type is CS229 (see -w option)\n");
  printf("Default output file is stdout unless another file is provided with -o.\n");
  printf("If no source file(s) are provided by the arguments, input is read from stdin.\n");
  printf("If only one source file is provided, the file is rewritten as-is in the desired\n");
  printf("format. (useful for converting between formats)\n\n");
  printf("Options:\n");
  printf("-h\t\tdisplays this help page\n");
  printf("-o [file]\toutput to a file rather than standard out\n");
  printf("-w\t\toutput in the WAVE format rather than CS229\n");
}

canonical_original_code:
void printHelp(char *cmd) {
  printf("Sndcat Help:\n");
  printf("Usage: %s file1 [file2 ...] [options]\n\n", cmd);
  printf("Utility:\n");
  printf("This program reads the CS229/WAVE file(s) passed as arguments, concatenates them,\n");
  printf("and writes the result to a file (default:stdout , see -o option). Outputs in the\n");
  printf("requested format (default:CS229, see -w option)\n\n");
  printf("Defaults:\n");
  printf("Default output file type is CS229 (see -w option)\n");
  printf("Default output file is stdout unless another file is provided with -o.\n");
  printf("If no source file(s) are provided by the arguments, input is read from stdin.\n");
  printf("If only one source file is provided, the file is rewritten as-is in the desired\n");
  printf("format. (useful for converting between formats)\n\n");
  printf("Options:\n");
  printf("-h\t\tdisplays this help page\n");
  printf("-o [file]\toutput to a file rather than standard out\n");
  printf("-w\t\toutput in the WAVE format rather than CS229\n");
}

variable_types:
cmd
char *


handleCommandLineArgs

original_code:
fileType_t handleCommandLineArgs(int argc, char** argv, char** fileNames, int capacity, int* numFilesRead, char** outputFileName) {
  int i;
  fileType_t outputType = CS229;
  for(i = 1; i < argc; i++) {
    if(argv[i][0] == '-') {
      if(argv[i][1] == 'h') {
        printHelp(argv[0]);
        *numFilesRead = -1;
        return outputType;
      }
      else if(argv[i][1] == 'o') {
        *outputFileName = argv[i+1];
        ++i;
      }
      else if(argv[i][1] == 'w') {
        outputType = WAVE;
      }
      else {
        printInvalidOptionError(argv[i][1]);
        *numFilesRead = -1;
        return outputType;
      }
    }
    else {
      fileNames[(*numFilesRead)++] = argv[i];
    }
  }
  return outputType;
}

canonical_original_code:
enum fileType_t handleCommandLineArgs(int argc, char **argv, char **fileNames, int capacity, int *numFilesRead, char **outputFileName) {
  int i;
  enum fileType_t outputType = CS229;
  for(i = 1; i < argc; i++) {
    if(argv[i][0] == '-') {
      if(argv[i][1] == 'h') {
        printHelp(argv[0]);
        *numFilesRead = -1;
        return outputType;
      }
      else if(argv[i][1] == 'o') {
        *outputFileName = argv[i+1];
        ++i;
      }
      else if(argv[i][1] == 'w') {
        outputType = WAVE;
      }
      else {
        printInvalidOptionError(argv[i][1]);
        *numFilesRead = -1;
        return outputType;
      }
    }
    else {
      fileNames[(*numFilesRead)++] = argv[i];
    }
  }
  return outputType;
}

variable_types: argc int

variable_types:
argv
char **

variable_types:
fileNames
char **


wavToSound

original_code:
void wavToSound(wavData_t* wd, sound_t* sound) {
  sound->sampleRate = wd->sampleRate;
  sound->bitDepth = wd->bitDepth;
  sound->numChannels = wd->numChannels;
  sound->dataSize = wd->dataChunkSize;
  sound->error = wd->error;
  sound->rawData = wd->data;
}

canonical_original_code:
void wavToSound(struct wavData_t *wd, struct sound_t *sound) {
  sound->sampleRate = wd->sampleRate;
  sound->bitDepth = wd->bitDepth;
  sound->numChannels = wd->numChannels;
  sound->dataSize = wd->dataChunkSize;
  sound->error = wd->error;
  sound->rawData = wd->data;
}

variable_types: struct wavData_t { void *data; enum chunkId_t { CHUNK_UNKNOWN=0, CHUNK_FMT=1, CHUNK_DATA=2 } currentChunkId; enum readError_t { NO_ERROR=0, ERROR_EOF=1, ERROR_READING=2, ERROR_MEMORY=3, ERROR_FILETYPE=4, ERROR_BIT_DEPTH=5, ERROR_INVALID_KEYWORD=6, ERROR_NO_VALUE=7, ERROR_SAMPLE_DATA=8, ERROR_ZERO_CHANNELS=9 } error; unsigned int numBytesInChunk; unsigned int sampleRate; unsigned int byteRate; unsigned int dataChunkSize; unsigned short audioFormat; unsigned short numChannels; unsigned short blockAlign; unsigned short bitDepth; } *

user_defined_types: struct wavData_t { void *data; enum chunkId_t currentChunkId; enum readError_t error; unsigned int numBytesInChunk; unsigned int sampleRate; unsigned int byteRate; unsigned int dataChunkSize; unsigned short audioFormat; unsigned short numChannels; unsigned short blockAlign; unsigned short bitDepth; }


PrintOutput

decompiled_code:
__int64 __fastcall PrintOutput(char *s)
{
time_t timer; // [rsp+8h] [rbp-10h] BYREF

time(&timer);
ctime_r(&timer, s);
s[strlen(s) - 1] = 0;
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func0(char *s)
{
time_t timer; // [rsp+8h] [rbp-10h] BYREF

time(&timer);
ctime_r(&timer, s);
s[strlen(s) - 1] = 0;
return 0LL;
}

original_code:
int PrintOutput(char *string){
 time_t ltime;
  time(&ltime);
  ctime_r(&ltime,string);
  string[strlen(string)-1]='\0';
  return 0;
}

canonical_original_code:
int PrintOutput(char *string){
 long ltime;
  time(&ltime);
  ctime_r(&ltime,string);
  string[strlen(string)-1]='\0';
  return 0;
}

variable_types:
string
char *

variable_types: ltime long


CoreRemove

decompiled_code:
int __fastcall CoreRemove(sem_t *a1, unsigned int a2)
{
sem_t *v2; // r13
int v4; // eax
unsigned int v5; // er12
const char *v6; // rdi
int result; // eax

v2 = a1 + 3;
if ( sem_wait(a1 + 3) )
{
LABEL_16:
perror("sem wait");
return -1;
}
v4 = GetElementMatrix(a1->__align, a2);
v5 = v4;
if ( v4 == -1 )
{
v6 = "Get Element Matrix Problem";
goto LABEL_19;
}
if ( v4 <= 0 )
{
if ( sem_post(v2) )
goto LABEL_12;
return 1;
}
v6 = "RemoveMatrix Problem";
if ( (unsigned int)RemoveMatrix(a1->__align, a2) == -1 )
goto LABEL_19;
if ( sem_post(v2) )
goto LABEL_12;
v2 = a1 + 2;
if ( sem_wait(a1 + 2) )
goto LABEL_16;
v6 = "DeleteNeedle Problem";
if ( (unsigned int)DeleteNeedle(*((unsigned int *)&a1->__align + 5), v5) == -1 )
{
LABEL_19:
puts(v6);
if ( !sem_post(v2) )
goto LABEL_13;
goto LABEL_12;
}
if ( sem_post(a1 + 2) )
goto LABEL_12;
if ( sem_wait(a1 + 4) )
goto LABEL_16;
if ( (unsigned int)QueueAdd(*(&a1->__align + 1), a2) == -1 )
{
puts("QueueAdd Problem");
if ( !sem_post(a1 + 4) )
goto LABEL_13;
goto LABEL_12;
}
result = sem_post(a1 + 4);
if ( result )
{
LABEL_12:
perror("sem post");
LABEL_13:
result = -1;
}
return result;
}

canonical_decompiled_code:
int __fastcall func1(sem_t *a1, unsigned int a2)
{
sem_t *v2; // r13
int v4; // eax
unsigned int v5; // er12
const char *v6; // rdi
int result; // eax

v2 = a1 + 3;
if ( sem_wait(a1 + 3) )
{
LABEL_16:
perror("sem wait");
return -1;
}
v4 = GetElementMatrix(a1->__align, a2);
v5 = v4;
if ( v4 == -1 )
{
v6 = "Get Element Matrix Problem";
goto LABEL_19;
}
if ( v4 <= 0 )
{
if ( sem_post(v2) )
goto LABEL_12;
return 1;
}
v6 = "RemoveMatrix Problem";
if ( (unsigned int)RemoveMatrix(a1->__align, a2) == -1 )
goto LABEL_19;
if ( sem_post(v2) )
goto LABEL_12;
v2 = a1 + 2;
if ( sem_wait(a1 + 2) )
goto LABEL_16;
v6 = "DeleteNeedle Problem";
if ( (unsigned int)DeleteNeedle(*((unsigned int *)&a1->__align + 5), v5) == -1 )
{
LABEL_19:
puts(v6);
if ( !sem_post(v2) )
goto LABEL_13;
goto LABEL_12;
}
if ( sem_post(a1 + 2) )
goto LABEL_12;
if ( sem_wait(a1 + 4) )
goto LABEL_16;
if ( (unsigned int)QueueAdd(*(&a1->__align + 1), a2) == -1 )
{
puts("QueueAdd Problem");
if ( !sem_post(a1 + 4) )
goto LABEL_13;
goto LABEL_12;
}
result = sem_post(a1 + 4);
if ( result )
{
LABEL_12:
perror("sem post");
LABEL_13:
result = -1;
}
return result;
}

original_code:
int CoreRemove(CorePtr Core,int Id){
 int Offset;
 if(sem_wait(& (Core)->Sem_Matrix)){perror("sem wait"); return -1;}
 if( (Offset=GetElementMatrix(Core->Matrix,Id))==-1){
  printf("Get Element Matrix Problem\n");
  if(sem_post(& (Core)->Sem_Matrix)){perror("sem post"); return -1;}
  return -1;
 }
 if(Offset>0)
  if(RemoveMatrix(Core->Matrix,Id)==-1){
   printf("RemoveMatrix Problem\n");
   if(sem_post(& (Core)->Sem_Matrix)){perror("sem post"); return -1;}
   return -1;
 }
 if(sem_post(& (Core)->Sem_Matrix)){perror("sem post"); return -1;}
 if(Offset>0){
  if(sem_wait(& ((Core)->Sem_File))){perror("sem wait"); return -1;}
  if(DeleteNeedle((Core)->Fd, Offset)==-1){
   printf("DeleteNeedle Problem\n");
   if(sem_post(& ((Core)->Sem_File))){perror("sem post"); return -1;}
   return -1;
  }
  if(sem_post(& ((Core)->Sem_File))){perror("sem post"); return -1;}
  if(sem_wait(& (Core)->Sem_Queue)){perror("sem wait"); return -1;}
  if(QueueAdd(Core->Queue,Id)==-1){
   printf("QueueAdd Problem\n");
   if(sem_post(& (Core)->Sem_Queue)){perror("sem post"); return -1;}
   return -1;
  }
  if(sem_post(& (Core)->Sem_Queue)){perror("sem post"); return -1;}
  return 0;
 }
 else{
  return 1;
 }
}

canonical_original_code:
int CoreRemove(struct Core *Core, int Id){
 int Offset;
 if(sem_wait(& (Core)->Sem_Matrix)){perror("sem wait"); return -1;}
 if( (Offset=GetElementMatrix(Core->Matrix,Id))==-1){
  printf("Get Element Matrix Problem\n");
  if(sem_post(& (Core)->Sem_Matrix)){perror("sem post"); return -1;}
  return -1;
 }
 if(Offset>0)
  if(RemoveMatrix(Core->Matrix,Id)==-1){
   printf("RemoveMatrix Problem\n");
   if(sem_post(& (Core)->Sem_Matrix)){perror("sem post"); return -1;}
   return -1;
 }
 if(sem_post(& (Core)->Sem_Matrix)){perror("sem post"); return -1;}
 if(Offset>0){
  if(sem_wait(& ((Core)->Sem_File))){perror("sem wait"); return -1;}
  if(DeleteNeedle((Core)->Fd, Offset)==-1){
   printf("DeleteNeedle Problem\n");
   if(sem_post(& ((Core)->Sem_File))){perror("sem post"); return -1;}
   return -1;
  }
  if(sem_post(& ((Core)->Sem_File))){perror("sem post"); return -1;}
  if(sem_wait(& (Core)->Sem_Queue)){perror("sem wait"); return -1;}
  if(QueueAdd(Core->Queue,Id)==-1){
   printf("QueueAdd Problem\n");
   if(sem_post(& (Core)->Sem_Queue)){perror("sem post"); return -1;}
   return -1;
  }
  if(sem_post(& (Core)->Sem_Queue)){perror("sem post"); return -1;}
  return 0;
 }
 else{
  return 1;
 }
}

variable_types: struct Core { struct Matrix { int *Table; int Size; } *Matrix; struct Queue { struct Node { int Element; struct Node *Next; } *Start; struct Node *End; } *Queue; int Id; int Fd; int Total_Threads; union sem_t { char __size[32]; long __align; } Sem_Total; union sem_t Sem_File; union sem_t Sem_Matrix; union sem_t Sem_Queue; union sem_t Sem_Id; int TerminationFlag; } *

variable_types: Id int

variable_types: Offset int

user_defined_types: struct Core { struct Matrix *Matrix; struct Queue *Queue; int Id; int Fd; int Total_Threads; union sem_t Sem_Total; union sem_t Sem_File; union sem_t Sem_Matrix; union sem_t Sem_Queue; union sem_t Sem_Id; int TerminationFlag; }

user_defined_types: struct Queue { struct Node *Start; struct Node *End; }


CoreExists

decompiled_code:
__int64 __fastcall CoreExists(sem_t *a1, unsigned int a2)
{
sem_t *v2; // r13
int v3; // er12

v2 = a1 + 3;
if ( sem_wait(a1 + 3) )
{
v3 = -1;
perror("sem wait");
return (unsigned int)v3;
}
v3 = GetElementMatrix(a1->__align, a2);
if ( v3 != -1 )
{
if ( !sem_post(v2) )
{
if ( v3 < 0 )
v3 = 0;
return (unsigned int)v3;
}
goto LABEL_8;
}
if ( sem_post(v2) )
{
LABEL_8:
perror("sem post");
return 0xFFFFFFFFLL;
}
puts("Get Element Matrix Problem");
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 __fastcall func2(sem_t *a1, unsigned int a2)
{
sem_t *v2; // r13
int v3; // er12

v2 = a1 + 3;
if ( sem_wait(a1 + 3) )
{
v3 = -1;
perror("sem wait");
return (unsigned int)v3;
}
v3 = GetElementMatrix(a1->__align, a2);
if ( v3 != -1 )
{
if ( !sem_post(v2) )
{
if ( v3 < 0 )
v3 = 0;
return (unsigned int)v3;
}
goto LABEL_8;
}
if ( sem_post(v2) )
{
LABEL_8:
perror("sem post");
return 0xFFFFFFFFLL;
}
puts("Get Element Matrix Problem");
return 0xFFFFFFFFLL;
}

original_code:
int CoreExists(CorePtr Core,int Id){
 int Offset;
 if(sem_wait(& (Core)->Sem_Matrix)){perror("sem wait"); return -1;}
 if( (Offset=GetElementMatrix(Core->Matrix,Id))==-1){
  if(sem_post(& (Core)->Sem_Matrix)){perror("sem post"); return -1;}
  printf("Get Element Matrix Problem\n");
  return -1;
 }
 if(sem_post(& (Core)->Sem_Matrix)){perror("sem post"); return -1;}
 if(Offset>0){
  return Offset;
 }
 else{
  return 0;
 }
}

canonical_original_code:
int CoreExists(struct Core *Core, int Id){
 int Offset;
 if(sem_wait(& (Core)->Sem_Matrix)){perror("sem wait"); return -1;}
 if( (Offset=GetElementMatrix(Core->Matrix,Id))==-1){
  if(sem_post(& (Core)->Sem_Matrix)){perror("sem post"); return -1;}
  printf("Get Element Matrix Problem\n");
  return -1;
 }
 if(sem_post(& (Core)->Sem_Matrix)){perror("sem post"); return -1;}
 if(Offset>0){
  return Offset;
 }
 else{
  return 0;
 }
}

user_defined_types: union sem_t { char __size[32]; long __align; }

user_defined_types: struct Node { int Element; struct Node *Next; }


CoreInitiate

decompiled_code:
__int64 __fastcall CoreInitiate(sem_t **a1, unsigned int a2, __int64 a3)
{
sem_t *v5; // rax
unsigned int v6; // eax
unsigned int v7; // er12
sem_t *v8; // rdi

if ( !a3 )
return (unsigned int)-1;
v5 = (sem_t *)malloc(0xC8uLL);
*a1 = v5;
if ( v5 )
{
if ( (unsigned int)InitiateMatrix(v5, a2) )
{
v7 = -1;
puts("Init Matrix Problem");
}
else if ( (unsigned int)QueueInitiate(&(*a1)->__align + 1) )
{
v7 = -1;
puts("Init Queue Problem");
}
else
{
*((_DWORD *)&(*a1)->__align + 4) = 0;
v6 = InitializeHayStack(a3);
v7 = v6;
if ( v6 == -1 )
{
puts("Init HayStack Problem");
}
else
{
v8 = *a1;
*((_DWORD *)&v8->__align + 5) = v6;
++v8;
*((_DWORD *)&v8[-1].__align + 6) = 0;
*(_DWORD *)v8[5].__size = 0;
if ( sem_init(v8, 0, 1u)
|| sem_init(*a1 + 2, 0, 1u)
|| sem_init(*a1 + 3, 0, 1u)
|| sem_init(*a1 + 4, 0, 1u)
|| (v7 = sem_init(*a1 + 5, 0, 1u)) != 0 )
{
v7 = -1;
perror("Sem Init");
}
}
}
}
else
{
v7 = -1;
perror("Core malloc");
}
return v7;
}

canonical_decompiled_code:
__int64 __fastcall func3(sem_t **a1, unsigned int a2, __int64 a3)
{
sem_t *v5; // rax
unsigned int v6; // eax
unsigned int v7; // er12
sem_t *v8; // rdi

if ( !a3 )
return (unsigned int)-1;
v5 = (sem_t *)malloc(0xC8uLL);
*a1 = v5;
if ( v5 )
{
if ( (unsigned int)InitiateMatrix(v5, a2) )
{
v7 = -1;
puts("Init Matrix Problem");
}
else if ( (unsigned int)QueueInitiate(&(*a1)->__align + 1) )
{
v7 = -1;
puts("Init Queue Problem");
}
else
{
*((_DWORD *)&(*a1)->__align + 4) = 0;
v6 = InitializeHayStack(a3);
v7 = v6;
if ( v6 == -1 )
{
puts("Init HayStack Problem");
}
else
{
v8 = *a1;
*((_DWORD *)&v8->__align + 5) = v6;
++v8;
*((_DWORD *)&v8[-1].__align + 6) = 0;
*(_DWORD *)v8[5].__size = 0;
if ( sem_init(v8, 0, 1u)
|| sem_init(*a1 + 2, 0, 1u)
|| sem_init(*a1 + 3, 0, 1u)
|| sem_init(*a1 + 4, 0, 1u)
|| (v7 = sem_init(*a1 + 5, 0, 1u)) != 0 )
{
v7 = -1;
perror("Sem Init");
}
}
}
}
else
{
v7 = -1;
perror("Core malloc");
}
return v7;
}

original_code:
int CoreInitiate(CorePtr *Core,int Size,char* WorkFile){
 int Fd;
 if(WorkFile==((void *)0))
  return -1;
 if(((*Core)=malloc(sizeof(struct Core)))==((void *)0)){perror("Core malloc");return -1;}
 if(InitiateMatrix(&((*Core)->Matrix),Size)!=0){printf("Init Matrix Problem\n");return -1;}
 if(QueueInitiate(&((*Core)->Queue))!=0){printf("Init Queue Problem\n");return -1;}
 (*Core)->Id=0;
 if( (Fd=InitializeHayStack( WorkFile,*Core))==-1){printf("Init HayStack Problem\n");return -1;}
 (*Core)->Fd=Fd;
 (*Core)->Total_Threads=0;
 (*Core)->TerminationFlag=0;
 if( sem_init (& ((*Core)->Sem_Total) ,0 ,1)!=0){ perror("Sem Init"); return -1; }
 if( sem_init (& ((*Core)->Sem_File) ,0 ,1)!=0){ perror("Sem Init"); return -1; }
 if( sem_init (& ((*Core)->Sem_Matrix) ,0 ,1)!=0){ perror("Sem Init"); return -1; }
 if( sem_init (& ((*Core)->Sem_Queue) ,0 ,1)!=0){ perror("Sem Init"); return -1; }
 if( sem_init (& ((*Core)->Sem_Id) ,0 ,1)!=0){ perror("Sem Init"); return -1; }
 return 0;
}

canonical_original_code:
int CoreInitiate(struct Core **Core, int Size, char *WorkFile){
 int Fd;
 if(WorkFile==((void *)0))
  return -1;
 if(((*Core)=malloc(sizeof(struct Core)))==((void *)0)){perror("Core malloc");return -1;}
 if(InitiateMatrix(&((*Core)->Matrix),Size)!=0){printf("Init Matrix Problem\n");return -1;}
 if(QueueInitiate(&((*Core)->Queue))!=0){printf("Init Queue Problem\n");return -1;}
 (*Core)->Id=0;
 if( (Fd=InitializeHayStack( WorkFile,*Core))==-1){printf("Init HayStack Problem\n");return -1;}
 (*Core)->Fd=Fd;
 (*Core)->Total_Threads=0;
 (*Core)->TerminationFlag=0;
 if( sem_init (& ((*Core)->Sem_Total) ,0 ,1)!=0){ perror("Sem Init"); return -1; }
 if( sem_init (& ((*Core)->Sem_File) ,0 ,1)!=0){ perror("Sem Init"); return -1; }
 if( sem_init (& ((*Core)->Sem_Matrix) ,0 ,1)!=0){ perror("Sem Init"); return -1; }
 if( sem_init (& ((*Core)->Sem_Queue) ,0 ,1)!=0){ perror("Sem Init"); return -1; }
 if( sem_init (& ((*Core)->Sem_Id) ,0 ,1)!=0){ perror("Sem Init"); return -1; }
 return 0;
}

variable_types: struct Core { struct Matrix { int *Table; int Size; } *Matrix; struct Queue { struct Node { int Element; struct Node *Next; } *Start; struct Node *End; } *Queue; int Id; int Fd; int Total_Threads; union sem_t { char __size[32]; long __align; } Sem_Total; union sem_t Sem_File; union sem_t Sem_Matrix; union sem_t Sem_Queue; union sem_t Sem_Id; int TerminationFlag; } **

variable_types: Size int

variable_types:
WorkFile
char *

variable_types: Fd int


CoreDelete

decompiled_code:
__int64 __fastcall CoreDelete(sem_t **a1)
{
unsigned int v1; // er12

if ( *a1 )
{
v1 = DeleteMatrix();
if ( v1 == -1 )
{
puts("Delete Matrix Problem");
return v1;
}
v1 = QueueDelete(&(*a1)->__align + 1);
if ( v1 == -1 )
{
puts("Delete Queue Problem");
return v1;
}
v1 = close(*((_DWORD *)&(*a1)->__align + 5));
if ( v1 == -1 )
{
perror("close");
return v1;
}
if ( sem_destroy(*a1 + 2) == -1
|| sem_destroy(*a1 + 3) == -1
|| sem_destroy(*a1 + 4) == -1
|| sem_destroy(*a1 + 5) == -1 )
{
v1 = -1;
perror("Sem Dest");
return v1;
}
free(*a1);
}
*a1 = 0LL;
return 0;
}

canonical_decompiled_code:
__int64 __fastcall func4(sem_t **a1)
{
unsigned int v1; // er12

if ( *a1 )
{
v1 = DeleteMatrix();
if ( v1 == -1 )
{
puts("Delete Matrix Problem");
return v1;
}
v1 = QueueDelete(&(*a1)->__align + 1);
if ( v1 == -1 )
{
puts("Delete Queue Problem");
return v1;
}
v1 = close(*((_DWORD *)&(*a1)->__align + 5));
if ( v1 == -1 )
{
perror("close");
return v1;
}
if ( sem_destroy(*a1 + 2) == -1
|| sem_destroy(*a1 + 3) == -1
|| sem_destroy(*a1 + 4) == -1
|| sem_destroy(*a1 + 5) == -1 )
{
v1 = -1;
perror("Sem Dest");
return v1;
}
free(*a1);
}
*a1 = 0LL;
return 0;
}

original_code:
int CoreDelete(CorePtr *Core){
 if((*Core)!=((void *)0)){
  if(DeleteMatrix(& ((*Core)->Matrix))==-1){printf("Delete Matrix Problem\n");return -1;}
  if(QueueDelete(& ((*Core)->Queue))==-1){printf("Delete Queue Problem\n");return -1;}
  if(close((*Core)->Fd)==-1){perror("close");return -1;}
  if(sem_destroy (& ((*Core)->Sem_File) )==-1){ perror("Sem Dest"); return -1; }
  if(sem_destroy (& ((*Core)->Sem_Matrix))==-1){ perror("Sem Dest"); return -1; }
  if(sem_destroy (& ((*Core)->Sem_Queue))==-1){ perror("Sem Dest"); return -1; }
  if(sem_destroy (& ((*Core)->Sem_Id) )==-1){ perror("Sem Dest"); return -1; }
  free(*Core);
 }
 *Core=((void *)0);
 return 0;
}

canonical_original_code:
int CoreDelete(struct Core **Core){
 if((*Core)!=((void *)0)){
  if(DeleteMatrix(& ((*Core)->Matrix))==-1){printf("Delete Matrix Problem\n");return -1;}
  if(QueueDelete(& ((*Core)->Queue))==-1){printf("Delete Queue Problem\n");return -1;}
  if(close((*Core)->Fd)==-1){perror("close");return -1;}
  if(sem_destroy (& ((*Core)->Sem_File) )==-1){ perror("Sem Dest"); return -1; }
  if(sem_destroy (& ((*Core)->Sem_Matrix))==-1){ perror("Sem Dest"); return -1; }
  if(sem_destroy (& ((*Core)->Sem_Queue))==-1){ perror("Sem Dest"); return -1; }
  if(sem_destroy (& ((*Core)->Sem_Id) )==-1){ perror("Sem Dest"); return -1; }
  free(*Core);
 }
 *Core=((void *)0);
 return 0;
}


CorePrint

decompiled_code:
__int64 __fastcall CorePrint(__int64 a1)
{
puts("Printing Core:");
if ( !a1 )
return 0LL;
if ( sem_wait((sem_t *)(a1 + 128)) )
goto LABEL_10;
if ( (unsigned int)QueuePrint(*(_QWORD *)(a1 + 8)) != -1 )
{
if ( sem_post((sem_t *)(a1 + 128)) )
{
LABEL_9:
perror("sem post");
return 0xFFFFFFFFLL;
}
if ( !sem_wait((sem_t *)(a1 + 96)) )
{
if ( (unsigned int)PrintMatrix(*(_QWORD *)a1) != -1 )
{
if ( !sem_post((sem_t *)(a1 + 96)) )
return 0LL;
goto LABEL_9;
}
goto LABEL_11;
}
LABEL_10:
perror("sem wait");
return 0xFFFFFFFFLL;
}
LABEL_11:
puts("Get Element Matrix Problem");
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1)
{
puts("Printing Core:");
if ( !a1 )
return 0LL;
if ( sem_wait((sem_t *)(a1 + 128)) )
goto LABEL_10;
if ( (unsigned int)QueuePrint(*(_QWORD *)(a1 + 8)) != -1 )
{
if ( sem_post((sem_t *)(a1 + 128)) )
{
LABEL_9:
perror("sem post");
return 0xFFFFFFFFLL;
}
if ( !sem_wait((sem_t *)(a1 + 96)) )
{
if ( (unsigned int)PrintMatrix(*(_QWORD *)a1) != -1 )
{
if ( !sem_post((sem_t *)(a1 + 96)) )
return 0LL;
goto LABEL_9;
}
goto LABEL_11;
}
LABEL_10:
perror("sem wait");
return 0xFFFFFFFFLL;
}
LABEL_11:
puts("Get Element Matrix Problem");
return 0xFFFFFFFFLL;
}

original_code:
int CorePrint(CorePtr Core){
 printf("Printing Core:\n");
 if(Core!=((void *)0)){
  if(sem_wait(& ((Core)->Sem_Queue))){perror("sem wait"); return -1;}
  if(QueuePrint(Core->Queue)==-1){printf("Get Element Matrix Problem\n");return -1;}
  if(sem_post(& (Core)->Sem_Queue)){perror("sem post"); return -1;}
  if(sem_wait(& (Core)->Sem_Matrix)){perror("sem wait"); return -1;}
  if(PrintMatrix(Core->Matrix)==-1){printf("Get Element Matrix Problem\n");return -1;}
  if(sem_post(& (Core)->Sem_Matrix)){perror("sem post"); return -1;}
 }
 return 0;
}

canonical_original_code:
int CorePrint(struct Core *Core){
 printf("Printing Core:\n");
 if(Core!=((void *)0)){
  if(sem_wait(& ((Core)->Sem_Queue))){perror("sem wait"); return -1;}
  if(QueuePrint(Core->Queue)==-1){printf("Get Element Matrix Problem\n");return -1;}
  if(sem_post(& (Core)->Sem_Queue)){perror("sem post"); return -1;}
  if(sem_wait(& (Core)->Sem_Matrix)){perror("sem wait"); return -1;}
  if(PrintMatrix(Core->Matrix)==-1){printf("Get Element Matrix Problem\n");return -1;}
  if(sem_post(& (Core)->Sem_Matrix)){perror("sem post"); return -1;}
 }
 return 0;
}


CoreGetId

decompiled_code:
__int64 __fastcall CoreGetId(__int64 a1)
{
sem_t *v1; // rbp
unsigned int v2; // er12
unsigned int v4[7]; // [rsp+Ch] [rbp-1Ch] BYREF

if ( !a1 )
{
v2 = -1;
puts("Core NUll");
return v2;
}
v1 = (sem_t *)(a1 + 128);
if ( sem_wait((sem_t *)(a1 + 128)) )
goto LABEL_13;
v2 = QueueRemoveHead(*(_QWORD *)(a1 + 8), v4);
if ( v2 == -1 )
{
puts("QueueRemoveH Problem");
if ( !sem_post(v1) )
return v2;
goto LABEL_9;
}
if ( sem_post(v1) )
goto LABEL_9;
if ( v2 != 1 )
return v4[0];
if ( sem_wait((sem_t *)(a1 + 160)) )
{
LABEL_13:
v2 = -1;
perror("sem wait");
return v2;
}
v4[0] = *(_DWORD *)(a1 + 16);
*(_DWORD *)(a1 + 16) = v4[0] + 1;
if ( !sem_post((sem_t *)(a1 + 160)) )
return v4[0];
LABEL_9:
perror("sem post");
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1)
{
sem_t *v1; // rbp
unsigned int v2; // er12
unsigned int v4[7]; // [rsp+Ch] [rbp-1Ch] BYREF

if ( !a1 )
{
v2 = -1;
puts("Core NUll");
return v2;
}
v1 = (sem_t *)(a1 + 128);
if ( sem_wait((sem_t *)(a1 + 128)) )
goto LABEL_13;
v2 = QueueRemoveHead(*(_QWORD *)(a1 + 8), v4);
if ( v2 == -1 )
{
puts("QueueRemoveH Problem");
if ( !sem_post(v1) )
return v2;
goto LABEL_9;
}
if ( sem_post(v1) )
goto LABEL_9;
if ( v2 != 1 )
return v4[0];
if ( sem_wait((sem_t *)(a1 + 160)) )
{
LABEL_13:
v2 = -1;
perror("sem wait");
return v2;
}
v4[0] = *(_DWORD *)(a1 + 16);
*(_DWORD *)(a1 + 16) = v4[0] + 1;
if ( !sem_post((sem_t *)(a1 + 160)) )
return v4[0];
LABEL_9:
perror("sem post");
return 0xFFFFFFFFLL;
}

original_code:
int CoreGetId(CorePtr Core){
 int Id,Err;
 if(Core==((void *)0)){printf("Core NUll\n");return -1;}
 if(sem_wait(& ((Core)->Sem_Queue))){perror("sem wait"); return -1;}
 if( (Err=QueueRemoveHead(Core->Queue,&Id))==-1){
  printf("QueueRemoveH Problem\n");
  if(sem_post(& (Core)->Sem_Queue)){perror("sem post"); return -1;}
  return -1;
 }
 if(sem_post(& (Core)->Sem_Queue)){perror("sem post"); return -1;}
 if(Err==1){
  if(sem_wait(& ((Core)->Sem_Id))){perror("sem wait"); return -1;}
  Id=Core->Id;
  Core->Id++;
  if(sem_post(& (Core)->Sem_Id)){perror("sem post"); return -1;}
 }
  return Id;
}

canonical_original_code:
int CoreGetId(struct Core *Core){
 int Id; int Err;
 if(Core==((void *)0)){printf("Core NUll\n");return -1;}
 if(sem_wait(& ((Core)->Sem_Queue))){perror("sem wait"); return -1;}
 if( (Err=QueueRemoveHead(Core->Queue,&Id))==-1){
  printf("QueueRemoveH Problem\n");
  if(sem_post(& (Core)->Sem_Queue)){perror("sem post"); return -1;}
  return -1;
 }
 if(sem_post(& (Core)->Sem_Queue)){perror("sem post"); return -1;}
 if(Err==1){
  if(sem_wait(& ((Core)->Sem_Id))){perror("sem wait"); return -1;}
  Id=Core->Id;
  Core->Id++;
  if(sem_post(& (Core)->Sem_Id)){perror("sem post"); return -1;}
 }
  return Id;
}

variable_types: Err int