original_code:
extern void
base32_encode(char*s, curve25519key_t *x) {
  int c; int i = 0; int v = 0; int a = 0;
  for (c = 0; c < 256; c++) {
    v |= curve25519key_getbit(x, c) << i;
    i++;
    if (i > 4) {
      s[a] = base32chars[v];
      v = 0;
      i = 0;
      a++;
    }
  }
  if (v) {
    s[a] = base32chars[v];
    a++;
  }
  s[a] = 0;
  a--;
  i=0;
  while (i < a) {
    v = s[a];
    s[a] = s[i];
    s[i] = v;
    i++; a--;
  }
}

canonical_original_code:
extern void base32_encode(char *s, unsigned long (*x)[-1]) {
  int c; int i = 0; int v = 0; int a = 0;
  for (c = 0; c < 256; c++) {
    v |= curve25519key_getbit(x, c) << i;
    i++;
    if (i > 4) {
      s[a] = base32chars[v];
      v = 0;
      i = 0;
      a++;
    }
  }
  if (v) {
    s[a] = base32chars[v];
    a++;
  }
  s[a] = 0;
  a--;
  i=0;
  while (i < a) {
    v = s[a];
    s[a] = s[i];
    s[i] = v;
    i++; a--;
  }
}

variable_types:
s
char *

variable_types: c int

variable_types: i int

variable_types: a int


decompiled_code:
__int64 __fastcall base32_decode(_BYTE *a1, __int64 a2)
{
__int64 v3; // rax
int v4; // edx
int v5; // er14
int i; // ebp
char *v7; // r13
int v8; // ebx
unsigned int v9; // eax
int v10; // edx
int v11; // ebx
__int64 result; // rax
__int64 v13; // rsi
__int64 v14; // rsi

if ( *a1 )
{
v3 = 0LL;
do
v4 = v3++;
while ( a1[v3] );
v5 = 5 * v4 + 5;
i = 0;
v7 = &a1[v4];
while ( 1 )
{
v8 = *v7;
v9 = v8 - 50;
v10 = v8 - 24;
v11 = v8 - 97;
if ( v9 <= 5 )
v11 = v10;
result = curve25519key_setbit(a2, (unsigned int)i, v11 & 1);
if ( i == 255 )
break;
--v7;
curve25519key_setbit(a2, (unsigned int)(i + 1), (v11 >> 1) & 1);
curve25519key_setbit(a2, (unsigned int)(i + 2), (v11 >> 2) & 1);
curve25519key_setbit(a2, (unsigned int)(i + 3), (v11 >> 3) & 1);
v13 = (unsigned int)(i + 4);
i += 5;
result = curve25519key_setbit(a2, v13, (v11 >> 4) & 1);
if ( i == v5 )
{
if ( i > 255 )
return result;
goto LABEL_10;
}
}
}
else
{
for ( i = 0; i != 256; ++i )
{
LABEL_10:
v14 = (unsigned int)i;
result = curve25519key_setbit(a2, v14, 0LL);
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(_BYTE *a1, __int64 a2)
{
__int64 v3; // rax
int v4; // edx
int v5; // er14
int i; // ebp
char *v7; // r13
int v8; // ebx
unsigned int v9; // eax
int v10; // edx
int v11; // ebx
__int64 result; // rax
__int64 v13; // rsi
__int64 v14; // rsi

if ( *a1 )
{
v3 = 0LL;
do
v4 = v3++;
while ( a1[v3] );
v5 = 5 * v4 + 5;
i = 0;
v7 = &a1[v4];
while ( 1 )
{
v8 = *v7;
v9 = v8 - 50;
v10 = v8 - 24;
v11 = v8 - 97;
if ( v9 <= 5 )
v11 = v10;
result = curve25519key_setbit(a2, (unsigned int)i, v11 & 1);
if ( i == 255 )
break;
--v7;
curve25519key_setbit(a2, (unsigned int)(i + 1), (v11 >> 1) & 1);
curve25519key_setbit(a2, (unsigned int)(i + 2), (v11 >> 2) & 1);
curve25519key_setbit(a2, (unsigned int)(i + 3), (v11 >> 3) & 1);
v13 = (unsigned int)(i + 4);
i += 5;
result = curve25519key_setbit(a2, v13, (v11 >> 4) & 1);
if ( i == v5 )
{
if ( i > 255 )
return result;
goto LABEL_10;
}
}
}
else
{
for ( i = 0; i != 256; ++i )
{
LABEL_10:
v14 = (unsigned int)i;
result = curve25519key_setbit(a2, v14, 0LL);
}
}
return result;
}

original_code:
extern void
base32_decode(const char*s, curve25519key_t *x) {
  int c; int i = 0; int v = 0; int a = 0;
  while (s[a]) {
    a++;
  }
  a--;
  while (a >= 0) {
    c = s[a];
    switch (c) {
    case '2': case '3': case '4': case '5': case '6': case '7':
      v = (c - '2')+26;
      break;
    default:
      v = c - 'a';
    }
    curve25519key_setbit(x, i, v&1); v>>=1; i++; if (i >= 256) { break; };
    curve25519key_setbit(x, i, v&1); v>>=1; i++; if (i >= 256) { break; };
    curve25519key_setbit(x, i, v&1); v>>=1; i++; if (i >= 256) { break; };
    curve25519key_setbit(x, i, v&1); v>>=1; i++; if (i >= 256) { break; };
    curve25519key_setbit(x, i, v&1); v>>=1; i++; if (i >= 256) { break; };
    a--;
  }
  while (i < 256) {
    curve25519key_setbit(x, i, 0);
    i++;
  }
}

variable_types:
x
unsigned long (*)[-1]

variable_types: v int

return_type: void


doit

decompiled_code:
int __fastcall doit(__int64 a1, __int64 a2, __int64 a3)
{
unsigned int i; // ebx
__int64 v6; // rsi
unsigned int v7; // eax
unsigned int v8; // ebx
__int64 v9; // rsi
unsigned int v10; // eax
unsigned int v11; // ebx
__int64 v12; // rsi
unsigned int v13; // eax

for ( i = 0; i != 32; ++i )
{
v6 = i;
v7 = curve25519key_getbyte(a2, v6);
printf("%02x", v7);
}
v8 = 0;
putchar(32);
do
{
v9 = v8++;
v10 = curve25519key_getbyte(a3, v9);
printf("%02x", v10);
}
while ( v8 != 32 );
v11 = 0;
putchar(32);
curve25519(a1, a2, a3);
do
{
v12 = v11++;
v13 = curve25519key_getbyte(a1, v12);
printf("%02x", v13);
}
while ( v11 != 32 );
return putchar(10);
}

canonical_decompiled_code:
int __fastcall func0(__int64 a1, __int64 a2, __int64 a3)
{
unsigned int i; // ebx
__int64 v6; // rsi
unsigned int v7; // eax
unsigned int v8; // ebx
__int64 v9; // rsi
unsigned int v10; // eax
unsigned int v11; // ebx
__int64 v12; // rsi
unsigned int v13; // eax

for ( i = 0; i != 32; ++i )
{
v6 = i;
v7 = curve25519key_getbyte(a2, v6);
printf("%02x", v7);
}
v8 = 0;
putchar(32);
do
{
v9 = v8++;
v10 = curve25519key_getbyte(a3, v9);
printf("%02x", v10);
}
while ( v8 != 32 );
v11 = 0;
putchar(32);
curve25519(a1, a2, a3);
do
{
v12 = v11++;
v13 = curve25519key_getbyte(a1, v12);
printf("%02x", v13);
}
while ( v11 != 32 );
return putchar(10);
}

original_code:
void doit(curve25519key_t *ek,curve25519key_t *e,curve25519key_t *k)
{
  int i;
  for (i = 0;i < 32;++i) printf("%02x",(unsigned int) curve25519key_getbyte(e,i)); printf(" ");
  for (i = 0;i < 32;++i) printf("%02x",(unsigned int) curve25519key_getbyte(k, i)); printf(" ");
  curve25519(ek,e,k);
  for (i = 0;i < 32;++i) printf("%02x",(unsigned int) curve25519key_getbyte(ek, i)); printf("\n");
}

canonical_original_code:
void doit(unsigned long (*ek)[-1], unsigned long (*e)[-1], unsigned long (*k)[-1])
{
  int i;
  for (i = 0;i < 32;++i) printf("%02x",(unsigned int) curve25519key_getbyte(e,i)); printf(" ");
  for (i = 0;i < 32;++i) printf("%02x",(unsigned int) curve25519key_getbyte(k, i)); printf(" ");
  curve25519(ek,e,k);
  for (i = 0;i < 32;++i) printf("%02x",(unsigned int) curve25519key_getbyte(ek, i)); printf("\n");
}

variable_types:
ek
unsigned long (*)[-1]

variable_types:
e
unsigned long (*)[-1]

variable_types:
k
unsigned long (*)[-1]


main

canonical_name: main

decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
char *v3; // rax
char *v4; // rbp
const char **v5; // rbx
const char **v6; // r12
const char *v7; // r14
size_t v8; // r15
__int64 v9; // r15
__int64 i; // r14
__int64 v11; // rdx
__int64 v12; // rsi
char *v13; // rbx
int v14; // er14
__int64 v15; // r15
int v16; // eax
unsigned int v17; // er13
char *v18; // rcx
__int64 v19; // rdx
char v20; // al
unsigned int v21; // er14
__int64 v22; // rsi
__int64 v23; // rsi
__int64 v24; // r15
__int64 v25; // r8
char *v26; // rbx
char *v27; // r13
__int64 v28; // rcx
char *v29; // rdi
__int64 v30; // rbp
__int64 v31; // r15
unsigned int v32; // er14
unsigned int v33; // ebx
unsigned int v34; // er13
unsigned int v35; // er12
__int64 v36; // r15
unsigned int v37; // er14
unsigned int v38; // ebx
unsigned int v39; // er13
unsigned int v40; // er12
unsigned int v41; // eax
int v42; // edx
unsigned int v43; // [rsp-8h] [rbp-140h]
int v44; // [rsp+Ch] [rbp-12Ch]
unsigned int v45; // [rsp+Ch] [rbp-12Ch]
unsigned int v46; // [rsp+Ch] [rbp-12Ch]
char *v47; // [rsp+10h] [rbp-128h]
unsigned int v48; // [rsp+10h] [rbp-128h]
__int64 v49; // [rsp+18h] [rbp-120h]
unsigned int v50; // [rsp+18h] [rbp-120h]
int v51; // [rsp+20h] [rbp-118h]
unsigned int v52; // [rsp+20h] [rbp-118h]
unsigned int v53; // [rsp+20h] [rbp-118h]
int v54; // [rsp+24h] [rbp-114h]
unsigned int v55; // [rsp+24h] [rbp-114h]
unsigned int v57; // [rsp+28h] [rbp-110h]
unsigned int v58; // [rsp+30h] [rbp-108h]
unsigned int v59; // [rsp+34h] [rbp-104h]
unsigned int v60; // [rsp+38h] [rbp-100h]
unsigned int v61; // [rsp+3Ch] [rbp-FCh]
unsigned int v62; // [rsp+40h] [rbp-F8h]
unsigned int v63; // [rsp+44h] [rbp-F4h]
unsigned int v64; // [rsp+48h] [rbp-F0h]
unsigned int v65; // [rsp+4Ch] [rbp-ECh]
unsigned int v66; // [rsp+50h] [rbp-E8h]
unsigned int v67; // [rsp+54h] [rbp-E4h]
unsigned int v68; // [rsp+58h] [rbp-E0h]
unsigned int v69; // [rsp+5Ch] [rbp-DCh]
unsigned int v70; // [rsp+60h] [rbp-D8h]
unsigned int v71; // [rsp+64h] [rbp-D4h]
unsigned int v72; // [rsp+68h] [rbp-D0h]
unsigned int v73; // [rsp+6Ch] [rbp-CCh]
unsigned int v74; // [rsp+70h] [rbp-C8h]
unsigned int v75; // [rsp+74h] [rbp-C4h]
unsigned int v76; // [rsp+78h] [rbp-C0h]
unsigned int v77; // [rsp+7Ch] [rbp-BCh]
char s[8]; // [rsp+80h] [rbp-B8h] BYREF
char v79[4]; // [rsp+88h] [rbp-B0h] BYREF
char v80; // [rsp+8Ch] [rbp-ACh] BYREF
char v81; // [rsp+90h] [rbp-A8h] BYREF
char v82; // [rsp+94h] [rbp-A4h] BYREF
char v83; // [rsp+98h] [rbp-A0h] BYREF
char v84; // [rsp+9Ch] [rbp-9Ch] BYREF
char v85; // [rsp+A0h] [rbp-98h] BYREF
char v86; // [rsp+A4h] [rbp-94h] BYREF
char v87; // [rsp+A8h] [rbp-90h] BYREF
char v88; // [rsp+ACh] [rbp-8Ch] BYREF
char v89; // [rsp+B0h] [rbp-88h] BYREF
char v90; // [rsp+B4h] [rbp-84h] BYREF
char v91; // [rsp+B8h] [rbp-80h] BYREF
char v92; // [rsp+BCh] [rbp-7Ch] BYREF
char v93; // [rsp+C0h] [rbp-78h] BYREF
char v94; // [rsp+C4h] [rbp-74h] BYREF
char v95; // [rsp+C8h] [rbp-70h] BYREF
char v96; // [rsp+CCh] [rbp-6Ch] BYREF
char v97; // [rsp+D0h] [rbp-68h] BYREF
char v98; // [rsp+D4h] [rbp-64h] BYREF
char v99; // [rsp+D8h] [rbp-60h] BYREF
char v100; // [rsp+DCh] [rbp-5Ch] BYREF
char v101; // [rsp+E0h] [rbp-58h] BYREF
char v102; // [rsp+E4h] [rbp-54h] BYREF
char v103; // [rsp+E8h] [rbp-50h] BYREF
char v104; // [rsp+ECh] [rbp-4Ch] BYREF
char v105; // [rsp+F0h] [rbp-48h] BYREF
char v106; // [rsp+F4h] [rbp-44h] BYREF
char v107; // [rsp+F8h] [rbp-40h] BYREF
char v108; // [rsp+FCh] [rbp-3Ch] BYREF

v3 = (char *)malloc(0x20uLL);
if ( argc <= 1 )
goto LABEL_70;
v54 = 1;
v4 = v3;
v44 = 0;
v5 = argv + 1;
v51 = 0;
v6 = &argv[(unsigned int)(argc - 2) + 2];
while ( 1 )
{
v7 = *v5;
if ( strlen(*v5) <= 8 && *v7 == 45 )
break;
v8 = 32LL * ++v44;
v4 = (char *)realloc(v4, v8);
if ( !v51 )
{
base32_decode(v7, &v4[v8 - 32]);
goto LABEL_10;
}
if ( v51 != 1 )
{
if ( (unsigned int)_isoc99_sscanf(
v7,
"%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%"
"02x%02x%02x%02x%02x%02x%02x%02x%02x",
s,
&s[4],
v79,
&v80,
&v81,
&v82,
&v83,
&v84,
&v85,
&v86,
&v87,
&v88,
&v89,
&v90,
&v91,
&v92,
&v93,
&v94,
&v95,
&v96,
&v97,
&v98,
&v99,
&v100,
&v101,
&v102,
&v103,
&v104,
&v105,
&v106,
&v107,
&v108) != 32 )
{
fwrite("Bad key format.\n", 1uLL, 0x10uLL, stderr);
v42 = 1;
goto LABEL_71;
}
v9 = (__int64)&v4[v8 - 32];
for ( i = 0LL; i != 32; ++i )
{
v11 = *(unsigned int *)&s[4 * i];
v12 = (unsigned int)i;
curve25519key_setbyte(v9, v12, v11);
}
LABEL_9:
v51 = 2;
goto LABEL_10;
}
v15 = (__int64)&v4[v8 - 32];
v16 = strlen(v7);
if ( v16 <= 0 )
{
v17 = 0;
}
else
{
v17 = 0;
v18 = (char *)&v7[v16 - 1];
v49 = (__int64)&v7[v16 - 2 - (v16 - 1)];
do
{
v19 = (unsigned int)*v18;
v20 = *v18;
if ( *v18 > 70 )
{
if ( (unsigned __int8)(v20 - 97) > 5u )
{
LABEL_37:
fprintf(stderr, "Bad character where an hexadecimal key was expected: %c\n", v19);
exit(1);
}
v21 = v19 - 87;
}
else if ( *v18 > 64 )
{
v21 = v19 - 55;
}
else
{
if ( (unsigned __int8)(v20 - 48) > 9u )
goto LABEL_37;
v21 = v19 - 48;
}
v47 = v18;
curve25519key_setbit(v15, v17, v21 & 1);
curve25519key_setbit(v15, v17 + 1, (v21 >> 1) & 1);
curve25519key_setbit(v15, v17 + 2, (v21 >> 2) & 1);
v22 = v17 + 3;
v17 += 4;
curve25519key_setbit(v15, v22, (v21 >> 3) & 1);
v18 = v47 - 1;
}
while ( v47 - 1 != (char *)v49 );
if ( v17 > 0xFF )
goto LABEL_10;
}
do
{
v23 = v17++;
curve25519key_setbit(v15, v23, 0LL);
}
while ( v17 != 256 );
LABEL_10:
if ( ++v5 == v6 )
{
if ( !v54 )
{
v14 = v44;
LABEL_45:
if ( v14 == 1 )
{
v28 = 6LL;
v24 = 1LL;
v29 = v79;
while ( v28 )
{
*(_DWORD *)v29 = 0;
v29 += 4;
--v28;
}
*(_QWORD *)s = 9LL;
curve25519(v4, v4, s);
}
else
{
if ( v14 <= 1 )
goto LABEL_70;
v24 = v14;
v25 = v14 - 1;
v26 = &v4[32 * v25 - 32];
v27 = &v4[32 * v25];
while ( 1 )
{
curve25519(v27, v26, v27);
if ( &v4[32 * v14 - 64 + -32 * (v14 - 2)] == v26 )
break;
if ( v54 )
{
if ( !(unsigned int)curve25519key_validate(v27) )
{
fwrite("Intermediate key may be unsafe!\n", 1uLL, 0x20uLL, stderr);
if ( v54 == 2 )
goto LABEL_17;
}
}
v26 -= 32;
}
}
v30 = (__int64)&v4[32 * v24 - 32];
if ( !v54
|| (unsigned int)curve25519key_validate(v30)
|| (fwrite("Output key may be unsafe!\n", 1uLL, 0x1AuLL, stderr), v54 != 2) )
{
if ( v51 )
{
if ( v51 == 1 )
{
v53 = curve25519key_getuint32(v30, 0LL);
v46 = curve25519key_getuint32(v30, 1LL);
v36 = (unsigned int)curve25519key_getuint32(v30, 2LL);
v37 = curve25519key_getuint32(v30, 3LL);
v38 = curve25519key_getuint32(v30, 4LL);
v39 = curve25519key_getuint32(v30, 5LL);
v40 = curve25519key_getuint32(v30, 6LL);
v41 = curve25519key_getuint32(v30, 7LL);
printf("%08x%08x%08x%08x%08x%08x%08x%08x\n", v41, v40, v39, v38, v37, v36, v46, v53);
}
else
{
v77 = curve25519key_getbyte(v30, 31LL);
v76 = curve25519key_getbyte(v30, 30LL);
v75 = curve25519key_getbyte(v30, 29LL);
v74 = curve25519key_getbyte(v30, 28LL);
v73 = curve25519key_getbyte(v30, 27LL);
v31 = (unsigned int)curve25519key_getbyte(v30, 26LL);
v72 = curve25519key_getbyte(v30, 25LL);
v45 = curve25519key_getbyte(v30, 24LL);
v52 = curve25519key_getbyte(v30, 23LL);
v48 = curve25519key_getbyte(v30, 22LL);
v50 = curve25519key_getbyte(v30, 21LL);
v55 = curve25519key_getbyte(v30, 20LL);
v57 = curve25519key_getbyte(v30, 19LL);
v58 = curve25519key_getbyte(v30, 18LL);
v59 = curve25519key_getbyte(v30, 17LL);
v60 = curve25519key_getbyte(v30, 16LL);
v61 = curve25519key_getbyte(v30, 15LL);
v62 = curve25519key_getbyte(v30, 14LL);
v63 = curve25519key_getbyte(v30, 13LL);
v64 = curve25519key_getbyte(v30, 12LL);
v65 = curve25519key_getbyte(v30, 11LL);
v66 = curve25519key_getbyte(v30, 10LL);
v67 = curve25519key_getbyte(v30, 9LL);
v68 = curve25519key_getbyte(v30, 8LL);
v69 = curve25519key_getbyte(v30, 7LL);
v70 = curve25519key_getbyte(v30, 6LL);
v71 = curve25519key_getbyte(v30, 5LL);
v32 = curve25519key_getbyte(v30, 4LL);
v33 = curve25519key_getbyte(v30, 3LL);
v34 = curve25519key_getbyte(v30, 2LL);
v35 = curve25519key_getbyte(v30, 1LL);
v43 = curve25519key_getbyte(v30, 0LL);
printf(
"%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x"
"%02x%02x%02x%02x%02x%02x\n",
v43,
v35,
v34,
v33,
v32,
v71,
v70,
v69,
v68,
v67,
v66,
v65,
v64,
v63,
v62,
v61,
v60,
v59,
v58,
v57,
v55,
v50,
v48,
v52,
v45,
v72,
v31,
v73,
v74,
v75,
v76,
v77);
}
}
else
{
base32_encode(s, v30);
puts(s);
}
exit(0);
}
goto LABEL_17;
}
if ( v44 )
{
v13 = v4;
v14 = 0;
while ( 1 )
{
if ( !(unsigned int)curve25519key_validate(v13) )
{
fprintf(stderr, "Input key n. %d may be unsafe!\n", (unsigned int)v14);
if ( v54 == 2 )
break;
}
++v14;
v13 += 32;
if ( v44 == v14 )
goto LABEL_45;
}
LABEL_17:
exit(1);
}
LABEL_70:
v42 = 0;
LABEL_71:
usage(stderr, *argv, v42);
goto LABEL_17;
}
}
if ( !strcmp(v7, "--hex") )
{
v51 = 1;
goto LABEL_10;
}
if ( strcmp(v7, "--ibh") )
{
if ( !strcmp(v7, "--b32") )
{
v51 = 0;
}
else if ( !strcmp(v7, "--safe") )
{
v54 = 2;
}
else if ( !strcmp(v7, "--warn") )
{
v54 = 1;
}
else if ( !strcmp(v7, "--unsafe") )
{
v54 = 0;
}
else if ( !strcmp(v7, "--help") )
{
usage(stdout, *argv, 0);
exit(0);
}
goto LABEL_10;
}
goto LABEL_9;
}

canonical_decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
char *v3; // rax
char *v4; // rbp
const char **v5; // rbx
const char **v6; // r12
const char *v7; // r14
size_t v8; // r15
__int64 v9; // r15
__int64 i; // r14
__int64 v11; // rdx
__int64 v12; // rsi
char *v13; // rbx
int v14; // er14
__int64 v15; // r15
int v16; // eax
unsigned int v17; // er13
char *v18; // rcx
__int64 v19; // rdx
char v20; // al
unsigned int v21; // er14
__int64 v22; // rsi
__int64 v23; // rsi
__int64 v24; // r15
__int64 v25; // r8
char *v26; // rbx
char *v27; // r13
__int64 v28; // rcx
char *v29; // rdi
__int64 v30; // rbp
__int64 v31; // r15
unsigned int v32; // er14
unsigned int v33; // ebx
unsigned int v34; // er13
unsigned int v35; // er12
__int64 v36; // r15
unsigned int v37; // er14
unsigned int v38; // ebx
unsigned int v39; // er13
unsigned int v40; // er12
unsigned int v41; // eax
int v42; // edx
unsigned int v43; // [rsp-8h] [rbp-140h]
int v44; // [rsp+Ch] [rbp-12Ch]
unsigned int v45; // [rsp+Ch] [rbp-12Ch]
unsigned int v46; // [rsp+Ch] [rbp-12Ch]
char *v47; // [rsp+10h] [rbp-128h]
unsigned int v48; // [rsp+10h] [rbp-128h]
__int64 v49; // [rsp+18h] [rbp-120h]
unsigned int v50; // [rsp+18h] [rbp-120h]
int v51; // [rsp+20h] [rbp-118h]
unsigned int v52; // [rsp+20h] [rbp-118h]
unsigned int v53; // [rsp+20h] [rbp-118h]
int v54; // [rsp+24h] [rbp-114h]
unsigned int v55; // [rsp+24h] [rbp-114h]
unsigned int v57; // [rsp+28h] [rbp-110h]
unsigned int v58; // [rsp+30h] [rbp-108h]
unsigned int v59; // [rsp+34h] [rbp-104h]
unsigned int v60; // [rsp+38h] [rbp-100h]
unsigned int v61; // [rsp+3Ch] [rbp-FCh]
unsigned int v62; // [rsp+40h] [rbp-F8h]
unsigned int v63; // [rsp+44h] [rbp-F4h]
unsigned int v64; // [rsp+48h] [rbp-F0h]
unsigned int v65; // [rsp+4Ch] [rbp-ECh]
unsigned int v66; // [rsp+50h] [rbp-E8h]
unsigned int v67; // [rsp+54h] [rbp-E4h]
unsigned int v68; // [rsp+58h] [rbp-E0h]
unsigned int v69; // [rsp+5Ch] [rbp-DCh]
unsigned int v70; // [rsp+60h] [rbp-D8h]
unsigned int v71; // [rsp+64h] [rbp-D4h]
unsigned int v72; // [rsp+68h] [rbp-D0h]
unsigned int v73; // [rsp+6Ch] [rbp-CCh]
unsigned int v74; // [rsp+70h] [rbp-C8h]
unsigned int v75; // [rsp+74h] [rbp-C4h]
unsigned int v76; // [rsp+78h] [rbp-C0h]
unsigned int v77; // [rsp+7Ch] [rbp-BCh]
char s[8]; // [rsp+80h] [rbp-B8h] BYREF
char v79[4]; // [rsp+88h] [rbp-B0h] BYREF
char v80; // [rsp+8Ch] [rbp-ACh] BYREF
char v81; // [rsp+90h] [rbp-A8h] BYREF
char v82; // [rsp+94h] [rbp-A4h] BYREF
char v83; // [rsp+98h] [rbp-A0h] BYREF
char v84; // [rsp+9Ch] [rbp-9Ch] BYREF
char v85; // [rsp+A0h] [rbp-98h] BYREF
char v86; // [rsp+A4h] [rbp-94h] BYREF
char v87; // [rsp+A8h] [rbp-90h] BYREF
char v88; // [rsp+ACh] [rbp-8Ch] BYREF
char v89; // [rsp+B0h] [rbp-88h] BYREF
char v90; // [rsp+B4h] [rbp-84h] BYREF
char v91; // [rsp+B8h] [rbp-80h] BYREF
char v92; // [rsp+BCh] [rbp-7Ch] BYREF
char v93; // [rsp+C0h] [rbp-78h] BYREF
char v94; // [rsp+C4h] [rbp-74h] BYREF
char v95; // [rsp+C8h] [rbp-70h] BYREF
char v96; // [rsp+CCh] [rbp-6Ch] BYREF
char v97; // [rsp+D0h] [rbp-68h] BYREF
char v98; // [rsp+D4h] [rbp-64h] BYREF
char v99; // [rsp+D8h] [rbp-60h] BYREF
char v100; // [rsp+DCh] [rbp-5Ch] BYREF
char v101; // [rsp+E0h] [rbp-58h] BYREF
char v102; // [rsp+E4h] [rbp-54h] BYREF
char v103; // [rsp+E8h] [rbp-50h] BYREF
char v104; // [rsp+ECh] [rbp-4Ch] BYREF
char v105; // [rsp+F0h] [rbp-48h] BYREF
char v106; // [rsp+F4h] [rbp-44h] BYREF
char v107; // [rsp+F8h] [rbp-40h] BYREF
char v108; // [rsp+FCh] [rbp-3Ch] BYREF

v3 = (char *)malloc(0x20uLL);
if ( argc <= 1 )
goto LABEL_70;
v54 = 1;
v4 = v3;
v44 = 0;
v5 = argv + 1;
v51 = 0;
v6 = &argv[(unsigned int)(argc - 2) + 2];
while ( 1 )
{
v7 = *v5;
if ( strlen(*v5) <= 8 && *v7 == 45 )
break;
v8 = 32LL * ++v44;
v4 = (char *)realloc(v4, v8);
if ( !v51 )
{
base32_decode(v7, &v4[v8 - 32]);
goto LABEL_10;
}
if ( v51 != 1 )
{
if ( (unsigned int)_isoc99_sscanf(
v7,
"%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%"
"02x%02x%02x%02x%02x%02x%02x%02x%02x",
s,
&s[4],
v79,
&v80,
&v81,
&v82,
&v83,
&v84,
&v85,
&v86,
&v87,
&v88,
&v89,
&v90,
&v91,
&v92,
&v93,
&v94,
&v95,
&v96,
&v97,
&v98,
&v99,
&v100,
&v101,
&v102,
&v103,
&v104,
&v105,
&v106,
&v107,
&v108) != 32 )
{
fwrite("Bad key format.\n", 1uLL, 0x10uLL, stderr);
v42 = 1;
goto LABEL_71;
}
v9 = (__int64)&v4[v8 - 32];
for ( i = 0LL; i != 32; ++i )
{
v11 = *(unsigned int *)&s[4 * i];
v12 = (unsigned int)i;
curve25519key_setbyte(v9, v12, v11);
}
LABEL_9:
v51 = 2;
goto LABEL_10;
}
v15 = (__int64)&v4[v8 - 32];
v16 = strlen(v7);
if ( v16 <= 0 )
{
v17 = 0;
}
else
{
v17 = 0;
v18 = (char *)&v7[v16 - 1];
v49 = (__int64)&v7[v16 - 2 - (v16 - 1)];
do
{
v19 = (unsigned int)*v18;
v20 = *v18;
if ( *v18 > 70 )
{
if ( (unsigned __int8)(v20 - 97) > 5u )
{
LABEL_37:
fprintf(stderr, "Bad character where an hexadecimal key was expected: %c\n", v19);
exit(1);
}
v21 = v19 - 87;
}
else if ( *v18 > 64 )
{
v21 = v19 - 55;
}
else
{
if ( (unsigned __int8)(v20 - 48) > 9u )
goto LABEL_37;
v21 = v19 - 48;
}
v47 = v18;
curve25519key_setbit(v15, v17, v21 & 1);
curve25519key_setbit(v15, v17 + 1, (v21 >> 1) & 1);
curve25519key_setbit(v15, v17 + 2, (v21 >> 2) & 1);
v22 = v17 + 3;
v17 += 4;
curve25519key_setbit(v15, v22, (v21 >> 3) & 1);
v18 = v47 - 1;
}
while ( v47 - 1 != (char *)v49 );
if ( v17 > 0xFF )
goto LABEL_10;
}
do
{
v23 = v17++;
curve25519key_setbit(v15, v23, 0LL);
}
while ( v17 != 256 );
LABEL_10:
if ( ++v5 == v6 )
{
if ( !v54 )
{
v14 = v44;
LABEL_45:
if ( v14 == 1 )
{
v28 = 6LL;
v24 = 1LL;
v29 = v79;
while ( v28 )
{
*(_DWORD *)v29 = 0;
v29 += 4;
--v28;
}
*(_QWORD *)s = 9LL;
curve25519(v4, v4, s);
}
else
{
if ( v14 <= 1 )
goto LABEL_70;
v24 = v14;
v25 = v14 - 1;
v26 = &v4[32 * v25 - 32];
v27 = &v4[32 * v25];
while ( 1 )
{
curve25519(v27, v26, v27);
if ( &v4[32 * v14 - 64 + -32 * (v14 - 2)] == v26 )
break;
if ( v54 )
{
if ( !(unsigned int)curve25519key_validate(v27) )
{
fwrite("Intermediate key may be unsafe!\n", 1uLL, 0x20uLL, stderr);
if ( v54 == 2 )
goto LABEL_17;
}
}
v26 -= 32;
}
}
v30 = (__int64)&v4[32 * v24 - 32];
if ( !v54
|| (unsigned int)curve25519key_validate(v30)
|| (fwrite("Output key may be unsafe!\n", 1uLL, 0x1AuLL, stderr), v54 != 2) )
{
if ( v51 )
{
if ( v51 == 1 )
{
v53 = curve25519key_getuint32(v30, 0LL);
v46 = curve25519key_getuint32(v30, 1LL);
v36 = (unsigned int)curve25519key_getuint32(v30, 2LL);
v37 = curve25519key_getuint32(v30, 3LL);
v38 = curve25519key_getuint32(v30, 4LL);
v39 = curve25519key_getuint32(v30, 5LL);
v40 = curve25519key_getuint32(v30, 6LL);
v41 = curve25519key_getuint32(v30, 7LL);
printf("%08x%08x%08x%08x%08x%08x%08x%08x\n", v41, v40, v39, v38, v37, v36, v46, v53);
}
else
{
v77 = curve25519key_getbyte(v30, 31LL);
v76 = curve25519key_getbyte(v30, 30LL);
v75 = curve25519key_getbyte(v30, 29LL);
v74 = curve25519key_getbyte(v30, 28LL);
v73 = curve25519key_getbyte(v30, 27LL);
v31 = (unsigned int)curve25519key_getbyte(v30, 26LL);
v72 = curve25519key_getbyte(v30, 25LL);
v45 = curve25519key_getbyte(v30, 24LL);
v52 = curve25519key_getbyte(v30, 23LL);
v48 = curve25519key_getbyte(v30, 22LL);
v50 = curve25519key_getbyte(v30, 21LL);
v55 = curve25519key_getbyte(v30, 20LL);
v57 = curve25519key_getbyte(v30, 19LL);
v58 = curve25519key_getbyte(v30, 18LL);
v59 = curve25519key_getbyte(v30, 17LL);
v60 = curve25519key_getbyte(v30, 16LL);
v61 = curve25519key_getbyte(v30, 15LL);
v62 = curve25519key_getbyte(v30, 14LL);
v63 = curve25519key_getbyte(v30, 13LL);
v64 = curve25519key_getbyte(v30, 12LL);
v65 = curve25519key_getbyte(v30, 11LL);
v66 = curve25519key_getbyte(v30, 10LL);
v67 = curve25519key_getbyte(v30, 9LL);
v68 = curve25519key_getbyte(v30, 8LL);
v69 = curve25519key_getbyte(v30, 7LL);
v70 = curve25519key_getbyte(v30, 6LL);
v71 = curve25519key_getbyte(v30, 5LL);
v32 = curve25519key_getbyte(v30, 4LL);
v33 = curve25519key_getbyte(v30, 3LL);
v34 = curve25519key_getbyte(v30, 2LL);
v35 = curve25519key_getbyte(v30, 1LL);
v43 = curve25519key_getbyte(v30, 0LL);
printf(
"%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x"
"%02x%02x%02x%02x%02x%02x\n",
v43,
v35,
v34,
v33,
v32,
v71,
v70,
v69,
v68,
v67,
v66,
v65,
v64,
v63,
v62,
v61,
v60,
v59,
v58,
v57,
v55,
v50,
v48,
v52,
v45,
v72,
v31,
v73,
v74,
v75,
v76,
v77);
}
}
else
{
base32_encode(s, v30);
puts(s);
}
exit(0);
}
goto LABEL_17;
}
if ( v44 )
{
v13 = v4;
v14 = 0;
while ( 1 )
{
if ( !(unsigned int)curve25519key_validate(v13) )
{
fprintf(stderr, "Input key n. %d may be unsafe!\n", (unsigned int)v14);
if ( v54 == 2 )
break;
}
++v14;
v13 += 32;
if ( v44 == v14 )
goto LABEL_45;
}
LABEL_17:
exit(1);
}
LABEL_70:
v42 = 0;
LABEL_71:
func0(stderr, *argv, v42);
goto LABEL_17;
}
}
if ( !strcmp(v7, "--hex") )
{
v51 = 1;
goto LABEL_10;
}
if ( strcmp(v7, "--ibh") )
{
if ( !strcmp(v7, "--b32") )
{
v51 = 0;
}
else if ( !strcmp(v7, "--safe") )
{
v54 = 2;
}
else if ( !strcmp(v7, "--warn") )
{
v54 = 1;
}
else if ( !strcmp(v7, "--unsafe") )
{
v54 = 0;
}
else if ( !strcmp(v7, "--help") )
{
func0(stdout, *argv, 0);
exit(0);
}
goto LABEL_10;
}
goto LABEL_9;
}

variable_types: loop int

return_type: int


repo: reveil/goodenough

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // er13
unsigned int v4; // eax
int v6; // ebp
int v7; // eax
int v8; // er12
unsigned int v9; // er14
int v10; // eax
int v11; // er15
ssize_t v12; // rax
ssize_t v13; // rax
ssize_t v14; // rax
_BYTE v15[4096]; // [rsp+0h] [rbp-2038h] BYREF
char buf[4152]; // [rsp+1000h] [rbp-1038h] BYREF

v4 = listen_on_port(argv[1]);
if ( v4 != -1 )
{
v6 = v4;
v7 = accept_connection(v4);
v8 = v7;
if ( v7 != -1 )
{
v9 = recv(v7, v15, 0x1000uLL, 0);
printf("received %d bytes\n", v9);
v10 = connect_to(argv[2], argv[3]);
v11 = v10;
if ( v10 == -1 )
{
perror("ERROR: unable to connect to target");
}
else
{
v12 = send(v10, v15, (int)v9, 0);
printf("sent %d bytes to target\n", v12);
v13 = recv(v11, buf, 0x1000uLL, 0);
v3 = v13;
printf("got %d bytes from target\n", v13);
}
v14 = send(v8, buf, v3, 0);
printf("sent %d bytes\n", v14);
close(v8);
close(v6);
}
}
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // er13
unsigned int v4; // eax
int v6; // ebp
int v7; // eax
int v8; // er12
unsigned int v9; // er14
int v10; // eax
int v11; // er15
ssize_t v12; // rax
ssize_t v13; // rax
ssize_t v14; // rax
_BYTE v15[4096]; // [rsp+0h] [rbp-2038h] BYREF
char buf[4152]; // [rsp+1000h] [rbp-1038h] BYREF

v4 = func12(argv[1]);
if ( v4 != -1 )
{
v6 = v4;
v7 = func13(v4);
v8 = v7;
if ( v7 != -1 )
{
v9 = recv(v7, v15, 0x1000uLL, 0);
printf("received %d bytes\n", v9);
v10 = func14(argv[2], argv[3]);
v11 = v10;
if ( v10 == -1 )
{
perror("ERROR: unable to connect to target");
}
else
{
v12 = send(v10, v15, (int)v9, 0);
printf("sent %d bytes to target\n", v12);
v13 = recv(v11, buf, 0x1000uLL, 0);
v3 = v13;
printf("got %d bytes from target\n", v13);
}
v14 = send(v8, buf, v3, 0);
printf("sent %d bytes\n", v14);
close(v8);
close(v6);
}
}
return 0;
}

original_code:
int main(int argc, char *argv[])
{
    int socketfd, remotefd, targetfd;
    int received, sent;
    int target_sent, target_received;
    char req[4096], resp[4096];
    socketfd = listen_on_port(argv[1]);
    if (socketfd != -1) {
        remotefd = accept_connection(socketfd);
        if (remotefd != -1) {
            received = recv(remotefd, req, sizeof(req), 0);
            printf("received %d bytes\n", received);
            targetfd = connect_to(argv[2], argv[3]);
            if (targetfd != -1) {
                target_sent = send(targetfd, req, received, 0);
                printf("sent %d bytes to target\n", target_sent);
                target_received = recv(targetfd, resp, sizeof(resp), 0);
                printf("got %d bytes from target\n", target_received);
            }
            else {
                perror("ERROR: unable to connect to target");
            }
            sent = send(remotefd, resp, target_received, 0);
            printf("sent %d bytes\n", sent);
            close(remotefd);
            close(socketfd);
        }
    }
    return 0;
}

canonical_original_code:
int main(int argc, char *argv[])
{
    int socketfd; int remotefd; int targetfd;
    int received; int sent;
    int target_sent; int target_received;
    char req[4096]; char resp[4096];
    socketfd = listen_on_port(argv[1]);
    if (socketfd != -1) {
        remotefd = accept_connection(socketfd);
        if (remotefd != -1) {
            received = recv(remotefd, req, sizeof(req), 0);
            printf("received %d bytes\n", received);
            targetfd = connect_to(argv[2], argv[3]);
            if (targetfd != -1) {
                target_sent = send(targetfd, req, received, 0);
                printf("sent %d bytes to target\n", target_sent);
                target_received = recv(targetfd, resp, sizeof(resp), 0);
                printf("got %d bytes from target\n", target_received);
            }
            else {
                perror("ERROR: unable to connect to target");
            }
            sent = send(remotefd, resp, target_received, 0);
            printf("sent %d bytes\n", sent);
            close(remotefd);
            close(socketfd);
        }
    }
    return 0;
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types: socketfd int

variable_types: remotefd int

variable_types: targetfd int

variable_types: received int

variable_types: sent int

variable_types:
req
char [4096]

variable_types:
resp
char [4096]


decompiled_code:
struct addrinfo *__fastcall prepare_addrinfo(const char *a1, const char *a2)
{
int v2; // eax
const char *v4; // rax
struct addrinfo *pai; // [rsp+8h] [rbp-40h] BYREF
struct addrinfo req; // [rsp+10h] [rbp-38h] BYREF

*(_OWORD *)&req.ai_flags = 0LL;
*(_OWORD *)&req.ai_addrlen = 0LL;
req.ai_socktype = 1;
*(_OWORD *)&req.ai_canonname = 0LL;
if ( !a1 )
req.ai_flags = 1;
v2 = getaddrinfo(a1, a2, &req, &pai);
if ( !v2 )
return pai;
v4 = gai_strerror(v2);
fprintf(_bss_start, "getaddrinfo: %s\n", v4);
return 0LL;
}

canonical_decompiled_code:
struct addrinfo *__fastcall func8(const char *a1, const char *a2)
{
int v2; // eax
const char *v4; // rax
struct addrinfo *pai; // [rsp+8h] [rbp-40h] BYREF
struct addrinfo req; // [rsp+10h] [rbp-38h] BYREF

*(_OWORD *)&req.ai_flags = 0LL;
*(_OWORD *)&req.ai_addrlen = 0LL;
req.ai_socktype = 1;
*(_OWORD *)&req.ai_canonname = 0LL;
if ( !a1 )
req.ai_flags = 1;
v2 = getaddrinfo(a1, a2, &req, &pai);
if ( !v2 )
return pai;
v4 = gai_strerror(v2);
fprintf(_bss_start, "getaddrinfo: %s\n", v4);
return 0LL;
}

original_code:
struct addrinfo* prepare_addrinfo(char *host, char *port)
{
    int status;
    struct addrinfo hints, *res;
    memset(&hints, 0, sizeof hints);
    hints.ai_family = 0;
    hints.ai_socktype = SOCK_STREAM;
    if (host == ((void *)0)) {
        hints.ai_flags = 0x0001;
    }
    status = getaddrinfo(host, port, &hints, &res);
    if (status != 0) {
        fprintf(stderr, "getaddrinfo: %s\n", gai_strerror(status));
        res = ((void *)0);
    }
    return res;
}

canonical_original_code:
struct addrinfo *prepare_addrinfo(char *host, char *port)
{
    int status;
    struct addrinfo hints; struct addrinfo *res;
    memset(&hints, 0, sizeof hints);
    hints.ai_family = 0;
    hints.ai_socktype = SOCK_STREAM;
    if (host == ((void *)0)) {
        hints.ai_flags = 0x0001;
    }
    status = getaddrinfo(host, port, &hints, &res);
    if (status != 0) {
        fprintf(stderr, "getaddrinfo: %s\n", gai_strerror(status));
        res = ((void *)0);
    }
    return res;
}

variable_types:
host
char *

variable_types:
port
char *

variable_types: status int

variable_types: struct addrinfo { int ai_flags; int ai_family; int ai_socktype; int ai_protocol; unsigned int ai_addrlen; struct sockaddr { unsigned short sa_family; char sa_data[14]; } *ai_addr; char *ai_canonname; struct addrinfo *ai_next; } *

user_defined_types: struct addrinfo { int ai_flags; int ai_family; int ai_socktype; int ai_protocol; unsigned int ai_addrlen; struct sockaddr *ai_addr; char *ai_canonname; struct addrinfo *ai_next; }


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

if ( a1 )
result = socket(a1[1], a1[2], a1[3]);
else
result = -1;
return result;
}

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

if ( a1 )
result = socket(a1[1], a1[2], a1[3]);
else
result = -1;
return result;
}

original_code:
int get_socket(struct addrinfo *res)
{
    int s = -1;
    if (res != ((void *)0)) {
        s = socket(res->ai_family, res->ai_socktype, res->ai_protocol);
    }
    return s;
}

variable_types: s int

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


decompiled_code:
__int64 __fastcall get_port_and_ip(__int64 a1, char *a2)
{
__int16 *v3; // rsi
int v4; // edi
__int16 v5; // bx
const void *v6; // rax
const void *v7; // rsi

v3 = *(__int16 **)(a1 + 24);
v4 = *(_DWORD *)(a1 + 4);
v5 = v3[1];
v6 = v3 + 2;
v7 = v3 + 4;
if ( v4 == 2 )
v7 = v6;
inet_ntop(v4, v7, a2, 0x2Eu);
return (unsigned __int16)_bswap_16(v5);
}

original_code:
int get_port_and_ip(struct addrinfo *res, char *ip)
{
    void *addr;
    unsigned short int port;
    if (res->ai_family == 2) {
        port = ((struct sockaddr_in*)res->ai_addr)->sin_port;
        addr = &((struct sockaddr_in*)res->ai_addr)->sin_addr;
    }
    else {
        port = ((struct sockaddr_in6*)res->ai_addr)->sin6_port;
        addr = &((struct sockaddr_in6*)res->ai_addr)->sin6_addr;
    }
    inet_ntop(res->ai_family, addr, ip, 46);
    return ntohs(port);
}

canonical_original_code:
int get_port_and_ip(struct addrinfo *res, char *ip)
{
    void *addr;
    unsigned short port;
    if (res->ai_family == 2) {
        port = ((struct sockaddr_in *)res->ai_addr)->sin_port;
        addr = &((struct sockaddr_in *)res->ai_addr)->sin_addr;
    }
    else {
        port = ((struct sockaddr_in6 *)res->ai_addr)->sin6_port;
        addr = &((struct sockaddr_in6 *)res->ai_addr)->sin6_addr;
    }
    inet_ntop(res->ai_family, addr, ip, 46);
    return ntohs(port);
}

variable_types:
ip
char *

variable_types:
addr
void *

variable_types:
port
unsigned short

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_in6 { unsigned short sin6_family; unsigned short sin6_port; unsigned int sin6_flowinfo; struct in6_addr sin6_addr; unsigned int sin6_scope_id; }

user_defined_types: struct in6_addr { union { unsigned char __u6_addr8[16]; unsigned short __u6_addr16[8]; unsigned int __u6_addr32[4]; } __in6_u; }


decompiled_code:
__int64 __fastcall bind_socket(__int64 a1)
{
int v1; // eax
unsigned int v2; // er12
int v4; // ebx
unsigned int v5; // eax
int v6; // edi
char v7[72]; // [rsp+0h] [rbp-48h] BYREF

v1 = get_socket((int *)a1);
v2 = v1;
if ( v1 == -1 )
return v2;
v4 = bind(v1, *(const struct sockaddr **)(a1 + 24), *(_DWORD *)(a1 + 16));
v5 = get_port_and_ip(a1, v7);
if ( v4 )
{
fprintf(_bss_start, "ERROR: bind to port %d on %s failed: ", v5, v7);
perror(0LL);
v6 = v2;
v2 = -1;
close(v6);
return v2;
}
printf("bind to port %d on %s OK\n", v5, v7);
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func11(__int64 a1)
{
int v1; // eax
unsigned int v2; // er12
int v4; // ebx
unsigned int v5; // eax
int v6; // edi
char v7[72]; // [rsp+0h] [rbp-48h] BYREF

v1 = func9((int *)a1);
v2 = v1;
if ( v1 == -1 )
return v2;
v4 = bind(v1, *(const struct sockaddr **)(a1 + 24), *(_DWORD *)(a1 + 16));
v5 = func10(a1, v7);
if ( v4 )
{
fprintf(_bss_start, "ERROR: bind to port %d on %s failed: ", v5, v7);
perror(0LL);
v6 = v2;
v2 = -1;
close(v6);
return v2;
}
printf("bind to port %d on %s OK\n", v5, v7);
return v2;
}

original_code:
int bind_socket(struct addrinfo *res)
{
    int socketfd, b;
    int port;
    char ip[46];
    socketfd = get_socket(res);
    if (socketfd != -1) {
        b = bind(socketfd, res->ai_addr, res->ai_addrlen);
        port = get_port_and_ip(res, ip);
        if (b != 0) {
            fprintf(stderr, "ERROR: bind to port %d on %s failed: ", port, ip);
            perror(((void *)0));
            close(socketfd);
            socketfd = -1;
        }
        else {
            printf("bind to port %d on %s OK\n", port, ip);
        }
    }
    return socketfd;
}

canonical_original_code:
int bind_socket(struct addrinfo *res)
{
    int socketfd; int b;
    int port;
    char ip[46];
    socketfd = get_socket(res);
    if (socketfd != -1) {
        b = bind(socketfd, res->ai_addr, res->ai_addrlen);
        port = get_port_and_ip(res, ip);
        if (b != 0) {
            fprintf(stderr, "ERROR: bind to port %d on %s failed: ", port, ip);
            perror(((void *)0));
            close(socketfd);
            socketfd = -1;
        }
        else {
            printf("bind to port %d on %s OK\n", port, ip);
        }
    }
    return socketfd;
}

variable_types: b int

variable_types: port int

variable_types:
ip
char [46]


decompiled_code:
__int64 __fastcall listen_on_port(const char *a1)
{
struct addrinfo *v1; // rbp
unsigned int v2; // er12
int v4; // edi

v1 = prepare_addrinfo(0LL, a1);
v2 = bind_socket((__int64)v1);
freeaddrinfo(v1);
if ( v2 != -1 && listen(v2, 20) == -1 )
{
fprintf(_bss_start, "ERROR: listen to port %s failed: ", a1);
v4 = v2;
v2 = -1;
close(v4);
}
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func12(const char *a1)
{
struct addrinfo *v1; // rbp
unsigned int v2; // er12
int v4; // edi

v1 = func8(0LL, a1);
v2 = func11((__int64)v1);
freeaddrinfo(v1);
if ( v2 != -1 && listen(v2, 20) == -1 )
{
fprintf(_bss_start, "ERROR: listen to port %s failed: ", a1);
v4 = v2;
v2 = -1;
close(v4);
}
return v2;
}

original_code:
int listen_on_port(char *port)
{
    int socketfd;
    struct addrinfo *res;
    res = prepare_addrinfo(((void *)0), port);
    socketfd = bind_socket(res);
    freeaddrinfo(res);
    if (socketfd != -1) {
        if (listen(socketfd, 20) == -1) {
            fprintf(stderr, "ERROR: listen to port %s failed: ", port);
            close(socketfd);
            socketfd = -1;
        }
    }
    return socketfd;
}

variable_types: socketfd int


decompiled_code:
int __fastcall accept_connection(int a1)
{
socklen_t addr_len; // [rsp+Ch] [rbp-8Ch] BYREF
struct sockaddr addr; // [rsp+10h] [rbp-88h] BYREF

addr_len = 128;
return accept(a1, &addr, &addr_len);
}

canonical_decompiled_code:
int __fastcall func13(int a1)
{
socklen_t addr_len; // [rsp+Ch] [rbp-8Ch] BYREF
struct sockaddr addr; // [rsp+10h] [rbp-88h] BYREF

addr_len = 128;
return accept(a1, &addr, &addr_len);
}

original_code:
int accept_connection(int socketfd)
{
    int remotefd;
    socklen_t addr_size;
    struct sockaddr_storage remote_addr;
    addr_size = sizeof(struct sockaddr_storage);
    remotefd = accept(socketfd, (struct sockaddr*)&remote_addr, &addr_size);
    return remotefd;
}

canonical_original_code:
int accept_connection(int socketfd)
{
    int remotefd;
    unsigned int addr_size;
    struct sockaddr_storage remote_addr;
    addr_size = sizeof(struct sockaddr_storage);
    remotefd = accept(socketfd, (struct sockaddr *)&remote_addr, &addr_size);
    return remotefd;
}

variable_types: remotefd int

variable_types: struct sockaddr_storage { unsigned short ss_family; char __ss_padding[-1]; unsigned long __ss_align; }


decompiled_code:
__int64 __fastcall connect_to(const char *a1, const char *a2)
{
struct addrinfo *v2; // rbp
int v3; // eax
unsigned int v4; // er12
int v6; // edi

v2 = prepare_addrinfo(a1, a2);
v3 = get_socket(&v2->ai_flags);
v4 = v3;
if ( v3 != -1 && connect(v3, v2->ai_addr, v2->ai_addrlen) == -1 )
{
fprintf(_bss_start, "ERROR: connect %s:%s failed: ", a1, a2);
perror(0LL);
v6 = v4;
v4 = -1;
close(v6);
}
freeaddrinfo(v2);
return v4;
}

canonical_decompiled_code:
__int64 __fastcall func14(const char *a1, const char *a2)
{
struct addrinfo *v2; // rbp
int v3; // eax
unsigned int v4; // er12
int v6; // edi

v2 = func8(a1, a2);
v3 = func9(&v2->ai_flags);
v4 = v3;
if ( v3 != -1 && connect(v3, v2->ai_addr, v2->ai_addrlen) == -1 )
{
fprintf(_bss_start, "ERROR: connect %s:%s failed: ", a1, a2);
perror(0LL);
v6 = v4;
v4 = -1;
close(v6);
}
freeaddrinfo(v2);
return v4;
}

original_code:
int connect_to(char *host, char *port)
{
    int socketfd;
    struct addrinfo *res;
    res = prepare_addrinfo(host, port);
    socketfd = get_socket(res);
    if (socketfd != -1) {
        if (connect(socketfd, res->ai_addr, res->ai_addrlen) == -1) {
            fprintf(stderr, "ERROR: connect %s:%s failed: ", host, port);
            perror(((void *)0));
            close(socketfd);
            socketfd = -1;
        }
    }
    freeaddrinfo(res);
    return socketfd;
}


mymalloc

decompiled_code:
void *__fastcall mymalloc(size_t a1)
{
void *result; // rax

result = calloc(a1, 1uLL);
if ( !a1 )
errx(1, "Cannot malloc %d", 0LL);
return result;
}

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

result = calloc(a1, 1uLL);
if ( !a1 )
errx(1, "Cannot malloc %d", 0LL);
return result;
}

original_code:
void *
mymalloc (size_t n)
{
  void *m = malloc (n);
  if (!n)
    errx (1, "Cannot malloc %d", (int) n);
  memset (m, 0, n);
  return m;
}

canonical_original_code:
void *mymalloc(unsigned long n)
{
  void *m = malloc (n);
  if (!n)
    errx (1, "Cannot malloc %d", (int) n);
  memset (m, 0, n);
  return m;
}

variable_types:
n
unsigned long

variable_types:
m
void *

return_type: void *


dimplaces

decompiled_code:
char *__fastcall dimplaces(__int64 a1, int a2)
{
__int64 v2; // rax
char *v3; // rbx
char *v4; // rax
char v5; // dl

v2 = a1;
v3 = &val_0;
if ( a1 < 0 )
{
val_0 = 45;
v2 = -a1;
v3 = &val_0 + 1;
}
v4 = &v3[sprintf(v3, "%lld.%0*lld", v2 / fixed, a2, v2 % fixed / fixplaces)];
if ( v4 > &val_0 )
{
while ( 1 )
{
v5 = *(v4 - 1);
if ( v5 != 48 )
break;
if ( --v4 == &val_0 )
goto LABEL_9;
}
if ( v4 > &val_0 )
v4 -= v5 == 46;
}
LABEL_9:
*v4 = 0;
return &val_0;
}

original_code:
char *
dimplaces (poly_dim_t v, int places)
{
  static char val[100];
  char *c = val;
  if (v < 0)
    {
      v = 0 - v;
      *c++ = '-';
    }
  c += sprintf (c, "%lld.%0*lld", v / fixed, places, v % fixed / fixplaces);
  while (c > val && c[-1] == '0')
    c--;
  if (c > val && c[-1] == '.')
    c--;
  *c = 0;
  return val;
}

canonical_original_code:
char *dimplaces(long long v, int places)
{
  static char val[100];
  char *c = val;
  if (v < 0)
    {
      v = 0 - v;
      *c++ = '-';
    }
  c += sprintf (c, "%lld.%0*lld", v / fixed, places, v % fixed / fixplaces);
  while (c > val && c[-1] == '0')
    c--;
  if (c > val && c[-1] == '.')
    c--;
  *c = 0;
  return val;
}

variable_types:
v
long long

variable_types: places int

variable_types:
val
char [100]

variable_types:
c
char *

return_type: char *


decompiled_code:
__int64 __fastcall poly_sub(__int64 a1, __int64 a2)
{
__int64 v2; // rbp
__int64 v3; // r12

v2 = poly_clip(4294967294LL, 2LL, a1, a2);
v3 = poly_clip(2LL, 2LL, a1, v2);
poly_free(v2);
return v3;
}

original_code:
polygon_t *
poly_sub (polygon_t * a, polygon_t * b)
{
  polygon_t *d = poly_clip (-2, 2, a, b);
  polygon_t *r = poly_clip (2, 2, a, d);
  poly_free (d);
  return r;
}

canonical_original_code:
struct polygon_s *poly_sub(struct polygon_s *a, struct polygon_s *b)
{
  struct polygon_s *d = poly_clip (-2, 2, a, b);
  struct polygon_s *r = poly_clip (2, 2, a, d);
  poly_free (d);
  return r;
}

variable_types:
a
struct polygon_s *

variable_types:
b
struct polygon_s *

variable_types: struct polygon_s { struct poly_contour_s { struct poly_contour_s *next; struct poly_vertex_s { struct poly_vertex_s *next; int flag; long long x; } *vertices; int dir; } *contours; struct poly_vertex_s **add; } *

user_defined_types: struct polygon_s { struct poly_contour_s *contours; struct poly_vertex_s **add; }

user_defined_types: struct poly_contour_s { struct poly_contour_s *next; struct poly_vertex_s *vertices; int dir; }


decompiled_code:
int __fastcall stl_origin(_QWORD *a1)
{
_QWORD *v1; // rdx
__int64 v3; // rsi
__int64 v4; // r8
__int64 i; // rdi
_QWORD *v6; // rax
int result; // eax
const char *v8; // rax
const char *v9; // rax
const char *v10; // rax

v1 = (_QWORD *)a1[9];
v3 = a1[3];
v4 = a1[5];
for ( i = a1[4]; v1; v1 = (_QWORD *)*v1 )
{
v6 = v1 + 1;
do
{
*v6 -= v3;
v6[1] -= i;
v6[2] -= v4;
v6 += 3;
}
while ( v6 != v1 + 10 );
}
a1[6] -= v3;
a1[7] -= i;
result = debug;
a1[8] -= v4;
a1[3] = 0LL;
a1[4] = 0LL;
a1[5] = 0LL;
if ( result )
{
fwrite("Origin adjusted\n", 1uLL, 0x10uLL, stderr);
v8 = (const char *)dimplaces(a1[6], places);
fprintf(stderr, "Max X %s\n", v8);
v9 = (const char *)dimplaces(a1[7], places);
fprintf(stderr, "Max Y %s\n", v9);
v10 = (const char *)dimplaces(a1[8], places);
result = fprintf(stderr, "Max Z %s\n", v10);
}
return result;
}

canonical_decompiled_code:
int __fastcall func2(_QWORD *a1)
{
_QWORD *v1; // rdx
__int64 v3; // rsi
__int64 v4; // r8
__int64 i; // rdi
_QWORD *v6; // rax
int result; // eax
const char *v8; // rax
const char *v9; // rax
const char *v10; // rax

v1 = (_QWORD *)a1[9];
v3 = a1[3];
v4 = a1[5];
for ( i = a1[4]; v1; v1 = (_QWORD *)*v1 )
{
v6 = v1 + 1;
do
{
*v6 -= v3;
v6[1] -= i;
v6[2] -= v4;
v6 += 3;
}
while ( v6 != v1 + 10 );
}
a1[6] -= v3;
a1[7] -= i;
result = debug;
a1[8] -= v4;
a1[3] = 0LL;
a1[4] = 0LL;
a1[5] = 0LL;
if ( result )
{
fwrite("Origin adjusted\n", 1uLL, 0x10uLL, stderr);
v8 = (const char *)dimplaces(a1[6], places);
fprintf(stderr, "Max X %s\n", v8);
v9 = (const char *)dimplaces(a1[7], places);
fprintf(stderr, "Max Y %s\n", v9);
v10 = (const char *)dimplaces(a1[8], places);
result = fprintf(stderr, "Max Z %s\n", v10);
}
return result;
}

original_code:
void
stl_origin (stl_t * stl)
{
  facet_t *e;
  for (e = stl->facets; e; e = e->next)
    {
      int v;
      for (v = 0; v < 3; v++)
 {
   e->vertex[v].x -= stl->min.x;
   e->vertex[v].y -= stl->min.y;
   e->vertex[v].z -= stl->min.z;
 }
    }
  stl->max.x -= stl->min.x;
  stl->max.y -= stl->min.y;
  stl->max.z -= stl->min.z;
  stl->min.x = 0;
  stl->min.y = 0;
  stl->min.z = 0;
  if (debug)
    {
      fprintf (stderr, "Origin adjusted\n");
      fprintf (stderr, "Max X %s\n", dimplaces(stl->max.x,places));
      fprintf (stderr, "Max Y %s\n", dimplaces(stl->max.y,places));
      fprintf (stderr, "Max Z %s\n", dimplaces(stl->max.z,places));
    }
}

canonical_original_code:
void stl_origin(struct stl_s *stl)
{
  struct facet_s *e;
  for (e = stl->facets; e; e = e->next)
    {
      int v;
      for (v = 0; v < 3; v++)
 {
   e->vertex[v].x -= stl->min.x;
   e->vertex[v].y -= stl->min.y;
   e->vertex[v].z -= stl->min.z;
 }
    }
  stl->max.x -= stl->min.x;
  stl->max.y -= stl->min.y;
  stl->max.z -= stl->min.z;
  stl->min.x = 0;
  stl->min.y = 0;
  stl->min.z = 0;
  if (debug)
    {
      fprintf (stderr, "Origin adjusted\n");
      fprintf (stderr, "Max X %s\n", dimplaces(stl->max.x,places));
      fprintf (stderr, "Max Y %s\n", dimplaces(stl->max.y,places));
      fprintf (stderr, "Max Z %s\n", dimplaces(stl->max.z,places));
    }
}

variable_types: struct stl_s { char *filename; char *name; int count; struct { long long x; } min; struct facet_s { struct facet_s *next; struct { long long x; } vertex[3]; } *facets; struct slice_s { struct slice_s *next; long long z; struct polygon_s { struct poly_contour_s { struct poly_contour_s *next; struct poly_vertex_s { struct poly_vertex_s *next; int flag; long long x; } *vertices; int dir; } *contours; struct poly_vertex_s **add; } *outline; struct polygon_s *fill; struct polygon_s *infill; struct polygon_s *solid; struct polygon_s *flying; struct polygon_s *extrude[-1]; } *slices; struct polygon_s *border; struct polygon_s *anchor; struct polygon_s *anchorjoin; } *

variable_types: v int

user_defined_types: struct stl_s { char *filename; char *name; int count; struct { long long x; } min; struct facet_s *facets; struct slice_s *slices; struct polygon_s *border; struct polygon_s *anchor; struct polygon_s *anchorjoin; }

user_defined_types: struct slice_s { struct slice_s *next; long long z; struct polygon_s *outline; struct polygon_s *fill; struct polygon_s *infill; struct polygon_s *solid; struct polygon_s *flying; struct polygon_s *extrude[-1]; }


repo: rfaisal/SPOKC

decompiled_code:
double __fastcall round2(int a1, double a2)
{
double v2; // xmm0_8
double v3; // xmm0_8

v2 = pow(10.0, (double)a1) * a2;
if ( v2 < 0.0 )
v3 = v2 - 0.5;
else
v3 = v2 + 0.5;
return (double)(int)v3 / pow(10.0, (double)a1);
}

canonical_decompiled_code:
double __fastcall func1(int a1, double a2)
{
double v2; // xmm0_8
double v3; // xmm0_8

v2 = pow(10.0, (double)a1) * a2;
if ( v2 < 0.0 )
v3 = v2 - 0.5;
else
v3 = v2 + 0.5;
return (double)(int)v3 / pow(10.0, (double)a1);
}

original_code:
double round2(double num, int precision)
 {
  double rnum;
  int tnum;
  rnum = num*pow(10,precision);
  tnum = (int)(rnum < 0 ? rnum-0.5 : rnum + 0.5);
  rnum = tnum/pow(10,precision);
  return rnum;
 }

variable_types: num double

variable_types: precision int

variable_types: rnum double

variable_types: tnum int

return_type: double


decompiled_code:
void __fastcall my_constraints(double *a1, int a2)
{
double *v2; // rbx
double v3; // xmm0_8

if ( a2 > 0 )
{
v2 = a1;
do
{
v3 = *v2++;
*(v2 - 1) = round2(2, v3);
}
while ( v2 != &a1[(unsigned int)(a2 - 1) + 1] );
}
}

canonical_decompiled_code:
void __fastcall func2(double *a1, int a2)
{
double *v2; // rbx
double v3; // xmm0_8

if ( a2 > 0 )
{
v2 = a1;
do
{
v3 = *v2++;
*(v2 - 1) = func1(2, v3);
}
while ( v2 != &a1[(unsigned int)(a2 - 1) + 1] );
}
}

original_code:
void my_constraints(double x[], int n)
 {
   int i;
   for (i=0; i<n; i++) {
     x[i] = round2(x[i],2);
   }
 }

variable_types:
x
double []

variable_types: n int

variable_types: i int


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
double v4; // [rsp+0h] [rbp-18h] BYREF
double v5; // [rsp+8h] [rbp-10h]

v5 = *(double *)&LC0;
v4 = *(double *)&LC5;
simplex(rosen, &v4, 2LL, my_constraints, 0.0001);
printf("%f\n", v4);
printf("%f\n", v5);
return 0;
}

original_code:
int main()
 {
  double start[] = {-1.2,1.0};
  double min;
  int i;
  min=simplex(rosen,start,2,1.0e-4,1,my_constraints);
  for (i=0;i<2;i++) {
   printf("%f\n",start[i]);
  }
  return 0;
 }

variable_types:
start
double []

variable_types: min double


objfun

original_code:
double objfun(double x[])
 {
   double Req;
   double VL;
   double PL;
   double Vs = 9.0;
   double RL = x[0];
   Req = 470*RL/(470+RL);
   VL = Vs*Req/(1000+Req);
   PL = VL*VL/RL;
   printf("RL:%f P:%f\n",RL,PL);
   return -PL;
 }

variable_types: Req double

variable_types: VL double

variable_types: PL double

variable_types: Vs double

variable_types: RL double


decompiled_code:
void __fastcall my_constraints(double *a1, int a2)
{
__int64 v2; // rax

if ( a2 > 0 )
{
v2 = (__int64)&a1[(unsigned int)(a2 - 1) + 1];
do
{
if ( *a1 < 0.0 )
*(_QWORD *)a1 &= LC1;
++a1;
}
while ( a1 != (double *)v2 );
}
}

original_code:
void my_constraints(double x[], int n)
 {
   int i;
   for (i=0; i<n; i++) {
     if (x[i] < 0) {
       x[i] = fabs(x[i]);
     }
   }
 }


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
double v4[2]; // [rsp+8h] [rbp-10h] BYREF

v4[0] = *(double *)&LC7;
simplex(objfun, v4, 1LL, my_constraints, 0.00000001, 1.0);
printf("%f\n", v4[0]);
return 0;
}

original_code:
int main()
{
 double start[] = {100};
 double min;
 int i;
  int dim = 1;
  double eps = 1.0e-8;
  double scale = 1.0;
 min=simplex(objfun,start,dim,eps,scale,my_constraints);
 for (i=0; i<dim; i++) {
  printf("%f\n",start[i]);
 }
 return 0;
}

variable_types: dim int

variable_types: eps double

variable_types: scale double


subscribed

decompiled_code:
_BOOL8 __fastcall subscribed(__int64 **a1, __int64 a2)
{
_BOOL8 result; // rax
__int64 *v3; // rbx
int v4; // ebp

result = 0LL;
if ( a1 )
{
v3 = *a1;
if ( *a1 )
{
v4 = 1;
do
{
if ( *((_DWORD *)v3 + 8) != v4 )
{
if ( (unsigned int)wildmat(a2, v3[1]) )
v4 = *((_DWORD *)v3 + 8);
}
v3 = (__int64 *)*v3;
}
while ( v3 );
result = v4 == 0;
}
}
return result;
}

canonical_decompiled_code:
_BOOL8 __fastcall func0(__int64 **a1, __int64 a2)
{
_BOOL8 result; // rax
__int64 *v3; // rbx
int v4; // ebp

result = 0LL;
if ( a1 )
{
v3 = *a1;
if ( *a1 )
{
v4 = 1;
do
{
if ( *((_DWORD *)v3 + 8) != v4 )
{
if ( (unsigned int)wildmat(a2, v3[1]) )
v4 = *((_DWORD *)v3 + 8);
}
v3 = (__int64 *)*v3;
}
while ( v3 );
result = v4 == 0;
}
}
return result;
}

original_code:
int subscribed(LIST *sub_list, const char *gname)
{
    int unsub = 1;
    GROUP *gp;
    if (sub_list) for (gp = sub_list->head; gp; gp = gp->next) {
 if ((unsub != gp->u.not) && wildmat(gname, gp->name))
     unsub = gp->u.not;
    }
    return !unsub;
}

canonical_original_code:
int subscribed(struct LIST *sub_list, char *gname)
{
    int unsub = 1;
    struct group_s *gp;
    if (sub_list) for (gp = sub_list->head; gp; gp = gp->next) {
 if ((unsub != gp->u.not) && wildmat(gname, gp->name))
     unsub = gp->u.not;
    }
    return !unsub;
}

variable_types: struct LIST { struct group_s { struct group_s *next; char *name; char *desc; int order; union { int not; struct tag_s { struct tag_s *next; struct group_s *group; } *tag; } u; } *head; struct group_s *tail; unsigned int length; } *

variable_types:
gname
char *

variable_types: unsub int

user_defined_types: struct LIST { struct group_s *head; struct group_s *tail; unsigned int length; }

user_defined_types: struct group_s { struct group_s *next; char *name; char *desc; int order; union { int not; struct tag_s *tag; } u; }


decompiled_code:
_QWORD *create_list()
{
_QWORD *result; // rax

result = malloc(0x18uLL);
if ( result )
{
result[1] = 0LL;
*result = 0LL;
*((_DWORD *)result + 4) = 0;
}
else
{
gupout(1LL, "malloc of LIST failed");
result = (_QWORD *)add_group();
}
return result;
}

canonical_decompiled_code:
_QWORD *func1()
{
_QWORD *result; // rax

result = malloc(0x18uLL);
if ( result )
{
result[1] = 0LL;
*result = 0LL;
*((_DWORD *)result + 4) = 0;
}
else
{
gupout(1LL, "malloc of LIST failed");
result = (_QWORD *)add_group();
}
return result;
}

original_code:
LIST *create_list(void)
{
    LIST *l;
    l = malloc(sizeof(LIST));
    if (!l)
 gupout(1, "malloc of LIST failed");
    l->head = l->tail = ((void *)0);
    l->length = 0;
    return l;
}

canonical_original_code:
struct LIST *create_list()
{
    struct LIST *l;
    l = malloc(sizeof(LIST));
    if (!l)
 gupout(1, "malloc of LIST failed");
    l->head = l->tail = ((void *)0);
    l->length = 0;
    return l;
}

return_type: struct LIST { struct group_s { struct group_s *next; char *name; char *desc; int order; union { int not; struct tag_s { struct tag_s *next; struct group_s *group; } *tag; } u; } *head; struct group_s *tail; unsigned int length; } *


decompiled_code:
__int64 __fastcall remove_group(__int64 a1, __int64 *a2)
{
__int64 *v2; // rax
__int64 result; // rax
__int64 *v4; // rdx

v2 = *(__int64 **)a1;
if ( !*(_QWORD *)a1 )
return logit(3LL, "ERROR: remove_group can't find group");
if ( v2 != a2 )
{
while ( 1 )
{
v4 = v2;
v2 = (__int64 *)*v2;
if ( !v2 )
return logit(3LL, "ERROR: remove_group can't find group");
if ( a2 == v2 )
{
*v4 = *a2;
result = *a2;
goto LABEL_8;
}
}
}
result = *v2;
v4 = 0LL;
*(_QWORD *)a1 = result;
LABEL_8:
--*(_DWORD *)(a1 + 16);
if ( !result )
*(_QWORD *)(a1 + 8) = v4;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, __int64 *a2)
{
__int64 *v2; // rax
__int64 result; // rax
__int64 *v4; // rdx

v2 = *(__int64 **)a1;
if ( !*(_QWORD *)a1 )
return logit(3LL, "ERROR: remove_group can't find group");
if ( v2 != a2 )
{
while ( 1 )
{
v4 = v2;
v2 = (__int64 *)*v2;
if ( !v2 )
return logit(3LL, "ERROR: remove_group can't find group");
if ( a2 == v2 )
{
*v4 = *a2;
result = *a2;
goto LABEL_8;
}
}
}
result = *v2;
v4 = 0LL;
*(_QWORD *)a1 = result;
LABEL_8:
--*(_DWORD *)(a1 + 16);
if ( !result )
*(_QWORD *)(a1 + 8) = v4;
return result;
}

original_code:
void remove_group(LIST *list, GROUP *group)
{
    GROUP *prev, *tmp;
    prev = ((void *)0);
    for (tmp = list->head; tmp; tmp = tmp->next) {
 if (tmp == group)
     break;
 prev = tmp;
    }
    if (!tmp) {
 logit(((1<<0) | (1<<1)), "ERROR: remove_group can't find group");
 return;
    }
    if (!prev)
 list->head = group->next;
    else
 prev->next = group->next;
    if (!group->next)
 list->tail = prev;
    list->length--;
}

canonical_original_code:
void remove_group(struct LIST *list, struct group_s *group)
{
    struct group_s *prev; struct group_s *tmp;
    prev = ((void *)0);
    for (tmp = list->head; tmp; tmp = tmp->next) {
 if (tmp == group)
     break;
 prev = tmp;
    }
    if (!tmp) {
 logit(((1<<0) | (1<<1)), "ERROR: remove_group can't find group");
 return;
    }
    if (!prev)
 list->head = group->next;
    else
 prev->next = group->next;
    if (!group->next)
 list->tail = prev;
    list->length--;
}

variable_types:
group
struct group_s *

variable_types: struct group_s { struct group_s *next; char *name; char *desc; int order; union { int not; struct tag_s { struct tag_s *next; struct group_s *group; } *tag; } u; } *


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

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

original_code:
void destroy_group(GROUP *gp)
{
    free(gp);
}

canonical_original_code:
void destroy_group(struct group_s *gp)
{
    free(gp);
}

user_defined_types: struct tag_s { struct tag_s *next; struct group_s *group; }


xstrdup

decompiled_code:
void *__fastcall xstrdup(void *src)
{
size_t v1; // rax
size_t v2; // r13
size_t v3; // r12
void *v4; // rax

v1 = strlen((const char *)src);
v2 = v1 + 1;
v3 = v1;
v4 = malloc(v1 + 1);
if ( v4 )
return memcpy(v4, src, v2);
gupout(1LL, "xstrdup of %d failed", v3);
return (void *)create_group();
}

canonical_decompiled_code:
void *__fastcall func4(void *src)
{
size_t v1; // rax
size_t v2; // r13
size_t v3; // r12
void *v4; // rax

v1 = strlen((const char *)src);
v2 = v1 + 1;
v3 = v1;
v4 = malloc(v1 + 1);
if ( v4 )
return memcpy(v4, src, v2);
gupout(1LL, "xstrdup of %d failed", v3);
return (void *)func5();
}

original_code:
char *xstrdup(const char *str)
{
    char *res;
    res = malloc(strlen(str) + 1);
    if (!res)
 gupout(1, "xstrdup of %d failed", strlen(str));
    return strcpy(res, str);
}

canonical_original_code:
char *xstrdup(char *str)
{
    char *res;
    res = malloc(strlen(str) + 1);
    if (!res)
 gupout(1, "xstrdup of %d failed", strlen(str));
    return strcpy(res, str);
}

variable_types:
str
char *

variable_types:
res
char *


vlogit

decompiled_code:
int __fastcall vlogit(char a1, const char *a2, const char *a3, __m128i *a4)
{
FILE *v7; // rax
FILE *v8; // rdi
struct tm *v9; // rax
time_t v11; // [rsp+0h] [rbp-B8h] BYREF
__m128i v12; // [rsp+8h] [rbp-B0h] BYREF
FILE *v13; // [rsp+18h] [rbp-A0h]
char s[152]; // [rsp+20h] [rbp-98h] BYREF

v12 = _mm_loadu_si128(a4);
v7 = (FILE *)a4[1].m128i_i64[0];
v13 = v7;
if ( (a1 & 4) != 0 )
{
time(&v11);
v9 = localtime(&v11);
LODWORD(v7) = strftime(s, 0x64uLL, "%d %h %Y %T: ", v9);
}
if ( log_fp && (a1 & 1) != 0 )
{
log_line(log_fp, a1, s, a2, a3, a4);
LODWORD(v7) = fflush(log_fp);
}
if ( (a1 & 2) != 0 )
{
v8 = mail_fp;
if ( mail_fp
|| (LODWORD(v7) = tried_mail_open_0) == 0
&& (tried_mail_open_0 = 1, v7 = (FILE *)mail_open(1LL, 0LL, 0LL, 0LL), mail_fp = v7, (v8 = v7) != 0LL) )
{
LODWORD(v7) = log_line(v8, a1, s, a2, a3, &v12);
}
}
return (int)v7;
}

canonical_decompiled_code:
int __fastcall func1(char a1, const char *a2, const char *a3, __m128i *a4)
{
FILE *v7; // rax
FILE *v8; // rdi
struct tm *v9; // rax
time_t v11; // [rsp+0h] [rbp-B8h] BYREF
__m128i v12; // [rsp+8h] [rbp-B0h] BYREF
FILE *v13; // [rsp+18h] [rbp-A0h]
char s[152]; // [rsp+20h] [rbp-98h] BYREF

v12 = _mm_loadu_si128(a4);
v7 = (FILE *)a4[1].m128i_i64[0];
v13 = v7;
if ( (a1 & 4) != 0 )
{
time(&v11);
v9 = localtime(&v11);
LODWORD(v7) = strftime(s, 0x64uLL, "%d %h %Y %T: ", v9);
}
if ( log_fp && (a1 & 1) != 0 )
{
func0(log_fp, a1, s, a2, a3, a4);
LODWORD(v7) = fflush(log_fp);
}
if ( (a1 & 2) != 0 )
{
v8 = mail_fp;
if ( mail_fp
|| (LODWORD(v7) = tried_mail_open_0) == 0
&& (tried_mail_open_0 = 1, v7 = (FILE *)mail_open(1LL, 0LL, 0LL, 0LL), mail_fp = v7, (v8 = v7) != 0LL) )
{
LODWORD(v7) = func0(v8, a1, s, a2, a3, &v12);
}
}
return (int)v7;
}

original_code:
void vlogit(int lflags, const char *prefix, const char *log_msg, va_list AP)
{
    time_t secs;
    struct tm *tm;
    char stamp[100];
    va_list AP2;
    static int tried_mail_open = 0;
    __builtin_va_copy(AP2,AP);
    if (lflags & (1<<2)) {
 time(&secs);
 tm = localtime(&secs);
 strftime(stamp, sizeof(stamp), "%d %h %Y %T: ", tm);
    }
    if (log_fp && (lflags & (1<<0))) {
 log_line(log_fp, lflags, stamp, prefix, log_msg, AP);
 fflush(log_fp);
    }
    if (lflags & (1<<1)) {
 if (!mail_fp && !tried_mail_open) {
     tried_mail_open = 1;
     mail_fp = mail_open(1, ((void *)0), ((void *)0), ((void *)0));
 }
 if (mail_fp)
     log_line(mail_fp, lflags, stamp, prefix, log_msg, AP2);
    }
    __builtin_va_end(AP2);
}

canonical_original_code:
void vlogit(int lflags, char *prefix, char *log_msg, __builtin_va_list AP)
{
    long secs;
    struct tm *tm;
    char stamp[100];
    __builtin_va_list AP2;
    static int tried_mail_open = 0;
    __builtin_va_copy(AP2,AP);
    if (lflags & (1<<2)) {
 time(&secs);
 tm = localtime(&secs);
 strftime(stamp, sizeof(stamp), "%d %h %Y %T: ", tm);
    }
    if (log_fp && (lflags & (1<<0))) {
 log_line(log_fp, lflags, stamp, prefix, log_msg, AP);
 fflush(log_fp);
    }
    if (lflags & (1<<1)) {
 if (!mail_fp && !tried_mail_open) {
     tried_mail_open = 1;
     mail_fp = mail_open(1, ((void *)0), ((void *)0), ((void *)0));
 }
 if (mail_fp)
     log_line(mail_fp, lflags, stamp, prefix, log_msg, AP2);
    }
    __builtin_va_end(AP2);
}

variable_types: lflags int

variable_types:
prefix
char *

variable_types: secs long

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

variable_types:
stamp
char [100]


logit

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

va_start(va, a2);
return vlogit(a1, 0LL, a2, (__m128i *)va);
}

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

va_start(va, a2);
return func1(a1, 0LL, a2, (__m128i *)va);
}

original_code:
void logit(int lflags, const char *log_msg, ...)
{
    va_list ap;
    __builtin_va_start(ap,log_msg);
    vlogit(lflags, ((void *)0), log_msg, ap);
    __builtin_va_end(ap);
}

canonical_original_code:
void logit(int lflags, char *log_msg, ...)
{
    __builtin_va_list ap;
    __builtin_va_start(ap,log_msg);
    vlogit(lflags, ((void *)0), log_msg, ap);
    __builtin_va_end(ap);
}


CrackFrom

original_code:
int CrackFrom(char *addr, char *name, char *p)
{
    register char *adp;
    register char *bp;
    register char *ap;
    register char *cp = ((void *)0);
    register char CurrChar;
    register int comment;
    register int address;
    register int addrfound;
    register int QuoteNext;
    register int InQuotes;
    char *xp;
    char comm[1024];
    char commbuf[1024];
    char addrbuf[1024];
    *name = '\0';
    *addr = '\0';
    if (p == ((void *)0))
 return 0;
    while (*p && ((*__ctype_b_loc ())[(int) ((*p))] & (unsigned short int) _ISspace))
 p++;
    comm[0] = '\0';
    commbuf[0] = '\0';
    addrbuf[0] = '\0';
    adp = addrbuf;
    comment = 0;
    addrfound = 0;
    address = 0;
    QuoteNext = 0;
    InQuotes = 0;
    for (; *p; p++) {
 CurrChar = (*p & 0x007F) | QuoteNext;
 QuoteNext = CurrChar == '\\' ? 0x0080 : 0;
 if (!comment && CurrChar == '"')
     InQuotes = InQuotes ? 0 : 0x0080;
 else
     CurrChar |= InQuotes;
 switch (CurrChar) {
 case '(':
     if (comment == 0) {
  cp = commbuf;
  *cp = '\0';
     }
     comment++;
     break;
 case ')':
     if (comment > 0 && --comment == 0) {
  *cp = '\0';
  xp = comm;
  if (*xp) {
      while (*xp)
   xp++;
      *xp++ = ',';
      *xp++ = ' ';
  }
  for (cp = &commbuf[1]; (*xp++ = *cp) != '\0'; cp++)
      continue;
  cp = ((void *)0);
  continue;
     }
     break;
 case '<':
     if (address)
  return 0;
     if (!comment) {
  address++;
  *adp = '\0';
  adp = addr;
     }
     break;
 case '>':
     if (!comment && address) {
  address--;
  addrfound++;
  for (*adp = '\0', adp = addrbuf; *adp;)
      adp++;
  continue;
     }
     break;
 }
 if (comment)
     *cp++ = CurrChar;
 else if (!address || CurrChar != '<')
     *adp++ = CurrChar;
 if (*p == '\0')
     break;
    }
    *adp++ = '\0';
    if (addrfound)
 for (ap = name, xp = addrbuf; (*ap++ = (*xp & 0x007F)) != 0; xp++)
     continue;
    else {
 for (cp = addr, xp = addrbuf; (*cp++ = *xp) != 0; xp++)
     continue;
 *name = '\0';
    }
    if (*comm) {
 ap = name;
 if (*ap) {
     while (*ap)
  ap++;
     *ap++ = ',';
     *ap++ = ' ';
 }
 for (xp = comm; (*ap = (*xp++ & 0x007F)) != 0; ap++)
     continue;
    }
    for (cp = addr; ((*__ctype_b_loc ())[(int) ((*cp))] & (unsigned short int) _ISspace); cp++)
 continue;
    for (xp = addr; (*xp = *cp++) != 0;)
 xp++;
    while (*addr && ((*__ctype_b_loc ())[(int) ((*--xp))] & (unsigned short int) _ISspace))
 *xp = '\0';
    for (ap = name, bp = name; ((*__ctype_b_loc ())[(int) ((*bp))] & (unsigned short int) _ISspace) || ((*bp) == '"' || (*bp) == '(' || (*bp) == ')' || (*bp) == '\\'); bp++)
 continue;
    while ((*ap = *bp++) != '\0')
 if (!((*ap) == '"' || (*ap) == '(' || (*ap) == ')' || (*ap) == '\\'))
     ap++;
    while (*name && ((*__ctype_b_loc ())[(int) ((*--ap))] & (unsigned short int) _ISspace))
 *ap = '\0';
    return 1;
}

canonical_original_code:
int CrackFrom(char *addr, char *name, char *p)
{
    register char *adp;
    register char *bp;
    register char *ap;
    register char *cp = ((void *)0);
    register char CurrChar;
    register int comment;
    register int address;
    register int addrfound;
    register int QuoteNext;
    register int InQuotes;
    char *xp;
    char comm[1024];
    char commbuf[1024];
    char addrbuf[1024];
    *name = '\0';
    *addr = '\0';
    if (p == ((void *)0))
 return 0;
    while (*p && ((*__ctype_b_loc ())[(int) ((*p))] & (unsigned short) _ISspace))
 p++;
    comm[0] = '\0';
    commbuf[0] = '\0';
    addrbuf[0] = '\0';
    adp = addrbuf;
    comment = 0;
    addrfound = 0;
    address = 0;
    QuoteNext = 0;
    InQuotes = 0;
    for (; *p; p++) {
 CurrChar = (*p & 0x007F) | QuoteNext;
 QuoteNext = CurrChar == '\\' ? 0x0080 : 0;
 if (!comment && CurrChar == '"')
     InQuotes = InQuotes ? 0 : 0x0080;
 else
     CurrChar |= InQuotes;
 switch (CurrChar) {
 case '(':
     if (comment == 0) {
  cp = commbuf;
  *cp = '\0';
     }
     comment++;
     break;
 case ')':
     if (comment > 0 && --comment == 0) {
  *cp = '\0';
  xp = comm;
  if (*xp) {
      while (*xp)
   xp++;
      *xp++ = ',';
      *xp++ = ' ';
  }
  for (cp = &commbuf[1]; (*xp++ = *cp) != '\0'; cp++)
      continue;
  cp = ((void *)0);
  continue;
     }
     break;
 case '<':
     if (address)
  return 0;
     if (!comment) {
  address++;
  *adp = '\0';
  adp = addr;
     }
     break;
 case '>':
     if (!comment && address) {
  address--;
  addrfound++;
  for (*adp = '\0', adp = addrbuf; *adp;)
      adp++;
  continue;
     }
     break;
 }
 if (comment)
     *cp++ = CurrChar;
 else if (!address || CurrChar != '<')
     *adp++ = CurrChar;
 if (*p == '\0')
     break;
    }
    *adp++ = '\0';
    if (addrfound)
 for (ap = name, xp = addrbuf; (*ap++ = (*xp & 0x007F)) != 0; xp++)
     continue;
    else {
 for (cp = addr, xp = addrbuf; (*cp++ = *xp) != 0; xp++)
     continue;
 *name = '\0';
    }
    if (*comm) {
 ap = name;
 if (*ap) {
     while (*ap)
  ap++;
     *ap++ = ',';
     *ap++ = ' ';
 }
 for (xp = comm; (*ap = (*xp++ & 0x007F)) != 0; ap++)
     continue;
    }
    for (cp = addr; ((*__ctype_b_loc ())[(int) ((*cp))] & (unsigned short) _ISspace); cp++)
 continue;
    for (xp = addr; (*xp = *cp++) != 0;)
 xp++;
    while (*addr && ((*__ctype_b_loc ())[(int) ((*--xp))] & (unsigned short) _ISspace))
 *xp = '\0';
    for (ap = name, bp = name; ((*__ctype_b_loc ())[(int) ((*bp))] & (unsigned short) _ISspace) || ((*bp) == '"' || (*bp) == '(' || (*bp) == ')' || (*bp) == '\\'); bp++)
 continue;
    while ((*ap = *bp++) != '\0')
 if (!((*ap) == '"' || (*ap) == '(' || (*ap) == ')' || (*ap) == '\\'))
     ap++;
    while (*name && ((*__ctype_b_loc ())[(int) ((*--ap))] & (unsigned short) _ISspace))
 *ap = '\0';
    return 1;
}

variable_types:
addr
char *

variable_types:
name
char *

variable_types:
p
char *

variable_types:
adp
char *

variable_types:
bp
char *

variable_types:
ap
char *

variable_types:
cp
char *

variable_types: CurrChar char

variable_types: comment int

variable_types: address int

variable_types: addrfound int

variable_types: QuoteNext int

variable_types: InQuotes int

variable_types:
xp
char *

variable_types:
comm
char [1024]

variable_types:
commbuf
char [1024]

variable_types:
addrbuf
char [1024]


decompiled_code:
__int64 __fastcall mat_compare(const void *a1, const void *a2)
{
__int64 v2; // r11
_BYTE *v3; // r8
char *v4; // rdi
int v5; // edx
int v6; // eax
__int64 v7; // r9
__int64 v8; // rcx

v2 = *(_QWORD *)a1;
v3 = *(_BYTE **)(*(_QWORD *)a2 + 8LL);
v4 = *(char **)(*(_QWORD *)a1 + 8LL);
v5 = (char)*v3;
v6 = *v4;
if ( !*v3 || !(_BYTE)v6 )
return (unsigned int)(v6 - v5);
v7 = 0x6000000200001LL;
v8 = 1LL;
while ( ((unsigned __int8)(v6 - 42) > 0x32u || !_bittest64(&v7, (unsigned int)(v6 - 42)))
&& ((unsigned __int8)(v5 - 42) > 0x32u || !_bittest64(&v7, (unsigned int)(v5 - 42))) )
{
if ( (_BYTE)v5 == (_BYTE)v6 )
{
v6 = v4[v8];
v5 = (char)v3[v8++];
if ( (_BYTE)v6 )
{
if ( (_BYTE)v5 )
continue;
}
}
return (unsigned int)(v6 - v5);
}
return (unsigned int)(*(_DWORD *)(v2 + 24) - *(_DWORD *)(*(_QWORD *)a2 + 24LL));
}

variable_types: struct group_s { struct group_s *next; char *name; char *desc; int order; union { int not; struct tag_s { struct tag_s *next; struct group_s *group; } *tag; } u; } **


decompiled_code:
__int64 __fastcall sort_groups(void *ptr)
{
size_t v1; // r13
_QWORD *v2; // rax
_QWORD *v3; // rbp
__int64 *v4; // rax
__int64 v5; // rdx
__int64 v6; // r13
__int64 v7; // rbx
__int64 v8; // rsi

v1 = *((unsigned int *)ptr + 4);
v2 = calloc(v1, 8uLL);
if ( !v2 )
{
gupout(1LL, "Malloc of sort table failed");
JUMPOUT(0x13FLL);
}
v3 = v2;
v4 = *(__int64 **)ptr;
if ( *(_QWORD *)ptr )
{
v5 = 0LL;
do
{
*((_DWORD *)v4 + 6) = v5;
v3[v5] = v4;
v4 = (__int64 *)*v4;
++v5;
}
while ( v4 );
}
qsort(v3, v1, 8uLL, (__compar_fn_t)mat_compare);
v6 = create_list();
if ( *((_DWORD *)ptr + 4) )
{
v7 = 0LL;
do
{
v8 = v3[v7++];
add_group(v6, v8);
}
while ( *((_DWORD *)ptr + 4) > (unsigned int)v7 );
}
free(v3);
free(ptr);
return v6;
}

canonical_decompiled_code:
__int64 __fastcall func1(void *ptr)
{
size_t v1; // r13
_QWORD *v2; // rax
_QWORD *v3; // rbp
__int64 *v4; // rax
__int64 v5; // rdx
__int64 v6; // r13
__int64 v7; // rbx
__int64 v8; // rsi

v1 = *((unsigned int *)ptr + 4);
v2 = calloc(v1, 8uLL);
if ( !v2 )
{
gupout(1LL, "Malloc of sort table failed");
JUMPOUT(0x13FLL);
}
v3 = v2;
v4 = *(__int64 **)ptr;
if ( *(_QWORD *)ptr )
{
v5 = 0LL;
do
{
*((_DWORD *)v4 + 6) = v5;
v3[v5] = v4;
v4 = (__int64 *)*v4;
++v5;
}
while ( v4 );
}
qsort(v3, v1, 8uLL, (__compar_fn_t)mat_compare);
v6 = create_list();
if ( *((_DWORD *)ptr + 4) )
{
v7 = 0LL;
do
{
v8 = v3[v7++];
add_group(v6, v8);
}
while ( *((_DWORD *)ptr + 4) > (unsigned int)v7 );
}
free(v3);
free(ptr);
return v6;
}

original_code:
extern LIST *sort_groups(LIST *glist)
{
    LIST *slist;
    GROUP **stab;
    GROUP *gp;
    int st_ix;
    stab = calloc((glist->length), sizeof(GROUP *));
    if (!stab)
 gupout(1, "Malloc of sort table failed");
    st_ix = 0;
    if (glist) for (gp = glist->head; gp; gp = gp->next) {
 gp->order = st_ix;
 stab[st_ix++] = gp;
    }
    qsort(stab, (glist->length), sizeof(GROUP *), mat_compare);
    slist = create_list();
    for (st_ix = 0; st_ix < (glist->length); st_ix++)
 add_group(slist, stab[st_ix]);
    free(stab);
    free(glist);
    return slist;
}

canonical_original_code:
extern struct LIST *sort_groups(struct LIST *glist)
{
    struct LIST *slist;
    struct group_s **stab;
    struct group_s *gp;
    int st_ix;
    stab = calloc((glist->length), sizeof(struct group_s *));
    if (!stab)
 gupout(1, "Malloc of sort table failed");
    st_ix = 0;
    if (glist) for (gp = glist->head; gp; gp = gp->next) {
 gp->order = st_ix;
 stab[st_ix++] = gp;
    }
    qsort(stab, (glist->length), sizeof(struct group_s *), mat_compare);
    slist = create_list();
    for (st_ix = 0; st_ix < (glist->length); st_ix++)
 add_group(slist, stab[st_ix]);
    free(stab);
    free(glist);
    return slist;
}

variable_types:
glist
struct LIST *

variable_types: struct LIST { struct group_s { struct group_s *next; char *name; char *desc; int order; union { int not; struct tag_s { struct tag_s *next; struct group_s *group; } *tag; } u; } *head; struct group_s *tail; unsigned int length; } *


lockit

decompiled_code:
__int64 lockit()
{
int v0; // eax
__int64 result; // rax
int v2; // ebp

v0 = open(".", 0);
if ( v0 < 0 )
return 0LL;
v2 = v0;
if ( flock(v0, 2) )
{
logit(1LL, "WARNING: flock failed");
close(v2);
result = 0LL;
}
else
{
locked = 1;
result = 1LL;
}
return result;
}

canonical_decompiled_code:
__int64 func0()
{
int v0; // eax
__int64 result; // rax
int v2; // ebp

v0 = open(".", 0);
if ( v0 < 0 )
return 0LL;
v2 = v0;
if ( flock(v0, 2) )
{
logit(1LL, "WARNING: flock failed");
close(v2);
result = 0LL;
}
else
{
locked = 1;
result = 1LL;
}
return result;
}

original_code:
int lockit(void)
{
    int fd;
    if ((fd = open(".", 00)) >= 0) {
 if (flock(fd, 2) == 0) {
     locked = 1;
     return 1;
 }
 logit((1<<0), "WARNING: flock failed");
 close(fd);
    }
    return 0;
}

canonical_original_code:
int lockit()
{
    int fd;
    if ((fd = open(".", 00)) >= 0) {
 if (flock(fd, 2) == 0) {
     locked = 1;
     return 1;
 }
 logit((1<<0), "WARNING: flock failed");
 close(fd);
    }
    return 0;
}

variable_types: fd int


unlockit

decompiled_code:
int unlockit()
{
int result; // eax
int v1; // ebp

result = locked;
if ( locked )
{
locked = 0;
result = open(".", 0);
v1 = result;
if ( result >= 0 )
{
if ( flock(result, 8) )
logit(1LL, "WARNING: unflock failed");
result = close(v1);
}
}
return result;
}

canonical_decompiled_code:
int func1()
{
int result; // eax
int v1; // ebp

result = locked;
if ( locked )
{
locked = 0;
result = open(".", 0);
v1 = result;
if ( result >= 0 )
{
if ( flock(result, 8) )
logit(1LL, "WARNING: unflock failed");
result = close(v1);
}
}
return result;
}

original_code:
void unlockit(void)
{
    if (locked) {
 int fd;
 locked = 0;
 if ((fd = open(".", 00)) >= 0) {
     if (flock(fd, 8) == 0) {
  close(fd);
  return;
     }
     logit((1<<0), "WARNING: unflock failed");
     close(fd);
 }
    }
}

canonical_original_code:
void unlockit()
{
    if (locked) {
 int fd;
 locked = 0;
 if ((fd = open(".", 00)) >= 0) {
     if (flock(fd, 8) == 0) {
  close(fd);
  return;
     }
     logit((1<<0), "WARNING: unflock failed");
     close(fd);
 }
    }
}


help

decompiled_code:
__int64 help()
{
void **v0; // rbx

if ( !hlist )
return 0LL;
v0 = &hlist;
do
{
++v0;
logit(2LL);
}
while ( *v0 );
return 0LL;
}

canonical_decompiled_code:
__int64 func0()
{
void **v0; // rbx

if ( !hlist )
return 0LL;
v0 = &hlist;
do
{
++v0;
logit(2LL);
}
while ( *v0 );
return 0LL;
}

original_code:
int help(const char **tokens)
{
    const char **hp;
    for (hp = hlist; *hp; hp++)
 logit((1<<1), *hp);
    return 0;
}

canonical_original_code:
int help(char **tokens)
{
    char **hp;
    for (hp = hlist; *hp; hp++)
 logit((1<<1), *hp);
    return 0;
}

variable_types:
tokens
char **

variable_types:
hp
char **


decompiled_code:
int load_newsgroups()
{
__int64 v0; // rax
int v1; // eax
int v2; // ebp
int v3; // ebx
char *v4; // rax
const char *v5; // r12
__int64 **v6; // r13
char *v7; // rax
char *v8; // rbp
__int64 *v9; // rbx
__int64 v10; // rdx
struct stat v12; // [rsp-30h] [rbp-B8h] BYREF

newsgroups_loaded = 1;
if ( newsgroups_path && *newsgroups_path )
{
v1 = open(newsgroups_path, 0);
v2 = v1;
if ( v1 < 0 )
{
LODWORD(v0) = logit(3LL, "WARNING: Could not open newsgroups file '%s'", newsgroups_path);
}
else if ( fstat(v1, &v12) < 0 )
{
LODWORD(v0) = logit(3LL, "WARNING: Could not stat newsgroups file '%s'", newsgroups_path);
}
else
{
v3 = v12.st_size;
v4 = (char *)malloc(v12.st_size + 1);
v5 = v4;
if ( v4 )
{
LODWORD(v0) = read(v2, v4, v3);
if ( (int)v0 == v12.st_size )
{
v5[(int)v0] = 0;
if ( *v5 )
{
v6 = 0LL;
do
{
v7 = strchr(v5, 10);
v8 = v7;
if ( v7 )
*v7 = 0;
else
logit(1LL, "WARNING: premature end of newsgroups file");
v0 = (__int64)strchr(v5, 9);
v9 = (__int64 *)v0;
if ( v0 )
{
*(_BYTE *)v0 = 0;
v0 = (__int64)_ctype_b_loc();
do
{
v10 = *((char *)v9 + 1);
v9 = (__int64 *)((char *)v9 + 1);
}
while ( (*(_BYTE *)(*(_QWORD *)v0 + 2 * v10 + 1) & 0x20) != 0 );
if ( (_BYTE)v10 )
{
if ( !v6 || (LODWORD(v0) = strcmp((const char *)v6[1], v5), (_DWORD)v0) )
{
LODWORD(v0) = active_list;
if ( active_list )
{
v6 = (__int64 **)*active_list;
if ( *active_list )
{
while ( 1 )
{
LODWORD(v0) = strcmp((const char *)v6[1], v5);
if ( !(_DWORD)v0 )
{
v0 = (__int64)v6[2];
if ( !*(_BYTE *)v0 )
break;
}
v6 = (__int64 **)*v6;
if ( !v6 )
goto LABEL_10;
}
v6[2] = v9;
v6 = (__int64 **)*v6;
}
}
}
else
{
v6[2] = v9;
}
}
}
LABEL_10:
v5 = v8 + 1;
}
while ( v8[1] );
}
}
else
{
LODWORD(v0) = logit(3LL, "WARNING: Error reading newsgroups");
}
}
else
{
LODWORD(v0) = logit(3LL, "WARNING: Could not malloc space for newsgroups");
}
}
}
else
{
LODWORD(v0) = logit(3LL, "WARNING: No newsgroups file defined - needed for descriptions");
}
return v0;
}

canonical_decompiled_code:
int func0()
{
__int64 v0; // rax
int v1; // eax
int v2; // ebp
int v3; // ebx
char *v4; // rax
const char *v5; // r12
__int64 **v6; // r13
char *v7; // rax
char *v8; // rbp
__int64 *v9; // rbx
__int64 v10; // rdx
struct stat v12; // [rsp-30h] [rbp-B8h] BYREF

newsgroups_loaded = 1;
if ( newsgroups_path && *newsgroups_path )
{
v1 = open(newsgroups_path, 0);
v2 = v1;
if ( v1 < 0 )
{
LODWORD(v0) = logit(3LL, "WARNING: Could not open newsgroups file '%s'", newsgroups_path);
}
else if ( fstat(v1, &v12) < 0 )
{
LODWORD(v0) = logit(3LL, "WARNING: Could not stat newsgroups file '%s'", newsgroups_path);
}
else
{
v3 = v12.st_size;
v4 = (char *)malloc(v12.st_size + 1);
v5 = v4;
if ( v4 )
{
LODWORD(v0) = read(v2, v4, v3);
if ( (int)v0 == v12.st_size )
{
v5[(int)v0] = 0;
if ( *v5 )
{
v6 = 0LL;
do
{
v7 = strchr(v5, 10);
v8 = v7;
if ( v7 )
*v7 = 0;
else
logit(1LL, "WARNING: premature end of newsgroups file");
v0 = (__int64)strchr(v5, 9);
v9 = (__int64 *)v0;
if ( v0 )
{
*(_BYTE *)v0 = 0;
v0 = (__int64)_ctype_b_loc();
do
{
v10 = *((char *)v9 + 1);
v9 = (__int64 *)((char *)v9 + 1);
}
while ( (*(_BYTE *)(*(_QWORD *)v0 + 2 * v10 + 1) & 0x20) != 0 );
if ( (_BYTE)v10 )
{
if ( !v6 || (LODWORD(v0) = strcmp((const char *)v6[1], v5), (_DWORD)v0) )
{
LODWORD(v0) = active_list;
if ( active_list )
{
v6 = (__int64 **)*active_list;
if ( *active_list )
{
while ( 1 )
{
LODWORD(v0) = strcmp((const char *)v6[1], v5);
if ( !(_DWORD)v0 )
{
v0 = (__int64)v6[2];
if ( !*(_BYTE *)v0 )
break;
}
v6 = (__int64 **)*v6;
if ( !v6 )
goto LABEL_10;
}
v6[2] = v9;
v6 = (__int64 **)*v6;
}
}
}
else
{
v6[2] = v9;
}
}
}
LABEL_10:
v5 = v8 + 1;
}
while ( v8[1] );
}
}
else
{
LODWORD(v0) = logit(3LL, "WARNING: Error reading newsgroups");
}
}
else
{
LODWORD(v0) = logit(3LL, "WARNING: Could not malloc space for newsgroups");
}
}
}
else
{
LODWORD(v0) = logit(3LL, "WARNING: No newsgroups file defined - needed for descriptions");
}
return v0;
}

original_code:
static void load_newsgroups(void)
{
    int fd;
    struct stat sb;
    char *desc;
    int length;
    GROUP *gp = ((void *)0);
    newsgroups_loaded = 1;
    if (!newsgroups_path || !*newsgroups_path) {
 logit(((1<<0) | (1<<1)),
     "WARNING: No newsgroups file defined - needed for descriptions");
 return;
    }
    if ((fd = open(newsgroups_path, 00)) < 0) {
 logit(((1<<0) | (1<<1)), "WARNING: Could not open newsgroups file '%s'",
  newsgroups_path);
 return;
    }
    if (fstat(fd, &sb) < 0) {
 logit(((1<<0) | (1<<1)), "WARNING: Could not stat newsgroups file '%s'",
  newsgroups_path);
 return;
    }
    desc = malloc(sb.st_size + 1);
    if (!desc) {
 logit(((1<<0) | (1<<1)), "WARNING: Could not malloc space for newsgroups");
 return;
    }
    length = read(fd, desc, (int) sb.st_size);
    if (length != sb.st_size) {
 logit(((1<<0) | (1<<1)), "WARNING: Error reading newsgroups");
 return;
    }
    desc[length] = 0;
    while (*desc) {
 char *eoln, *p;
 if ((eoln = strchr(desc, '\n')))
     *eoln = 0;
 else
     logit((1<<0), "WARNING: premature end of newsgroups file");
 if ((p = strchr(desc, '\t'))) {
     *p = 0;
     while (((*__ctype_b_loc ())[(int) ((*++p))] & (unsigned short int) _ISspace));
     if (*p) {
  if (gp && !strcmp(gp->name, desc))
      gp->desc = p;
  else {
      if (active_list) for (gp = active_list->head; gp; gp = gp->next) {
   if (!strcmp(gp->name, desc) && !*gp->desc) {
       gp->desc = p;
       gp = gp->next;
       break;
   }
      }
  }
     }
 }
 desc = eoln + 1;
    }
}

canonical_original_code:
static void load_newsgroups()
{
    int fd;
    struct stat sb;
    char *desc;
    int length;
    struct group_s *gp = ((void *)0);
    newsgroups_loaded = 1;
    if (!newsgroups_path || !*newsgroups_path) {
 logit(((1<<0) | (1<<1)),
     "WARNING: No newsgroups file defined - needed for descriptions");
 return;
    }
    if ((fd = open(newsgroups_path, 00)) < 0) {
 logit(((1<<0) | (1<<1)), "WARNING: Could not open newsgroups file '%s'",
  newsgroups_path);
 return;
    }
    if (fstat(fd, &sb) < 0) {
 logit(((1<<0) | (1<<1)), "WARNING: Could not stat newsgroups file '%s'",
  newsgroups_path);
 return;
    }
    desc = malloc(sb.st_size + 1);
    if (!desc) {
 logit(((1<<0) | (1<<1)), "WARNING: Could not malloc space for newsgroups");
 return;
    }
    length = read(fd, desc, (int) sb.st_size);
    if (length != sb.st_size) {
 logit(((1<<0) | (1<<1)), "WARNING: Error reading newsgroups");
 return;
    }
    desc[length] = 0;
    while (*desc) {
 char *eoln; char *p;
 if ((eoln = strchr(desc, '\n')))
     *eoln = 0;
 else
     logit((1<<0), "WARNING: premature end of newsgroups file");
 if ((p = strchr(desc, '\t'))) {
     *p = 0;
     while (((*__ctype_b_loc ())[(int) ((*++p))] & (unsigned short) _ISspace));
     if (*p) {
  if (gp && !strcmp(gp->name, desc))
      gp->desc = p;
  else {
      if (active_list) for (gp = active_list->head; gp; gp = gp->next) {
   if (!strcmp(gp->name, desc) && !*gp->desc) {
       gp->desc = p;
       gp = gp->next;
       break;
   }
      }
  }
     }
 }
 desc = eoln + 1;
    }
}

variable_types: struct stat { unsigned long st_dev; unsigned long st_ino; unsigned long st_nlink; unsigned int st_mode; unsigned int st_uid; unsigned int st_gid; int __pad0; unsigned long st_rdev; long st_size; long st_blksize; long st_blocks; struct timespec { long tv_sec; long tv_nsec; } st_atim; struct timespec st_mtim; struct timespec st_ctim; long __glibc_reserved[3]; }

variable_types:
desc
char *

variable_types: length int

variable_types: struct group_s { struct group_s *next; char *name; char *desc; int order; union { int not; struct tag_s { struct tag_s *next; struct group_s *group; } *tag; } u; } *

variable_types:
eoln
char *

variable_types:
p
char *

user_defined_types: struct stat { unsigned long st_dev; unsigned long st_ino; unsigned long st_nlink; unsigned int st_mode; unsigned int st_uid; unsigned int st_gid; int __pad0; unsigned long st_rdev; long st_size; long st_blksize; long st_blocks; struct timespec st_atim; struct timespec st_mtim; struct timespec st_ctim; long __glibc_reserved[3]; }


prune

original_code:
void prune(LIST *active_l, LIST *group_l)
{
    GROUP *gp;
    GROUP *ap;
    int groupcount;
    groupcount = 0;
    if (active_l) for (ap = active_l->head; ap; ap = ap->next) {
 ap->u.tag = ((void *)0);
 if (group_l) for (gp = group_l->head; gp; gp = gp->next) {
     if (wildmat(ap->name, gp->name)) {
  TAG *t = (TAG *) malloc(sizeof(TAG));
  if (!t) {
      logit(((1<<0) | (1<<1)), "WARNING: insufficient memory to prune!");
      return;
  }
  t->group = gp;
  t->next = ap->u.tag;
  ap->u.tag = t;
     }
 }
 if (ap && ap->u.tag && ap->u.tag->group)
     if (ap->u.tag->group->u.not == 0)
  groupcount++;
    }
    if (groupcount > maxgroups)
 gupout(1, "Too many groups (%d, only %d allowed)",
  groupcount, maxgroups);
    if (group_l) for (gp = group_l->head; gp; gp = gp->next) {
 int effect = 0;
 if (active_l) for (ap = active_l->head; ap; ap = ap->next) {
     TAG *tag = ap->u.tag;
     if (tag && tag->group == gp && ((!tag->next && !gp->u.not) ||
  (tag->next && tag->next->group->u.not != gp->u.not))) {
  effect = 1;
  break;
     }
 }
 if (!effect && gp->u.not != 2) {
     if (active_l) for (ap = active_l->head; ap; ap = ap->next) {
  TAG *t, *prev;
  for (prev = ((void *)0), t = ap->u.tag; t; prev = t, t = t->next) {
      if (t->group == gp) {
   if (!prev)
       ap->u.tag = t->next;
   else
       prev->next = t->next;
   free(t);
   break;
      }
  }
     }
     remove_group(group_l, gp);
     logit(((1<<0) | (1<<1)), "PRUNED: %s %s subsumed",
      gp->u.not ? "exclude" : "include", gp->name);
 }
    }
}

canonical_original_code:
void prune(struct LIST *active_l, struct LIST *group_l)
{
    struct group_s *gp;
    struct group_s *ap;
    int groupcount;
    groupcount = 0;
    if (active_l) for (ap = active_l->head; ap; ap = ap->next) {
 ap->u.tag = ((void *)0);
 if (group_l) for (gp = group_l->head; gp; gp = gp->next) {
     if (wildmat(ap->name, gp->name)) {
  struct tag_s *t = (TAG *) malloc(sizeof(TAG));
  if (!t) {
      logit(((1<<0) | (1<<1)), "WARNING: insufficient memory to prune!");
      return;
  }
  t->group = gp;
  t->next = ap->u.tag;
  ap->u.tag = t;
     }
 }
 if (ap && ap->u.tag && ap->u.tag->group)
     if (ap->u.tag->group->u.not == 0)
  groupcount++;
    }
    if (groupcount > maxgroups)
 gupout(1, "Too many groups (%d, only %d allowed)",
  groupcount, maxgroups);
    if (group_l) for (gp = group_l->head; gp; gp = gp->next) {
 int effect = 0;
 if (active_l) for (ap = active_l->head; ap; ap = ap->next) {
     struct tag_s *tag = ap->u.tag;
     if (tag && tag->group == gp && ((!tag->next && !gp->u.not) ||
  (tag->next && tag->next->group->u.not != gp->u.not))) {
  effect = 1;
  break;
     }
 }
 if (!effect && gp->u.not != 2) {
     if (active_l) for (ap = active_l->head; ap; ap = ap->next) {
  struct tag_s *t; struct tag_s *prev;
  for (prev = ((void *)0), t = ap->u.tag; t; prev = t, t = t->next) {
      if (t->group == gp) {
   if (!prev)
       ap->u.tag = t->next;
   else
       prev->next = t->next;
   free(t);
   break;
      }
  }
     }
     remove_group(group_l, gp);
     logit(((1<<0) | (1<<1)), "PRUNED: %s %s subsumed",
      gp->u.not ? "exclude" : "include", gp->name);
 }
    }
}

variable_types: groupcount int

variable_types: struct tag_s { struct tag_s *next; struct group_s { struct group_s *next; char *name; char *desc; int order; union { int not; struct tag_s *tag; } u; } *group; } *

variable_types: effect int


repo: rfhh/lily-contribs

decompiled_code:
int xly_repeat()
{
int result; // eax
__int64 v1; // r12
__int64 v2; // rbx
__int64 v3; // rdx

result = fwrite("Find repeats...\n", 1uLL, 0x10uLL, stderr);
if ( n_part > 0 )
{
v1 = 0LL;
do
{
fprintf(stderr, " ........ part %d, ", (unsigned int)v1);
if ( *(int *)(part + 16 * v1) > 0 )
{
v2 = 0LL;
do
{
fprintf(stderr, " staff %d", (unsigned int)v2);
v3 = 9 * v2++;
do_staff_repeat(*(_QWORD *)(part + 16 * v1 + 8) + 8 * v3);
}
while ( *(_DWORD *)(part + 16 * v1) > (int)v2 );
}
++v1;
result = fputc(10, stderr);
}
while ( n_part > (int)v1 );
}
return result;
}

canonical_decompiled_code:
int func2()
{
int result; // eax
__int64 v1; // r12
__int64 v2; // rbx
__int64 v3; // rdx

result = fwrite("Find repeats...\n", 1uLL, 0x10uLL, stderr);
if ( n_part > 0 )
{
v1 = 0LL;
do
{
fprintf(stderr, " ........ part %d, ", (unsigned int)v1);
if ( *(int *)(part + 16 * v1) > 0 )
{
v2 = 0LL;
do
{
fprintf(stderr, " staff %d", (unsigned int)v2);
v3 = 9 * v2++;
func1(*(_QWORD *)(part + 16 * v1 + 8) + 8 * v3);
}
while ( *(_DWORD *)(part + 16 * v1) > (int)v2 );
}
++v1;
result = fputc(10, stderr);
}
while ( n_part > (int)v1 );
}
return result;
}

original_code:
void
xly_repeat(void)
{
    int p;
    int f;
    fprintf(stderr, "Find repeats...\n");
    for (p = 0; p < n_part; p++) {
        fprintf(stderr, "      ........ part %d, ", p);
        for (f = 0; f < part[p].n_staff; f++) {
            fprintf(stderr, " staff %d", f);
            do_staff_repeat(&part[p].staff[f]);
        }
        fprintf(stderr, "\n");
    }
}

canonical_original_code:
void xly_repeat()
{
    int p;
    int f;
    fprintf(stderr, "Find repeats...\n");
    for (p = 0; p < n_part; p++) {
        fprintf(stderr, "      ........ part %d, ", p);
        for (f = 0; f < part[p].n_staff; f++) {
            fprintf(stderr, " staff %d", f);
            do_staff_repeat(&part[p].staff[f]);
        }
        fprintf(stderr, "\n");
    }
}

variable_types: p int

variable_types: f int


decompiled_code:
void xly_repeat_init()
{
;
}

canonical_decompiled_code:
void func3()
{
;
}

original_code:
void
xly_repeat_init(void)
{
}

canonical_original_code:
void xly_repeat_init()
{
}


decompiled_code:
void xly_repeat_end()
{
;
}

canonical_decompiled_code:
void func4()
{
;
}

original_code:
void
xly_repeat_end(void)
{
}

canonical_original_code:
void xly_repeat_end()
{
}


decompiled_code:
__int64 __fastcall mpq_dump(__int64 a1)
{
return mpq_printf(stderr, a1);
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1)
{
return func0(stderr, a1);
}

original_code:
int
mpq_dump(const mpq_t t)
{
    return mpq_printf(stderr, t);
}

canonical_original_code:
int mpq_dump(struct __mpq_struct t[1])
{
    return mpq_printf(stderr, t);
}

variable_types: struct __mpq_struct { struct __mpz_struct { int _mp_alloc; int _mp_size; unsigned long *_mp_d; } _mp_num; struct __mpz_struct _mp_den; } [1]

user_defined_types: struct __mpq_struct { struct __mpz_struct _mp_num; struct __mpz_struct _mp_den; }


decompiled_code:
const char *__fastcall SYMBOL_TYPE_string(unsigned int a1)
{
const char *result; // rax

result = "Unknown symbol";
if ( a1 <= 0x1B )
result = CSWTCH_20[a1];
return result;
}

canonical_decompiled_code:
const char *__fastcall func2(unsigned int a1)
{
const char *result; // rax

result = "Unknown symbol";
if ( a1 <= 0x1B )
result = CSWTCH_20[a1];
return result;
}

original_code:
const char *
SYMBOL_TYPE_string(symbol_type_t s)
{
    switch (s) {
    case SYM_ARPEGGIO: return "SYM_ARPEGGIO";
    case SYM_ARTICULATION: return "SYM_ARTICULATION";
    case SYM_BARLINE: return "SYM_BARLINE";
    case SYM_BAR_START: return "SYM_BAR_START";
    case SYM_CHORD: return "SYM_CHORD";
    case SYM_CLEF: return "SYM_CLEF";
    case SYM_DYNAMIC: return "SYM_DYNAMIC";
    case SYM_GLISSANDO: return "SYM_GLISSANDO";
    case SYM_HAIRPIN: return "SYM_HAIRPIN";
    case SYM_KEY_SIGN: return "SYM_KEY_SIGN";
    case SYM_MEASURE_NUMBERING: return "SYM_MEASURE_NUMBERING";
    case SYM_MIDI: return "SYM_MIDI";
    case SYM_NOTE: return "SYM_NOTE";
    case SYM_OTTAVA: return "SYM_OTTAVA";
    case SYM_ORNAMENT: return "SYM_ORNAMENT";
    case SYM_PARENTH: return "SYM_PARENTH";
    case SYM_PEDAL: return "SYM_PEDAL";
    case SYM_PORTAMENTO: return "SYM_PORTAMENTO";
    case SYM_REHEARSAL_MARK: return "SYM_REHEARSAL_MARK";
    case SYM_REPEAT: return "SYM_REPEAT";
    case SYM_STEM: return "SYM_STEM";
    case SYM_TEMPO: return "SYM_TEMPO";
    case SYM_TEXT: return "SYM_TEXT";
    case SYM_TIE: return "SYM_TIE";
    case SYM_TIME_SIGNATURE: return "SYM_TIME_SIGNATURE";
    case SYM_TREMOLO: return "SYM_TREMOLO";
    case SYM_TUPLET: return "SYM_TUPLET";
    case SYM_NUMBER: return "SYM_NUMBER";
    }
    return "Unknown symbol";
}

canonical_original_code:
char *SYMBOL_TYPE_string(enum SYMBOL_TYPE s)
{
    switch (s) {
    case SYM_ARPEGGIO: return "SYM_ARPEGGIO";
    case SYM_ARTICULATION: return "SYM_ARTICULATION";
    case SYM_BARLINE: return "SYM_BARLINE";
    case SYM_BAR_START: return "SYM_BAR_START";
    case SYM_CHORD: return "SYM_CHORD";
    case SYM_CLEF: return "SYM_CLEF";
    case SYM_DYNAMIC: return "SYM_DYNAMIC";
    case SYM_GLISSANDO: return "SYM_GLISSANDO";
    case SYM_HAIRPIN: return "SYM_HAIRPIN";
    case SYM_KEY_SIGN: return "SYM_KEY_SIGN";
    case SYM_MEASURE_NUMBERING: return "SYM_MEASURE_NUMBERING";
    case SYM_MIDI: return "SYM_MIDI";
    case SYM_NOTE: return "SYM_NOTE";
    case SYM_OTTAVA: return "SYM_OTTAVA";
    case SYM_ORNAMENT: return "SYM_ORNAMENT";
    case SYM_PARENTH: return "SYM_PARENTH";
    case SYM_PEDAL: return "SYM_PEDAL";
    case SYM_PORTAMENTO: return "SYM_PORTAMENTO";
    case SYM_REHEARSAL_MARK: return "SYM_REHEARSAL_MARK";
    case SYM_REPEAT: return "SYM_REPEAT";
    case SYM_STEM: return "SYM_STEM";
    case SYM_TEMPO: return "SYM_TEMPO";
    case SYM_TEXT: return "SYM_TEXT";
    case SYM_TIE: return "SYM_TIE";
    case SYM_TIME_SIGNATURE: return "SYM_TIME_SIGNATURE";
    case SYM_TREMOLO: return "SYM_TREMOLO";
    case SYM_TUPLET: return "SYM_TUPLET";
    case SYM_NUMBER: return "SYM_NUMBER";
    }
    return "Unknown symbol";
}

variable_types: enum SYMBOL_TYPE { SYM_ARPEGGIO=0, SYM_ARTICULATION=1, SYM_BARLINE=2, SYM_BAR_START=3, SYM_CHORD=4, SYM_CLEF=5, SYM_DYNAMIC=6, SYM_GLISSANDO=7, SYM_HAIRPIN=8, SYM_KEY_SIGN=9, SYM_MEASURE_NUMBERING=10, SYM_MIDI=11, SYM_NOTE=12, SYM_OTTAVA=13, SYM_ORNAMENT=14, SYM_PARENTH=15, SYM_PEDAL=16, SYM_PORTAMENTO=17, SYM_REHEARSAL_MARK=18, SYM_REPEAT=19, SYM_STEM=20, SYM_TEMPO=21, SYM_TEXT=22, SYM_TIE=23, SYM_TIME_SIGNATURE=24, SYM_TREMOLO=25, SYM_TUPLET=26, SYM_NUMBER=27 }


decompiled_code:
__int64 __fastcall rat2mpq(__int64 a1, __int16 *a2)
{
_gmpq_set_si(a1, *a2, a2[1]);
return _gmpq_canonicalize(a1);
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1, __int16 *a2)
{
_gmpq_set_si(a1, *a2, a2[1]);
return _gmpq_canonicalize(a1);
}

original_code:
void
rat2mpq(mpq_t q, RATIONAL *r)
{
    __gmpq_set_si(q, r->numerator, r->denominator);
    __gmpq_canonicalize(q);
}

canonical_original_code:
void rat2mpq(struct __mpq_struct q[1], struct RATIONAL *r)
{
    __gmpq_set_si(q, r->numerator, r->denominator);
    __gmpq_canonicalize(q);
}

variable_types: struct RATIONAL { short numerator; short denominator; } *

user_defined_types: struct __mpz_struct { int _mp_alloc; int _mp_size; unsigned long *_mp_d; }


decompiled_code:
__int64 __fastcall mpq_zero(__int64 a1)
{
_gmpq_init(&z_1);
_gmpq_set_ui(&z_1, 0LL, 1LL);
return _gmpq_equal(a1, &z_1);
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1)
{
_gmpq_init(&z_1);
_gmpq_set_ui(&z_1, 0LL, 1LL);
return _gmpq_equal(a1, &z_1);
}

original_code:
int
mpq_zero(mpq_t t)
{
    static mpq_t z;
    static int initialized = 0;
    if (! initialized) {
        __gmpq_init(z);
        __gmpq_set_ui(z, 0, 1);
    }
    return __gmpq_equal(t, z);
}

canonical_original_code:
int mpq_zero(struct __mpq_struct t[1])
{
    static struct __mpq_struct z[1];
    static int initialized = 0;
    if (! initialized) {
        __gmpq_init(z);
        __gmpq_set_ui(z, 0, 1);
    }
    return __gmpq_equal(t, z);
}

variable_types: initialized int


decompiled_code:
int verbose_printf(char *format, ...)
{
gcc_va_list arg; // [rsp+8h] [rbp-D0h] BYREF

va_start(arg, format);
return vfprintf(stderr, format, arg);
}

canonical_decompiled_code:
int func8(char *format, ...)
{
gcc_va_list arg; // [rsp+8h] [rbp-D0h] BYREF

va_start(arg, format);
return vfprintf(stderr, format, arg);
}

original_code:
int verbose_printf(char *fmt, ...)
{
    va_list ap;
    int r;
    __builtin_va_start(ap,fmt);
    r = vfprintf(stderr, fmt, ap);
    __builtin_va_end(ap);
    return r;
}

canonical_original_code:
int verbose_printf(char *fmt, ...)
{
    __builtin_va_list ap;
    int r;
    __builtin_va_start(ap,fmt);
    r = vfprintf(stderr, fmt, ap);
    __builtin_va_end(ap);
    return r;
}

variable_types:
fmt
char *

variable_types: r int


decompiled_code:
void __fastcall ties_increase(int a1)
{
int v1; // ebx
char *v2; // rdx
__int64 v3; // rax

v1 = n_ties;
if ( n_ties <= a1 )
{
n_ties = a1 + 1;
ties = realloc(ties, 16LL * (a1 + 1));
v2 = (char *)ties;
if ( v1 < n_ties )
{
v3 = 16LL * v1;
while ( 1 )
{
++v1;
*(_OWORD *)&v2[v3] = 0LL;
v3 += 16LL;
if ( n_ties <= v1 )
break;
v2 = (char *)ties;
}
}
}
}

canonical_decompiled_code:
void __fastcall func16(int a1)
{
int v1; // ebx
char *v2; // rdx
__int64 v3; // rax

v1 = n_ties;
if ( n_ties <= a1 )
{
n_ties = a1 + 1;
ties = realloc(ties, 16LL * (a1 + 1));
v2 = (char *)ties;
if ( v1 < n_ties )
{
v3 = 16LL * v1;
while ( 1 )
{
++v1;
*(_OWORD *)&v2[v3] = 0LL;
v3 += 16LL;
if ( n_ties <= v1 )
break;
v2 = (char *)ties;
}
}
}
}

original_code:
void
ties_increase(int ID)
{
    int i;
    int old_n;
    if (ID < n_ties) {
        return;
    }
    old_n = n_ties;
    n_ties = ID + 1;
    ties = realloc(ties, n_ties * sizeof(*ties));
    for (i = old_n; i < n_ties; i++) {
        memset(&ties[i], 0, sizeof(*ties));
    }
}

variable_types: ID int

variable_types: i int


decompiled_code:
char *__fastcall slurs_increase(int a1)
{
int v1; // ebx
char *result; // rax
void *v3; // rdx

v1 = n_slurs;
n_slurs = a1 + 1;
result = (char *)realloc(slur, 8LL * (a1 + 1));
slur = result;
if ( v1 < n_slurs )
{
v3 = result;
result = (char *)(8LL * v1);
while ( 1 )
{
*(_QWORD *)&result[(_QWORD)v3] = 0LL;
++v1;
result += 8;
if ( n_slurs <= v1 )
break;
v3 = slur;
}
}
return result;
}

canonical_decompiled_code:
char *__fastcall func17(int a1)
{
int v1; // ebx
char *result; // rax
void *v3; // rdx

v1 = n_slurs;
n_slurs = a1 + 1;
result = (char *)realloc(slur, 8LL * (a1 + 1));
slur = result;
if ( v1 < n_slurs )
{
v3 = result;
result = (char *)(8LL * v1);
while ( 1 )
{
*(_QWORD *)&result[(_QWORD)v3] = 0LL;
++v1;
result += 8;
if ( n_slurs <= v1 )
break;
v3 = slur;
}
}
return result;
}

original_code:
void
slurs_increase(int ID)
{
    int old_n_slurs = n_slurs;
    int i;
    n_slurs = ID + 1;
    slur = realloc(slur, n_slurs * sizeof(*slur));
    for (i = old_n_slurs; i < n_slurs; i++) {
        memset(&slur[i], 0, sizeof(*slur));
    }
}


decompiled_code:
void nf2_music_init()
{
;
}

canonical_decompiled_code:
void func18()
{
;
}

original_code:
void
nf2_music_init(void)
{
}

canonical_original_code:
void nf2_music_init()
{
}


decompiled_code:
void nf2_music_end()
{
;
}

canonical_decompiled_code:
void func19()
{
;
}

original_code:
void
nf2_music_end(void)
{
}

canonical_original_code:
void nf2_music_end()
{
}


decompiled_code:
void tag_activate_start()
{
tag_activate_collect = 1;
}

canonical_decompiled_code:
void func2()
{
tag_activate_collect = 1;
}

original_code:
void
tag_activate_start(void)
{
    tag_activate_collect = 1;
}


decompiled_code:
void tag_inactivate_start()
{
tag_inactivate_collect = 1;
}

canonical_decompiled_code:
void func5()
{
tag_inactivate_collect = 1;
}

original_code:
void
tag_inactivate_start(void)
{
    tag_inactivate_collect = 1;
}


decompiled_code:
void tag_inactivate_stop()
{
tag_inactivate_collect = 0;
}

canonical_decompiled_code:
void func6()
{
tag_inactivate_collect = 0;
}

original_code:
void
tag_inactivate_stop(void)
{
    tag_inactivate_collect = 0;
}