decompiled_code:
const char *__fastcall check_content(const char *a1)
{
bool v1; // cc
const char *result; // rax

if ( !a1 )
return "must specify";
v1 = strlen(a1) <= 0x7D00;
result = "too long";
if ( v1 )
result = 0LL;
return result;
}

canonical_decompiled_code:
const char *__fastcall func2(const char *a1)
{
bool v1; // cc
const char *result; // rax

if ( !a1 )
return "must specify";
v1 = strlen(a1) <= 0x7D00;
result = "too long";
if ( v1 )
result = 0LL;
return result;
}

original_code:
char *check_content(char *str)
{
 if (!str) {
  return "must specify";
 }
 if (strlen(str) > 32000) {
  return "too long";
 }
 return ((void *)0);
}


AllocDataBlock

repo: unixtools/authsrv

decompiled_code:
_DWORD *AllocDataBlock()
{
_DWORD *result; // rax

result = malloc(0x10uLL);
result[2] = 0;
*(_QWORD *)result = 0LL;
return result;
}

canonical_decompiled_code:
_DWORD *func3()
{
_DWORD *result; // rax

result = malloc(0x10uLL);
result[2] = 0;
*(_QWORD *)result = 0LL;
return result;
}

original_code:
struct DataBlock *AllocDataBlock()
{
 struct DataBlock *tmp;
 tmp = (struct DataBlock *)malloc(sizeof(struct DataBlock));
 tmp->length = 0;
 tmp->data = 0;
 return tmp;
}

variable_types: struct DataBlock { unsigned char *data; int length; } *


FetchHostKey

decompiled_code:
_DWORD *FetchHostKey()
{
return FileToDataBlock("/usr/share/authsrv/host-key");
}

canonical_decompiled_code:
_DWORD *func5()
{
return FileToDataBlock("/usr/share/authsrv/host-key");
}

original_code:
struct DataBlock *FetchHostKey(void)
{
 struct DataBlock *key = ((void *)0);
 key = FileToDataBlock("/usr/share/authsrv" "/" "host-key");
 return key;
}

canonical_original_code:
struct DataBlock *FetchHostKey()
{
 struct DataBlock *key = ((void *)0);
 key = FileToDataBlock("/usr/share/authsrv" "/" "host-key");
 return key;
}

return_type: struct DataBlock { unsigned char *data; int length; } *


FreeDataBlock

decompiled_code:
void __fastcall FreeDataBlock(void *ptr)
{
void *v2; // rdi

if ( ptr )
{
v2 = *(void **)ptr;
if ( v2 )
free(v2);
free(ptr);
}
}

canonical_decompiled_code:
void __fastcall func6(void *ptr)
{
void *v2; // rdi

if ( ptr )
{
v2 = *(void **)ptr;
if ( v2 )
free(v2);
free(ptr);
}
}

original_code:
void FreeDataBlock(struct DataBlock *datablock)
{
 if (datablock) {
  if (datablock->data) {
   free(datablock->data);
  }
  free(datablock);
 }
}

return_type: void

user_defined_types: struct DataBlock { unsigned char *data; int length; }


decompiled_code:
int __fastcall err_doit(int a1, const char *a2, void *a3)
{
int v4; // er13
char *v6; // rbx
size_t v7; // rax
char s[2]; // [rsp+0h] [rbp-228h] BYREF

v4 = *_errno_location();
vsprintf(s, a2, a3);
if ( a1 )
{
v6 = strerror(v4);
v7 = strlen(s);
sprintf(&s[v7], ": %s", v6);
}
*(_WORD *)&s[strlen(s)] = 10;
fflush(stdout);
fputs(s, stderr);
return fflush(stderr);
}

canonical_decompiled_code:
int __fastcall func0(int a1, const char *a2, void *a3)
{
int v4; // er13
char *v6; // rbx
size_t v7; // rax
char s[2]; // [rsp+0h] [rbp-228h] BYREF

v4 = *_errno_location();
vsprintf(s, a2, a3);
if ( a1 )
{
v6 = strerror(v4);
v7 = strlen(s);
sprintf(&s[v7], ": %s", v6);
}
*(_WORD *)&s[strlen(s)] = 10;
fflush(stdout);
fputs(s, stderr);
return fflush(stderr);
}

original_code:
static void err_doit(int errnoflag, const char *fmt, va_list ap) {
   int errno_save;
   char buf[512];
   errno_save = (*__errno_location ());
   vsprintf(buf, fmt, ap);
   if(errnoflag)
     sprintf(buf+strlen(buf), ": %s", strerror(errno_save));
   strcat(buf, "\n");
   fflush(stdout);
   fputs(buf, stderr);
   fflush(stderr);
   return;
}

canonical_original_code:
static void err_doit(int errnoflag, char *fmt, __builtin_va_list ap) {
   int errno_save;
   char buf[512];
   errno_save = (*__errno_location ());
   vsprintf(buf, fmt, ap);
   if(errnoflag)
     sprintf(buf+strlen(buf), ": %s", strerror(errno_save));
   strcat(buf, "\n");
   fflush(stdout);
   fputs(buf, stderr);
   fflush(stderr);
   return;
}

variable_types: errnoflag int

variable_types:
fmt
char *

variable_types:
buf
char [512]


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

va_start(va, a1);
err_doit(1, a1, va);
exit(1);
}

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

va_start(va, a1);
func0(1, a1, va);
exit(1);
}

original_code:
void err_sys(const char *fmt, ...) {
   va_list ap;
   __builtin_va_start(ap,fmt);
   err_doit(1, fmt, ap);
   __builtin_va_end(ap);
   exit(1);
}

canonical_original_code:
void err_sys(char *fmt, ...) {
   __builtin_va_list ap;
   __builtin_va_start(ap,fmt);
   err_doit(1, fmt, ap);
   __builtin_va_end(ap);
   exit(1);
}


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

va_start(va, a1);
err_doit(0, a1, va);
exit(1);
}

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

va_start(va, a1);
func0(0, a1, va);
exit(1);
}

original_code:
void err_quit(const char *fmt, ...) {
   va_list ap;
   __builtin_va_start(ap,fmt);
   err_doit(0, fmt, ap);
   __builtin_va_end(ap);
   exit(1);
}

canonical_original_code:
void err_quit(char *fmt, ...) {
   __builtin_va_list ap;
   __builtin_va_start(ap,fmt);
   err_doit(0, fmt, ap);
   __builtin_va_end(ap);
   exit(1);
}


writen

decompiled_code:
size_t __fastcall writen(int fd, void *buf, size_t n)
{
size_t v3; // r13
size_t v5; // rbx
ssize_t v6; // rax

v3 = n;
if ( !n )
return v3;
v5 = n;
while ( 1 )
{
v6 = write(fd, buf, v5);
if ( v6 <= 0 )
break;
LABEL_3:
buf = (char *)buf + v6;
v5 -= v6;
if ( !v5 )
return v3;
}
if ( *_errno_location() == 4 )
{
v6 = 0LL;
goto LABEL_3;
}
return -1LL;
}

canonical_decompiled_code:
size_t __fastcall func3(int fd, void *buf, size_t n)
{
size_t v3; // r13
size_t v5; // rbx
ssize_t v6; // rax

v3 = n;
if ( !n )
return v3;
v5 = n;
while ( 1 )
{
v6 = write(fd, buf, v5);
if ( v6 <= 0 )
break;
LABEL_3:
buf = (char *)buf + v6;
v5 -= v6;
if ( !v5 )
return v3;
}
if ( *_errno_location() == 4 )
{
v6 = 0LL;
goto LABEL_3;
}
return -1LL;
}

original_code:
ssize_t writen(int fd, const void *vptr, size_t n) {
   size_t nleft;
   ssize_t nwritten;
   const char *ptr;
   ptr = vptr;
   nleft = n;
   while (nleft > 0) {
   if ( (nwritten = write(fd, ptr, nleft)) <= 0) {
    if ((*__errno_location ()) == 4)
     nwritten = 0;
    else
     return(-1);
    }
    nleft -= nwritten;
    ptr += nwritten;
   }
   return(n);
}

canonical_original_code:
long writen(int fd, void *vptr, unsigned long n) {
   unsigned long nleft;
   long nwritten;
   char *ptr;
   ptr = vptr;
   nleft = n;
   while (nleft > 0) {
   if ( (nwritten = write(fd, ptr, nleft)) <= 0) {
    if ((*__errno_location ()) == 4)
     nwritten = 0;
    else
     return(-1);
    }
    nleft -= nwritten;
    ptr += nwritten;
   }
   return(n);
}

variable_types: fd int

variable_types:
vptr
void *

variable_types:
n
unsigned long

variable_types:
nleft
unsigned long

variable_types: nwritten long

variable_types:
ptr
char *

return_type: long


Writen

decompiled_code:
size_t __fastcall Writen(int a1, void *a2, size_t a3)
{
int v3; // ebx
size_t result; // rax

v3 = a3;
result = writen(a1, a2, a3);
if ( result != v3 )
err_sys("writen error");
return result;
}

canonical_decompiled_code:
size_t __fastcall func4(int a1, void *a2, size_t a3)
{
int v3; // ebx
size_t result; // rax

v3 = a3;
result = func3(a1, a2, a3);
if ( result != v3 )
func1("writen error");
return result;
}

original_code:
void Writen(int fd, void *ptr, size_t nbytes) {
 if (writen(fd, ptr, nbytes) != (int)nbytes)
  err_sys("writen error");
}

canonical_original_code:
void Writen(int fd, void *ptr, unsigned long nbytes) {
 if (writen(fd, ptr, nbytes) != (int)nbytes)
  err_sys("writen error");
}

variable_types:
ptr
void *

variable_types:
nbytes
unsigned long


Write

decompiled_code:
ssize_t __fastcall Write(int a1, const void *a2, size_t a3)
{
ssize_t result; // rax

result = write(a1, a2, a3);
if ( result != a3 )
err_sys("write error");
return result;
}

canonical_decompiled_code:
ssize_t __fastcall func5(int a1, const void *a2, size_t a3)
{
ssize_t result; // rax

result = write(a1, a2, a3);
if ( result != a3 )
func1("write error");
return result;
}

original_code:
void Write(int fd, void *ptr, size_t nbytes)
{
 if (write(fd, ptr, nbytes) != (ssize_t)nbytes)
  err_sys("write error");
}

canonical_original_code:
void Write(int fd, void *ptr, unsigned long nbytes)
{
 if (write(fd, ptr, nbytes) != (long)nbytes)
  err_sys("write error");
}


readn

decompiled_code:
size_t __fastcall readn(int fd, void *buf, size_t nbytes)
{
size_t v3; // r13
size_t v5; // rbx
ssize_t v6; // rax

v3 = nbytes;
if ( nbytes )
{
v5 = nbytes;
while ( 1 )
{
v6 = read(fd, buf, v5);
if ( v6 < 0 )
{
if ( *_errno_location() != 4 )
return -1LL;
v6 = 0LL;
}
else if ( !v6 )
{
return v3 - v5;
}
buf = (char *)buf + v6;
v5 -= v6;
if ( !v5 )
return v3 - v5;
}
}
v5 = 0LL;
return v3 - v5;
}

canonical_decompiled_code:
size_t __fastcall func6(int fd, void *buf, size_t nbytes)
{
size_t v3; // r13
size_t v5; // rbx
ssize_t v6; // rax

v3 = nbytes;
if ( nbytes )
{
v5 = nbytes;
while ( 1 )
{
v6 = read(fd, buf, v5);
if ( v6 < 0 )
{
if ( *_errno_location() != 4 )
return -1LL;
v6 = 0LL;
}
else if ( !v6 )
{
return v3 - v5;
}
buf = (char *)buf + v6;
v5 -= v6;
if ( !v5 )
return v3 - v5;
}
}
v5 = 0LL;
return v3 - v5;
}

original_code:
ssize_t readn(int fd, void *vptr, size_t n) {
 size_t nleft;
 ssize_t nread;
 char *ptr;
 ptr = vptr;
 nleft = n;
 while(nleft > 0) {
  if( (nread = read(fd, ptr, nleft)) < 0) {
   if((*__errno_location ()) == 4)
    nread = 0;
   else
    return(-1);
  }
  else if(nread == 0)
   break;
  nleft -= nread;
  ptr += nread;
 }
 return(n - nleft);
}

canonical_original_code:
long readn(int fd, void *vptr, unsigned long n) {
 unsigned long nleft;
 long nread;
 char *ptr;
 ptr = vptr;
 nleft = n;
 while(nleft > 0) {
  if( (nread = read(fd, ptr, nleft)) < 0) {
   if((*__errno_location ()) == 4)
    nread = 0;
   else
    return(-1);
  }
  else if(nread == 0)
   break;
  nleft -= nread;
  ptr += nread;
 }
 return(n - nleft);
}

variable_types: nread long


Readn

decompiled_code:
signed __int64 __fastcall Readn(int a1, void *a2, size_t a3)
{
signed __int64 result; // rax

result = readn(a1, a2, a3);
if ( result < 0 )
err_sys("readn error");
return result;
}

canonical_decompiled_code:
signed __int64 __fastcall func7(int a1, void *a2, size_t a3)
{
signed __int64 result; // rax

result = func6(a1, a2, a3);
if ( result < 0 )
func1("readn error");
return result;
}

original_code:
ssize_t Readn(int fd, void *ptr, size_t nbytes) {
 ssize_t n;
 if ( (n = readn(fd, ptr, nbytes)) < 0)
  err_sys("readn error");
 return(n);
}

canonical_original_code:
long Readn(int fd, void *ptr, unsigned long nbytes) {
 long n;
 if ( (n = readn(fd, ptr, nbytes)) < 0)
  err_sys("readn error");
 return(n);
}

variable_types: n long


Read

decompiled_code:
ssize_t __fastcall Read(int a1, void *a2, size_t a3)
{
ssize_t result; // rax
int *v4; // rax

result = read(a1, a2, a3);
if ( result == -1 )
{
v4 = _errno_location();
err_sys("read error %d\t", (unsigned int)*v4);
}
return result;
}

canonical_decompiled_code:
ssize_t __fastcall func8(int a1, void *a2, size_t a3)
{
ssize_t result; // rax
int *v4; // rax

result = read(a1, a2, a3);
if ( result == -1 )
{
v4 = _errno_location();
func1("read error %d\t", (unsigned int)*v4);
}
return result;
}

original_code:
ssize_t Read(int fd, void *ptr, size_t nbytes) {
 ssize_t n;
 if ( (n = read(fd, ptr, nbytes)) == -1)
  err_sys("read error %d\t", (*__errno_location ()));
 return(n);
}

canonical_original_code:
long Read(int fd, void *ptr, unsigned long nbytes) {
 long n;
 if ( (n = read(fd, ptr, nbytes)) == -1)
  err_sys("read error %d\t", (*__errno_location ()));
 return(n);
}


decompiled_code:
void __fastcall M1(__int64 a1)
{
_BYTE *v1; // rbx
_BYTE *v2; // rbp
__int64 i; // rax
void *ptr; // [rsp+18h] [rbp-30h] BYREF
char v5[40]; // [rsp+20h] [rbp-28h] BYREF

if ( !have_N )
_assert_fail("have_N", "srp.c", 0xB7u, "M1");
if ( !have_g )
_assert_fail("have_g", "srp.c", 0xB8u, "M1");
if ( !have_s )
_assert_fail("have_s", "srp.c", 0xB9u, "M1");
if ( !have_A )
_assert_fail("have_A", "srp.c", 0xBAu, "M1");
if ( !have_B )
_assert_fail("have_B", "srp.c", 0xBBu, "M1");
if ( !have_K )
_assert_fail("have_K", "srp.c", 0xBCu, "M1");
v1 = (_BYTE *)sha256_binz(&my_N);
v2 = (_BYTE *)sha256_binz(&my_g);
for ( i = 0LL; i != 32; ++i )
v1[i] ^= v2[i];
_gmpz_init(v5);
_gmpz_import(v5, 32LL, 1LL, 1LL, 0LL, 0LL, v1);
free(v1);
free(v2);
_gmp_asprintf(&ptr, "%Zx%Zx%Zx%Zx%Zx", v5, &my_s, &my_A, &my_B, &my_K);
sha256_s(ptr, a1);
free(ptr);
}

canonical_decompiled_code:
void __fastcall func0(__int64 a1)
{
_BYTE *v1; // rbx
_BYTE *v2; // rbp
__int64 i; // rax
void *ptr; // [rsp+18h] [rbp-30h] BYREF
char v5[40]; // [rsp+20h] [rbp-28h] BYREF

if ( !have_N )
_assert_fail("have_N", "srp.c", 0xB7u, "M1");
if ( !have_g )
_assert_fail("have_g", "srp.c", 0xB8u, "M1");
if ( !have_s )
_assert_fail("have_s", "srp.c", 0xB9u, "M1");
if ( !have_A )
_assert_fail("have_A", "srp.c", 0xBAu, "M1");
if ( !have_B )
_assert_fail("have_B", "srp.c", 0xBBu, "M1");
if ( !have_K )
_assert_fail("have_K", "srp.c", 0xBCu, "M1");
v1 = (_BYTE *)sha256_binz(&my_N);
v2 = (_BYTE *)sha256_binz(&my_g);
for ( i = 0LL; i != 32; ++i )
v1[i] ^= v2[i];
_gmpz_init(v5);
_gmpz_import(v5, 32LL, 1LL, 1LL, 0LL, 0LL, v1);
free(v1);
free(v2);
_gmp_asprintf(&ptr, "%Zx%Zx%Zx%Zx%Zx", v5, &my_s, &my_A, &my_B, &my_K);
sha256_s(ptr, a1);
free(ptr);
}

original_code:
static void M1( mpz_t retval )
{
  ((have_N) ? (void) (0) : __assert_fail ("have_N", "srp.c", 183, __extension__ __PRETTY_FUNCTION__));
  ((have_g) ? (void) (0) : __assert_fail ("have_g", "srp.c", 184, __extension__ __PRETTY_FUNCTION__));
  ((have_s) ? (void) (0) : __assert_fail ("have_s", "srp.c", 185, __extension__ __PRETTY_FUNCTION__));
  ((have_A) ? (void) (0) : __assert_fail ("have_A", "srp.c", 186, __extension__ __PRETTY_FUNCTION__));
  ((have_B) ? (void) (0) : __assert_fail ("have_B", "srp.c", 187, __extension__ __PRETTY_FUNCTION__));
  ((have_K) ? (void) (0) : __assert_fail ("have_K", "srp.c", 188, __extension__ __PRETTY_FUNCTION__));
  BYTE* HN = sha256_binz( my_N );
  BYTE* Hg = sha256_binz( my_g );
  for( int i = 0; i < 32; i++ ) {
    HN[i] ^= Hg[i];
  }
  mpz_t HG; __gmpz_init( HG );
  __gmpz_import( HG, 32, 1, 1, 0, 0, HN );
  free( HN); free( Hg);
  char* pALL;
  __gmp_asprintf( &pALL, "%Zx%Zx%Zx%Zx%Zx", HG, my_s, my_A, my_B, my_K );
  sha256_s( (const unsigned char const*)pALL, retval );
  free( pALL );
}

canonical_original_code:
static void M1(struct __mpz_struct retval[1])
{
  ((have_N) ? (void) (0) : __assert_fail ("have_N", "srp.c", 183, __extension__ __PRETTY_FUNCTION__));
  ((have_g) ? (void) (0) : __assert_fail ("have_g", "srp.c", 184, __extension__ __PRETTY_FUNCTION__));
  ((have_s) ? (void) (0) : __assert_fail ("have_s", "srp.c", 185, __extension__ __PRETTY_FUNCTION__));
  ((have_A) ? (void) (0) : __assert_fail ("have_A", "srp.c", 186, __extension__ __PRETTY_FUNCTION__));
  ((have_B) ? (void) (0) : __assert_fail ("have_B", "srp.c", 187, __extension__ __PRETTY_FUNCTION__));
  ((have_K) ? (void) (0) : __assert_fail ("have_K", "srp.c", 188, __extension__ __PRETTY_FUNCTION__));
  unsigned char *HN = sha256_binz( my_N );
  unsigned char *Hg = sha256_binz( my_g );
  for( int i = 0; i < 32; i++ ) {
    HN[i] ^= Hg[i];
  }
  struct __mpz_struct HG[1]; __gmpz_init( HG );
  __gmpz_import( HG, 32, 1, 1, 0, 0, HN );
  free( HN); free( Hg);
  char *pALL;
  __gmp_asprintf( &pALL, "%Zx%Zx%Zx%Zx%Zx", HG, my_s, my_A, my_B, my_K );
  sha256_s( (unsigned char *)pALL, retval );
  free( pALL );
}

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

variable_types:
HN
unsigned char *

variable_types:
Hg
unsigned char *

variable_types: i int

variable_types:
pALL
char *


decompiled_code:
void __fastcall M2(__int64 a1)
{
void *ptr; // [rsp+8h] [rbp-20h] BYREF
char v2[24]; // [rsp+10h] [rbp-18h] BYREF

if ( !have_A )
_assert_fail("have_A", "srp.c", 0xD4u, "M2");
if ( !have_K )
_assert_fail("have_K", "srp.c", 0xD5u, "M2");
_gmpz_init(v2);
M1((__int64)v2);
_gmp_asprintf(&ptr, "%Zx%Zx%Zx", &my_A, v2, &my_K);
sha256_s(ptr, a1);
free(ptr);
}

canonical_decompiled_code:
void __fastcall func1(__int64 a1)
{
void *ptr; // [rsp+8h] [rbp-20h] BYREF
char v2[24]; // [rsp+10h] [rbp-18h] BYREF

if ( !have_A )
_assert_fail("have_A", "srp.c", 0xD4u, "M2");
if ( !have_K )
_assert_fail("have_K", "srp.c", 0xD5u, "M2");
_gmpz_init(v2);
func0((__int64)v2);
_gmp_asprintf(&ptr, "%Zx%Zx%Zx", &my_A, v2, &my_K);
sha256_s(ptr, a1);
free(ptr);
}

original_code:
static void M2( mpz_t retval )
{
  ((have_A) ? (void) (0) : __assert_fail ("have_A", "srp.c", 212, __extension__ __PRETTY_FUNCTION__));
  ((have_K) ? (void) (0) : __assert_fail ("have_K", "srp.c", 213, __extension__ __PRETTY_FUNCTION__));
  mpz_t my_M1; __gmpz_init( my_M1 );
  M1( my_M1 );
  char* pALL;
  __gmp_asprintf( &pALL, "%Zx%Zx%Zx", my_A, my_M1, my_K );
  sha256_s( (const unsigned char const*)pALL, retval );
  free( pALL );
}

canonical_original_code:
static void M2(struct __mpz_struct retval[1])
{
  ((have_A) ? (void) (0) : __assert_fail ("have_A", "srp.c", 212, __extension__ __PRETTY_FUNCTION__));
  ((have_K) ? (void) (0) : __assert_fail ("have_K", "srp.c", 213, __extension__ __PRETTY_FUNCTION__));
  struct __mpz_struct my_M1[1]; __gmpz_init( my_M1 );
  M1( my_M1 );
  char *pALL;
  __gmp_asprintf( &pALL, "%Zx%Zx%Zx", my_A, my_M1, my_K );
  sha256_s( (unsigned char *)pALL, retval );
  free( pALL );
}

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


decompiled_code:
__int64 __fastcall set_g(__int64 a1)
{
__int64 result; // rax

if ( have_g )
_assert_fail("! have_g", "srp.c", 0x1Du, "set_g");
_gmpz_init(&my_g);
result = _gmpz_set(&my_g, a1);
have_g = 1;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1)
{
__int64 result; // rax

if ( have_g )
_assert_fail("! have_g", "srp.c", 0x1Du, "set_g");
_gmpz_init(&my_g);
result = _gmpz_set(&my_g, a1);
have_g = 1;
return result;
}

original_code:
void set_g( mpz_t g )
{
  ((! have_g) ? (void) (0) : __assert_fail ("! have_g", "srp.c", 29, __extension__ __PRETTY_FUNCTION__));
  __gmpz_init( my_g );
  __gmpz_set( my_g, g );
  have_g = 1;
}

canonical_original_code:
void set_g(struct __mpz_struct g[1])
{
  ((! have_g) ? (void) (0) : __assert_fail ("! have_g", "srp.c", 29, __extension__ __PRETTY_FUNCTION__));
  __gmpz_init( my_g );
  __gmpz_set( my_g, g );
  have_g = 1;
}


decompiled_code:
__int64 __fastcall set_N(__int64 a1)
{
__int64 result; // rax

if ( have_N )
_assert_fail("! have_N", "srp.c", 0x28u, "set_N");
_gmpz_init(&my_N);
result = _gmpz_set(&my_N, a1);
have_N = 1;
return result;
}

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

if ( have_N )
_assert_fail("! have_N", "srp.c", 0x28u, "set_N");
_gmpz_init(&my_N);
result = _gmpz_set(&my_N, a1);
have_N = 1;
return result;
}

original_code:
void set_N( mpz_t N )
{
  ((! have_N) ? (void) (0) : __assert_fail ("! have_N", "srp.c", 40, __extension__ __PRETTY_FUNCTION__));
  __gmpz_init( my_N );
  __gmpz_set( my_N, N );
  have_N = 1;
}

canonical_original_code:
void set_N(struct __mpz_struct N[1])
{
  ((! have_N) ? (void) (0) : __assert_fail ("! have_N", "srp.c", 40, __extension__ __PRETTY_FUNCTION__));
  __gmpz_init( my_N );
  __gmpz_set( my_N, N );
  have_N = 1;
}


decompiled_code:
__int64 calc_k()
{
__int64 result; // rax

if ( !have_g )
_assert_fail("have_g", "srp.c", 0x34u, "calc_k");
if ( !have_N )
_assert_fail("have_N", "srp.c", 0x35u, "calc_k");
_gmpz_init(&my_k);
result = sha256_zz(&my_N, &my_g, &my_k);
have_k = 1;
return result;
}

canonical_decompiled_code:
__int64 func4()
{
__int64 result; // rax

if ( !have_g )
_assert_fail("have_g", "srp.c", 0x34u, "calc_k");
if ( !have_N )
_assert_fail("have_N", "srp.c", 0x35u, "calc_k");
_gmpz_init(&my_k);
result = sha256_zz(&my_N, &my_g, &my_k);
have_k = 1;
return result;
}

original_code:
void calc_k()
{
  ((have_g) ? (void) (0) : __assert_fail ("have_g", "srp.c", 52, __extension__ __PRETTY_FUNCTION__));
  ((have_N) ? (void) (0) : __assert_fail ("have_N", "srp.c", 53, __extension__ __PRETTY_FUNCTION__));
  __gmpz_init( my_k );
  sha256_zz( my_N, my_g, my_k );
  have_k = 1;
}


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

_gmpz_init(&my_s);
_gmpz_set(&my_s, a1);
have_s = 1;
_gmpz_init(&my_v);
result = _gmpz_set(&my_v, a2);
have_v = 1;
return result;
}

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

_gmpz_init(&my_s);
_gmpz_set(&my_s, a1);
have_s = 1;
_gmpz_init(&my_v);
result = _gmpz_set(&my_v, a2);
have_v = 1;
return result;
}

original_code:
void server_set_v( mpz_t salt, mpz_t v )
{
  __gmpz_init( my_s );
  __gmpz_set( my_s, salt );
  have_s = 1;
  __gmpz_init( my_v );
  __gmpz_set( my_v, v );
  have_v = 1;
}

canonical_original_code:
void server_set_v(struct __mpz_struct salt[1], struct __mpz_struct v[1])
{
  __gmpz_init( my_s );
  __gmpz_set( my_s, salt );
  have_s = 1;
  __gmpz_init( my_v );
  __gmpz_set( my_v, v );
  have_v = 1;
}

variable_types:
v
struct __mpz_struct [1]


decompiled_code:
__int64 calc_u()
{
_gmpz_init(&my_u);
if ( !have_A )
_assert_fail("have_A", "srp.c", 0x6Bu, "calc_u");
if ( !have_B )
_assert_fail("have_B", "srp.c", 0x6Cu, "calc_u");
return sha256_zz(&my_A, &my_B, &my_u);
}

canonical_decompiled_code:
__int64 func7()
{
_gmpz_init(&my_u);
if ( !have_A )
_assert_fail("have_A", "srp.c", 0x6Bu, "calc_u");
if ( !have_B )
_assert_fail("have_B", "srp.c", 0x6Cu, "calc_u");
return sha256_zz(&my_A, &my_B, &my_u);
}

original_code:
void calc_u()
{
  __gmpz_init( my_u );
  ((have_A) ? (void) (0) : __assert_fail ("have_A", "srp.c", 107, __extension__ __PRETTY_FUNCTION__));
  ((have_B) ? (void) (0) : __assert_fail ("have_B", "srp.c", 108, __extension__ __PRETTY_FUNCTION__));
  sha256_zz( my_A, my_B, my_u );
}


decompiled_code:
__int64 __fastcall client_init(__int64 a1)
{
__int64 result; // rax

_gmpz_init(&my_a);
set_random64(&my_a);
have_a = 1;
if ( !have_g )
_assert_fail("have_g", "srp.c", 0x7Du, "client_init");
if ( !have_N )
_assert_fail("have_N", "srp.c", 0x7Eu, "client_init");
_gmpz_powm(&my_A, &my_g, &my_a, &my_N);
result = _gmpz_set(a1, &my_A);
have_A = 1;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func8(__int64 a1)
{
__int64 result; // rax

_gmpz_init(&my_a);
set_random64(&my_a);
have_a = 1;
if ( !have_g )
_assert_fail("have_g", "srp.c", 0x7Du, "client_init");
if ( !have_N )
_assert_fail("have_N", "srp.c", 0x7Eu, "client_init");
_gmpz_powm(&my_A, &my_g, &my_a, &my_N);
result = _gmpz_set(a1, &my_A);
have_A = 1;
return result;
}

original_code:
void client_init( mpz_t A )
{
  __gmpz_init( my_a );
  set_random64( my_a );
  have_a = 1;
  ((have_g) ? (void) (0) : __assert_fail ("have_g", "srp.c", 125, __extension__ __PRETTY_FUNCTION__));
  ((have_N) ? (void) (0) : __assert_fail ("have_N", "srp.c", 126, __extension__ __PRETTY_FUNCTION__));
  __gmpz_powm( my_A, my_g, my_a, my_N );
  __gmpz_set( A, my_A );
  have_A = 1;
}

canonical_original_code:
void client_init(struct __mpz_struct A[1])
{
  __gmpz_init( my_a );
  set_random64( my_a );
  have_a = 1;
  ((have_g) ? (void) (0) : __assert_fail ("have_g", "srp.c", 125, __extension__ __PRETTY_FUNCTION__));
  ((have_N) ? (void) (0) : __assert_fail ("have_N", "srp.c", 126, __extension__ __PRETTY_FUNCTION__));
  __gmpz_powm( my_A, my_g, my_a, my_N );
  __gmpz_set( A, my_A );
  have_A = 1;
}


decompiled_code:
__int64 __fastcall client_setB(__int64 a1)
{
__int64 result; // rax

_gmpz_init(&my_B);
result = _gmpz_set(&my_B, a1);
have_B = 1;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func9(__int64 a1)
{
__int64 result; // rax

_gmpz_init(&my_B);
result = _gmpz_set(&my_B, a1);
have_B = 1;
return result;
}

original_code:
void client_setB( mpz_t B)
{
  __gmpz_init( my_B );
  __gmpz_set( my_B, B );
  have_B = 1;
}

canonical_original_code:
void client_setB(struct __mpz_struct B[1])
{
  __gmpz_init( my_B );
  __gmpz_set( my_B, B );
  have_B = 1;
}


decompiled_code:
__int64 __fastcall client_K(__int64 a1)
{
_BYTE v2[16]; // [rsp+0h] [rbp-68h] BYREF
char v3[16]; // [rsp+10h] [rbp-58h] BYREF
char v4[16]; // [rsp+20h] [rbp-48h] BYREF
char v5[16]; // [rsp+30h] [rbp-38h] BYREF
char v6[16]; // [rsp+40h] [rbp-28h] BYREF
char v7[24]; // [rsp+50h] [rbp-18h] BYREF

_gmpz_init(v7);
calc_u();
calc_k();
if ( !have_a )
_assert_fail("have_a", "srp.c", 0x94u, "client_K");
if ( !have_x )
_assert_fail("have_x", "srp.c", 0x95u, "client_K");
_gmpz_init(v6);
_gmpz_mul(v6, &my_u, &my_x);
_gmpz_init(v5);
_gmpz_add(v5, &my_a, v6);
_gmpz_clear(v6);
if ( !have_x )
_assert_fail("have_x", "srp.c", 0x9Cu, "client_K");
if ( !have_g )
_assert_fail("have_g", "srp.c", 0x9Du, "client_K");
if ( !have_k )
_assert_fail("have_k", "srp.c", 0x9Eu, "client_K");
if ( !have_B )
_assert_fail("have_B", "srp.c", 0x9Fu, "client_K");
_gmpz_init(v4);
_gmpz_powm(v4, &my_g, &my_x, &my_N);
_gmpz_init(v3);
_gmpz_mul(v3, &my_k, v4);
_gmpz_clear(v4);
_gmpz_init(v2);
_gmpz_sub(v2, &my_B, v3);
_gmpz_clear(v3);
_gmpz_powm(v7, v2, v5, &my_N);
_gmpz_clear(v2);
_gmpz_clear(v5);
sha256_z(v7, &my_K);
have_K = 1;
return _gmpz_set(a1, &my_K);
}

canonical_decompiled_code:
__int64 __fastcall func10(__int64 a1)
{
_BYTE v2[16]; // [rsp+0h] [rbp-68h] BYREF
char v3[16]; // [rsp+10h] [rbp-58h] BYREF
char v4[16]; // [rsp+20h] [rbp-48h] BYREF
char v5[16]; // [rsp+30h] [rbp-38h] BYREF
char v6[16]; // [rsp+40h] [rbp-28h] BYREF
char v7[24]; // [rsp+50h] [rbp-18h] BYREF

_gmpz_init(v7);
func7();
func4();
if ( !have_a )
_assert_fail("have_a", "srp.c", 0x94u, "client_K");
if ( !have_x )
_assert_fail("have_x", "srp.c", 0x95u, "client_K");
_gmpz_init(v6);
_gmpz_mul(v6, &my_u, &my_x);
_gmpz_init(v5);
_gmpz_add(v5, &my_a, v6);
_gmpz_clear(v6);
if ( !have_x )
_assert_fail("have_x", "srp.c", 0x9Cu, "client_K");
if ( !have_g )
_assert_fail("have_g", "srp.c", 0x9Du, "client_K");
if ( !have_k )
_assert_fail("have_k", "srp.c", 0x9Eu, "client_K");
if ( !have_B )
_assert_fail("have_B", "srp.c", 0x9Fu, "client_K");
_gmpz_init(v4);
_gmpz_powm(v4, &my_g, &my_x, &my_N);
_gmpz_init(v3);
_gmpz_mul(v3, &my_k, v4);
_gmpz_clear(v4);
_gmpz_init(v2);
_gmpz_sub(v2, &my_B, v3);
_gmpz_clear(v3);
_gmpz_powm(v7, v2, v5, &my_N);
_gmpz_clear(v2);
_gmpz_clear(v5);
sha256_z(v7, &my_K);
have_K = 1;
return _gmpz_set(a1, &my_K);
}

original_code:
void client_K( mpz_t K )
{
  mpz_t S;
  __gmpz_init( S );
  calc_u();
  calc_k();
  ((have_a) ? (void) (0) : __assert_fail ("have_a", "srp.c", 148, __extension__ __PRETTY_FUNCTION__));
  ((have_x) ? (void) (0) : __assert_fail ("have_x", "srp.c", 149, __extension__ __PRETTY_FUNCTION__));
  mpz_t ux; __gmpz_init( ux );
  __gmpz_mul( ux, my_u, my_x );
  mpz_t pow; __gmpz_init( pow );
  __gmpz_add( pow, my_a, ux );
  __gmpz_clear( ux );
  ((have_x) ? (void) (0) : __assert_fail ("have_x", "srp.c", 156, __extension__ __PRETTY_FUNCTION__));
  ((have_g) ? (void) (0) : __assert_fail ("have_g", "srp.c", 157, __extension__ __PRETTY_FUNCTION__));
  ((have_k) ? (void) (0) : __assert_fail ("have_k", "srp.c", 158, __extension__ __PRETTY_FUNCTION__));
  ((have_B) ? (void) (0) : __assert_fail ("have_B", "srp.c", 159, __extension__ __PRETTY_FUNCTION__));
  mpz_t a; __gmpz_init( a );
  __gmpz_powm( a, my_g, my_x, my_N );
  mpz_t b; __gmpz_init( b );
  __gmpz_mul( b, my_k, a );
  __gmpz_clear( a );
  mpz_t base; __gmpz_init( base );
  __gmpz_sub( base, my_B, b );
  __gmpz_clear( b );
  __gmpz_powm( S, base, pow, my_N );
  __gmpz_clear( base ); __gmpz_clear( pow );
  sha256_z( S, my_K );
  have_K = 1;
  __gmpz_set( K, my_K );
}

canonical_original_code:
void client_K(struct __mpz_struct K[1])
{
  struct __mpz_struct S[1];
  __gmpz_init( S );
  calc_u();
  calc_k();
  ((have_a) ? (void) (0) : __assert_fail ("have_a", "srp.c", 148, __extension__ __PRETTY_FUNCTION__));
  ((have_x) ? (void) (0) : __assert_fail ("have_x", "srp.c", 149, __extension__ __PRETTY_FUNCTION__));
  struct __mpz_struct ux[1]; __gmpz_init( ux );
  __gmpz_mul( ux, my_u, my_x );
  struct __mpz_struct pow[1]; __gmpz_init( pow );
  __gmpz_add( pow, my_a, ux );
  __gmpz_clear( ux );
  ((have_x) ? (void) (0) : __assert_fail ("have_x", "srp.c", 156, __extension__ __PRETTY_FUNCTION__));
  ((have_g) ? (void) (0) : __assert_fail ("have_g", "srp.c", 157, __extension__ __PRETTY_FUNCTION__));
  ((have_k) ? (void) (0) : __assert_fail ("have_k", "srp.c", 158, __extension__ __PRETTY_FUNCTION__));
  ((have_B) ? (void) (0) : __assert_fail ("have_B", "srp.c", 159, __extension__ __PRETTY_FUNCTION__));
  struct __mpz_struct a[1]; __gmpz_init( a );
  __gmpz_powm( a, my_g, my_x, my_N );
  struct __mpz_struct b[1]; __gmpz_init( b );
  __gmpz_mul( b, my_k, a );
  __gmpz_clear( a );
  struct __mpz_struct base[1]; __gmpz_init( base );
  __gmpz_sub( base, my_B, b );
  __gmpz_clear( b );
  __gmpz_powm( S, base, pow, my_N );
  __gmpz_clear( base ); __gmpz_clear( pow );
  sha256_z( S, my_K );
  have_K = 1;
  __gmpz_set( K, my_K );
}


decompiled_code:
void __fastcall client_M1(__int64 a1)
{
M1(a1);
}

canonical_decompiled_code:
void __fastcall func11(__int64 a1)
{
func0(a1);
}

original_code:
void client_M1( mpz_t retval )
{
  M1( retval );
}

canonical_original_code:
void client_M1(struct __mpz_struct retval[1])
{
  M1( retval );
}


decompiled_code:
bool __fastcall client_verifyM2(__int64 a1)
{
_BYTE v2[24]; // [rsp+0h] [rbp-18h] BYREF

_gmpz_init(v2);
M2((__int64)v2);
return (unsigned int)_gmpz_cmp(v2, a1) == 0;
}

canonical_decompiled_code:
bool __fastcall func12(__int64 a1)
{
_BYTE v2[24]; // [rsp+0h] [rbp-18h] BYREF

_gmpz_init(v2);
func1((__int64)v2);
return (unsigned int)_gmpz_cmp(v2, a1) == 0;
}

original_code:
_Bool client_verifyM2( mpz_t other_M2 )
{
  mpz_t my_M2; __gmpz_init( my_M2 );
  M2( my_M2 );
  if( __gmpz_cmp( my_M2, other_M2 ) == 0 ) {
    return 1;
  } else {
    return 0;
  }
}

canonical_original_code:
_Bool client_verifyM2(struct __mpz_struct other_M2[1])
{
  struct __mpz_struct my_M2[1]; __gmpz_init( my_M2 );
  M2( my_M2 );
  if( __gmpz_cmp( my_M2, other_M2 ) == 0 ) {
    return 1;
  } else {
    return 0;
  }
}


decompiled_code:
__int64 __fastcall server_init(__int64 a1)
{
_BYTE v2[16]; // [rsp+0h] [rbp-28h] BYREF
char v3[24]; // [rsp+10h] [rbp-18h] BYREF

calc_k();
_gmpz_init(&my_b);
set_random64(&my_b);
have_b = 1;
if ( !have_v )
_assert_fail("have_v", "srp.c", 0x103u, "server_init");
if ( !have_k )
_assert_fail("have_k", "srp.c", 0x104u, "server_init");
if ( !have_g )
_assert_fail("have_g", "srp.c", 0x105u, "server_init");
if ( !have_N )
_assert_fail("have_N", "srp.c", 0x106u, "server_init");
_gmpz_init(v3);
_gmpz_powm(v3, &my_g, &my_b, &my_N);
_gmpz_init(v2);
_gmpz_mul(v2, &my_k, &my_v);
_gmpz_add(&my_B, v2, v3);
_gmpz_mod(&my_B, &my_B, &my_N);
have_B = 1;
_gmpz_clear(v2);
_gmpz_clear(v3);
return _gmpz_set(a1, &my_B);
}

canonical_decompiled_code:
__int64 __fastcall func13(__int64 a1)
{
_BYTE v2[16]; // [rsp+0h] [rbp-28h] BYREF
char v3[24]; // [rsp+10h] [rbp-18h] BYREF

func4();
_gmpz_init(&my_b);
set_random64(&my_b);
have_b = 1;
if ( !have_v )
_assert_fail("have_v", "srp.c", 0x103u, "server_init");
if ( !have_k )
_assert_fail("have_k", "srp.c", 0x104u, "server_init");
if ( !have_g )
_assert_fail("have_g", "srp.c", 0x105u, "server_init");
if ( !have_N )
_assert_fail("have_N", "srp.c", 0x106u, "server_init");
_gmpz_init(v3);
_gmpz_powm(v3, &my_g, &my_b, &my_N);
_gmpz_init(v2);
_gmpz_mul(v2, &my_k, &my_v);
_gmpz_add(&my_B, v2, v3);
_gmpz_mod(&my_B, &my_B, &my_N);
have_B = 1;
_gmpz_clear(v2);
_gmpz_clear(v3);
return _gmpz_set(a1, &my_B);
}

original_code:
void server_init( mpz_t B )
{
  calc_k();
  __gmpz_init( my_b );
  set_random64( my_b );
  have_b = 1;
  ((have_v) ? (void) (0) : __assert_fail ("have_v", "srp.c", 259, __extension__ __PRETTY_FUNCTION__));
  ((have_k) ? (void) (0) : __assert_fail ("have_k", "srp.c", 260, __extension__ __PRETTY_FUNCTION__));
  ((have_g) ? (void) (0) : __assert_fail ("have_g", "srp.c", 261, __extension__ __PRETTY_FUNCTION__));
  ((have_N) ? (void) (0) : __assert_fail ("have_N", "srp.c", 262, __extension__ __PRETTY_FUNCTION__));
  mpz_t pow; __gmpz_init( pow );
  __gmpz_powm( pow, my_g, my_b, my_N );
  mpz_t kv; __gmpz_init( kv );
  __gmpz_mul( kv, my_k, my_v );
  __gmpz_add( my_B, kv, pow );
  __gmpz_mod( my_B, my_B, my_N );
  have_B = 1;
  __gmpz_clear( kv ); __gmpz_clear( pow );
  __gmpz_set( B, my_B );
}

canonical_original_code:
void server_init(struct __mpz_struct B[1])
{
  calc_k();
  __gmpz_init( my_b );
  set_random64( my_b );
  have_b = 1;
  ((have_v) ? (void) (0) : __assert_fail ("have_v", "srp.c", 259, __extension__ __PRETTY_FUNCTION__));
  ((have_k) ? (void) (0) : __assert_fail ("have_k", "srp.c", 260, __extension__ __PRETTY_FUNCTION__));
  ((have_g) ? (void) (0) : __assert_fail ("have_g", "srp.c", 261, __extension__ __PRETTY_FUNCTION__));
  ((have_N) ? (void) (0) : __assert_fail ("have_N", "srp.c", 262, __extension__ __PRETTY_FUNCTION__));
  struct __mpz_struct pow[1]; __gmpz_init( pow );
  __gmpz_powm( pow, my_g, my_b, my_N );
  struct __mpz_struct kv[1]; __gmpz_init( kv );
  __gmpz_mul( kv, my_k, my_v );
  __gmpz_add( my_B, kv, pow );
  __gmpz_mod( my_B, my_B, my_N );
  have_B = 1;
  __gmpz_clear( kv ); __gmpz_clear( pow );
  __gmpz_set( B, my_B );
}


decompiled_code:
__int64 __fastcall server_setA(__int64 a1)
{
__int64 result; // rax

result = _gmpz_set(&my_A, a1);
have_A = 1;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func14(__int64 a1)
{
__int64 result; // rax

result = _gmpz_set(&my_A, a1);
have_A = 1;
return result;
}

original_code:
void server_setA( mpz_t A )
{
  __gmpz_set( my_A, A );
  have_A = 1;
}

canonical_original_code:
void server_setA(struct __mpz_struct A[1])
{
  __gmpz_set( my_A, A );
  have_A = 1;
}


decompiled_code:
__int64 __fastcall server_K(__int64 a1)
{
__int64 result; // rax
_BYTE v2[16]; // [rsp+0h] [rbp-38h] BYREF
char v3[16]; // [rsp+10h] [rbp-28h] BYREF
char v4[24]; // [rsp+20h] [rbp-18h] BYREF

_gmpz_init(v4);
calc_u();
if ( !have_v )
_assert_fail("have_v", "srp.c", 0x121u, "server_K");
if ( !have_b )
_assert_fail("have_b", "srp.c", 0x122u, "server_K");
if ( !have_A )
_assert_fail("have_A", "srp.c", 0x123u, "server_K");
if ( !have_N )
_assert_fail("have_N", "srp.c", 0x124u, "server_K");
_gmpz_init(v3);
_gmpz_powm(v3, &my_v, &my_u, &my_N);
_gmpz_init(v2);
_gmpz_mul(v2, &my_A, v3);
_gmpz_clear(v3);
_gmpz_powm(v4, v2, &my_b, &my_N);
_gmpz_clear(v2);
sha256_z(v4, &my_K);
result = _gmpz_set(a1, &my_K);
have_K = 1;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func15(__int64 a1)
{
__int64 result; // rax
_BYTE v2[16]; // [rsp+0h] [rbp-38h] BYREF
char v3[16]; // [rsp+10h] [rbp-28h] BYREF
char v4[24]; // [rsp+20h] [rbp-18h] BYREF

_gmpz_init(v4);
func7();
if ( !have_v )
_assert_fail("have_v", "srp.c", 0x121u, "server_K");
if ( !have_b )
_assert_fail("have_b", "srp.c", 0x122u, "server_K");
if ( !have_A )
_assert_fail("have_A", "srp.c", 0x123u, "server_K");
if ( !have_N )
_assert_fail("have_N", "srp.c", 0x124u, "server_K");
_gmpz_init(v3);
_gmpz_powm(v3, &my_v, &my_u, &my_N);
_gmpz_init(v2);
_gmpz_mul(v2, &my_A, v3);
_gmpz_clear(v3);
_gmpz_powm(v4, v2, &my_b, &my_N);
_gmpz_clear(v2);
sha256_z(v4, &my_K);
result = _gmpz_set(a1, &my_K);
have_K = 1;
return result;
}

original_code:
void server_K( mpz_t K )
{
  mpz_t S;
  __gmpz_init( S );
  calc_u();
  ((have_v) ? (void) (0) : __assert_fail ("have_v", "srp.c", 289, __extension__ __PRETTY_FUNCTION__));
  ((have_b) ? (void) (0) : __assert_fail ("have_b", "srp.c", 290, __extension__ __PRETTY_FUNCTION__));
  ((have_A) ? (void) (0) : __assert_fail ("have_A", "srp.c", 291, __extension__ __PRETTY_FUNCTION__));
  ((have_N) ? (void) (0) : __assert_fail ("have_N", "srp.c", 292, __extension__ __PRETTY_FUNCTION__));
  mpz_t pow; __gmpz_init( pow );
  __gmpz_powm( pow, my_v, my_u, my_N );
  mpz_t Avu; __gmpz_init( Avu );
  __gmpz_mul( Avu, my_A, pow );
  __gmpz_clear(pow);
  __gmpz_powm( S, Avu, my_b, my_N );
  __gmpz_clear( Avu );
  sha256_z( S, my_K );
  __gmpz_set( K, my_K );
  have_K = 1;
}

canonical_original_code:
void server_K(struct __mpz_struct K[1])
{
  struct __mpz_struct S[1];
  __gmpz_init( S );
  calc_u();
  ((have_v) ? (void) (0) : __assert_fail ("have_v", "srp.c", 289, __extension__ __PRETTY_FUNCTION__));
  ((have_b) ? (void) (0) : __assert_fail ("have_b", "srp.c", 290, __extension__ __PRETTY_FUNCTION__));
  ((have_A) ? (void) (0) : __assert_fail ("have_A", "srp.c", 291, __extension__ __PRETTY_FUNCTION__));
  ((have_N) ? (void) (0) : __assert_fail ("have_N", "srp.c", 292, __extension__ __PRETTY_FUNCTION__));
  struct __mpz_struct pow[1]; __gmpz_init( pow );
  __gmpz_powm( pow, my_v, my_u, my_N );
  struct __mpz_struct Avu[1]; __gmpz_init( Avu );
  __gmpz_mul( Avu, my_A, pow );
  __gmpz_clear(pow);
  __gmpz_powm( S, Avu, my_b, my_N );
  __gmpz_clear( Avu );
  sha256_z( S, my_K );
  __gmpz_set( K, my_K );
  have_K = 1;
}


decompiled_code:
void __fastcall server_M2(__int64 a1)
{
M2(a1);
}

canonical_decompiled_code:
void __fastcall func16(__int64 a1)
{
func1(a1);
}

original_code:
void server_M2( mpz_t retval )
{
  M2( retval );
}

canonical_original_code:
void server_M2(struct __mpz_struct retval[1])
{
  M2( retval );
}


decompiled_code:
bool __fastcall server_verifyM1(__int64 a1)
{
_BYTE v2[24]; // [rsp+0h] [rbp-18h] BYREF

_gmpz_init(v2);
M1((__int64)v2);
return (unsigned int)_gmpz_cmp(v2, a1) == 0;
}

canonical_decompiled_code:
bool __fastcall func17(__int64 a1)
{
_BYTE v2[24]; // [rsp+0h] [rbp-18h] BYREF

_gmpz_init(v2);
func0((__int64)v2);
return (unsigned int)_gmpz_cmp(v2, a1) == 0;
}

original_code:
_Bool server_verifyM1( mpz_t other_M1 )
{
  mpz_t my_M1; __gmpz_init( my_M1 );
  M1( my_M1 );
  if( __gmpz_cmp( my_M1, other_M1 ) == 0 ) {
    return 1;
  } else {
    return 0;
  }
}

canonical_original_code:
_Bool server_verifyM1(struct __mpz_struct other_M1[1])
{
  struct __mpz_struct my_M1[1]; __gmpz_init( my_M1 );
  M1( my_M1 );
  if( __gmpz_cmp( my_M1, other_M1 ) == 0 ) {
    return 1;
  } else {
    return 0;
  }
}


decompiled_code:
char *__fastcall my_strdup(char *src)
{
size_t v1; // rax
char *v2; // rax
char *v3; // rbx

v1 = strlen(src);
v2 = (char *)malloc(v1 + 1);
v3 = v2;
if ( v2 )
strcpy(v2, src);
return v3;
}

canonical_decompiled_code:
char *__fastcall func0(char *src)
{
size_t v1; // rax
char *v2; // rax
char *v3; // rbx

v1 = strlen(src);
v2 = (char *)malloc(v1 + 1);
v3 = v2;
if ( v2 )
strcpy(v2, src);
return v3;
}

original_code:
inline char *my_strdup(const char *s) {
 char *p = malloc(strlen(s) + 1);
 if(p)
  strcpy(p, s);
 else
  return ((void *)0);
 return p;
}

canonical_original_code:
inline char *my_strdup(char *s) {
 char *p = malloc(strlen(s) + 1);
 if(p)
  strcpy(p, s);
 else
  return ((void *)0);
 return p;
}

variable_types:
s
char *

variable_types:
p
char *

return_type: char *


decompiled_code:
void __fastcall __noreturn print_usage(FILE *stream, int status, const char *a3)
{
fprintf(stream, "Usage: %s OPTIONS\n", a3);
fprintf(
stream,
" -i --input file\tMandatory argument. Input file containing transactions.\n"
" -s --support N\tMinimum support threshold (%%).\n"
" -h --help\t\tPrint this usage information.\n");
exit(status);
}

canonical_decompiled_code:
void __fastcall __noreturn func1(FILE *stream, int status, const char *a3)
{
fprintf(stream, "Usage: %s OPTIONS\n", a3);
fprintf(
stream,
" -i --input file\tMandatory argument. Input file containing transactions.\n"
" -s --support N\tMinimum support threshold (%%).\n"
" -h --help\t\tPrint this usage information.\n");
exit(status);
}

original_code:
void print_usage(const char* program_name) {
 fprintf(stdout, "Usage: %s OPTIONS\n", program_name);
 fprintf(stdout,
     "	-o	--palvelin N		Palvelimen ip osoite.\n"
     "	-p	--portti P		Palvelimen portti.\n"
     "	-t	--tunnus K		Käyttäjätunnus.\n"
     "	-s	--salasana S		Salasana.\n"
     "	-k	--kysely PPPP-NNNNNN	Palvelimelta kysyttävä puhelinnumero (Prefix ja Numero).\n");
 exit(0);
}

canonical_original_code:
void print_usage(char *program_name) {
 fprintf(stdout, "Usage: %s OPTIONS\n", program_name);
 fprintf(stdout,
     "	-o	--palvelin N		Palvelimen ip osoite.\n"
     "	-p	--portti P		Palvelimen portti.\n"
     "	-t	--tunnus K		Käyttäjätunnus.\n"
     "	-s	--salasana S		Salasana.\n"
     "	-k	--kysely PPPP-NNNNNN	Palvelimelta kysyttävä puhelinnumero (Prefix ja Numero).\n");
 exit(0);
}


isnumeric

decompiled_code:
__int64 __fastcall isnumeric(char *a1)
{
char v2; // bl

while ( 1 )
{
v2 = *a1;
if ( !*a1 )
break;
++a1;
if ( ((*_ctype_b_loc())[v2] & 0x800) == 0 )
return 0LL;
}
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func2(char *a1)
{
char v2; // bl

while ( 1 )
{
v2 = *a1;
if ( !*a1 )
break;
++a1;
if ( ((*_ctype_b_loc())[v2] & 0x800) == 0 )
return 0LL;
}
return 1LL;
}

original_code:
int isnumeric(const char *str) {
 while(*str)
  if(!((*__ctype_b_loc ())[(int) ((*(str++)))] & (unsigned short int) _ISdigit))
   return 0;
 return 1;
}

canonical_original_code:
int isnumeric(char *str) {
 while(*str)
  if(!((*__ctype_b_loc ())[(int) ((*(str++)))] & (unsigned short) _ISdigit))
   return 0;
 return 1;
}

variable_types:
str
char *

return_type: int


decompiled_code:
__int64 __fastcall remove_infrequent_items(_DWORD *a1, int a2, int a3)
{
__int64 result; // rax
void *v5; // rbx
__int64 v6; // rax

result = (unsigned int)*a1;
if ( (_DWORD)result )
{
v5 = (void *)list_iterator(a1, 0LL);
while ( list_next(v5) )
{
if ( (float)a2 > (float)((float)((float)*(int *)(list_current(v5) + 8) / (float)a3) * 100.0) )
{
v6 = list_current(v5);
list_remove(a1, v6);
}
}
free(v5);
result = *a1 != 0;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(_DWORD *a1, int a2, int a3)
{
__int64 result; // rax
void *v5; // rbx
__int64 v6; // rax

result = (unsigned int)*a1;
if ( (_DWORD)result )
{
v5 = (void *)list_iterator(a1, 0LL);
while ( list_next(v5) )
{
if ( (float)a2 > (float)((float)((float)*(int *)(list_current(v5) + 8) / (float)a3) * 100.0) )
{
v6 = list_current(v5);
list_remove(a1, v6);
}
}
free(v5);
result = *a1 != 0;
}
return result;
}

original_code:
int remove_infrequent_items(list_p items, int min_sup, int tr_cnt) {
 if(!items->length)
  return 0;
 float sup;
 int cur_sup_cnt;
 set_p cur;
 list_iter_p iter = list_iterator(items, 0);
 while(list_next(iter)) {
  cur = (set_p)list_current(iter);
  cur_sup_cnt = cur->sup_cnt;
  sup = ((float)cur_sup_cnt / (float)tr_cnt) * 100;
  if(sup < min_sup) {
   list_remove(items, (void*)list_current(iter));
  }
 }
 free(iter);
 if(!items->length)
  return 0;
 return 1;
}

canonical_original_code:
int remove_infrequent_items(struct list *items, int min_sup, int tr_cnt) {
 if(!items->length)
  return 0;
 float sup;
 int cur_sup_cnt;
 struct set *cur;
 struct list_iter *iter = list_iterator(items, 0);
 while(list_next(iter)) {
  cur = (struct set *)list_current(iter);
  cur_sup_cnt = cur->sup_cnt;
  sup = ((float)cur_sup_cnt / (float)tr_cnt) * 100;
  if(sup < min_sup) {
   list_remove(items, (void *)list_current(iter));
  }
 }
 free(iter);
 if(!items->length)
  return 0;
 return 1;
}

variable_types: struct list { int length; struct linked_node { void *data; struct linked_node *next; struct linked_node *prev; } *first; struct linked_node *last; void (*destructor)(void *); } *

variable_types: sup float

variable_types: struct set { char *item; int sup_cnt; } *

variable_types: struct list_iter { struct linked_node { void *data; struct linked_node *next; struct linked_node *prev; } *current; char started; } *

user_defined_types: struct list { int length; struct linked_node *first; struct linked_node *last; void (*destructor)(void *); }

user_defined_types: struct list_iter { struct linked_node *current; char started; }


decompiled_code:
_BOOL8 __fastcall find_frequent_items(int *a1, _DWORD *a2, int a3)
{
void *v3; // r15
const char **v4; // rax
const char **v5; // rbx
char *i; // r12
void *v7; // rbp
char *v8; // rax
char *v9; // rax
char *v10; // r14
_DWORD *v11; // rbx

v3 = (void *)list_iterator(a1, 0LL);
while ( list_next(v3) )
{
v8 = (char *)list_current(v3);
v9 = my_strdup(v8);
v10 = v9;
if ( !v9 )
{
perror("malloc");
exit(1);
}
for ( i = strtok(v9, " .,:;"); i; i = strtok(0LL, " .,:;") )
{
v7 = (void *)list_iterator(a2, 0LL);
do
{
v4 = (const char **)list_current(v7);
v5 = v4;
if ( v4 && !strcmp(*v4, i) )
{
++*((_DWORD *)v5 + 2);
free(v7);
goto LABEL_7;
}
}
while ( list_next(v7) );
free(v7);
v11 = malloc(0x10uLL);
*(_QWORD *)v11 = my_strdup(i);
v11[2] = 1;
list_add(a2, v11, 16LL);
free(v11);
LABEL_7:
;
}
free(v10);
}
free(v3);
return (unsigned int)remove_infrequent_items(a2, a3, *a1) != 0;
}

canonical_decompiled_code:
_BOOL8 __fastcall func5(int *a1, _DWORD *a2, int a3)
{
void *v3; // r15
const char **v4; // rax
const char **v5; // rbx
char *i; // r12
void *v7; // rbp
char *v8; // rax
char *v9; // rax
char *v10; // r14
_DWORD *v11; // rbx

v3 = (void *)list_iterator(a1, 0LL);
while ( list_next(v3) )
{
v8 = (char *)list_current(v3);
v9 = func0(v8);
v10 = v9;
if ( !v9 )
{
perror("malloc");
exit(1);
}
for ( i = strtok(v9, " .,:;"); i; i = strtok(0LL, " .,:;") )
{
v7 = (void *)list_iterator(a2, 0LL);
do
{
v4 = (const char **)list_current(v7);
v5 = v4;
if ( v4 && !strcmp(*v4, i) )
{
++*((_DWORD *)v5 + 2);
free(v7);
goto LABEL_7;
}
}
while ( list_next(v7) );
free(v7);
v11 = malloc(0x10uLL);
*(_QWORD *)v11 = func0(i);
v11[2] = 1;
list_add(a2, v11, 16LL);
free(v11);
LABEL_7:
;
}
free(v10);
}
free(v3);
return (unsigned int)func4(a2, a3, *a1) != 0;
}

original_code:
int find_frequent_items(list_p tractions, list_p items, int min_sup) {
 int match;
 char *it, *tr_cp;
 const char* const delims = " .,:;";
 set_p new_set, cur_set;
 list_iter_p iter = list_iterator(tractions, 0);
 list_iter_p it_iter;
 while(list_next(iter)) {
  tr_cp = my_strdup((char*)list_current(iter));
  if(!tr_cp) {
   perror("malloc");
   exit(1);
  }
  it = strtok(tr_cp, delims);
  while(it) {
   it_iter = list_iterator(items, 0);
   do {
    match = 0;
    cur_set = (set_p)list_current(it_iter);
    if(cur_set && (!strcmp(cur_set->item, it))) {
     cur_set->sup_cnt++;
     match = 1;
     break;
    }
   } while(list_next(it_iter));
   free(it_iter);
   if(!match) {
    new_set = (set_p) malloc(sizeof(struct set));
    new_set->item = my_strdup(it);
    new_set->sup_cnt = 1;
    list_add(items, (void*)new_set, sizeof(*new_set));
    free(new_set);
   }
   it = strtok(((void *)0), delims);
  }
  free(tr_cp);
 }
 free(iter);
 if(!remove_infrequent_items(items, min_sup, tractions->length))
  return 0;
 return 1;
}

canonical_original_code:
int find_frequent_items(struct list *tractions, struct list *items, int min_sup) {
 int match;
 char *it; char *tr_cp;
 char *delims = " .,:;";
 struct set *new_set; struct set *cur_set;
 struct list_iter *iter = list_iterator(tractions, 0);
 struct list_iter *it_iter;
 while(list_next(iter)) {
  tr_cp = my_strdup((char *)list_current(iter));
  if(!tr_cp) {
   perror("malloc");
   exit(1);
  }
  it = strtok(tr_cp, delims);
  while(it) {
   it_iter = list_iterator(items, 0);
   do {
    match = 0;
    cur_set = (struct set *)list_current(it_iter);
    if(cur_set && (!strcmp(cur_set->item, it))) {
     cur_set->sup_cnt++;
     match = 1;
     break;
    }
   } while(list_next(it_iter));
   free(it_iter);
   if(!match) {
    new_set = (struct set *) malloc(sizeof(struct set));
    new_set->item = my_strdup(it);
    new_set->sup_cnt = 1;
    list_add(items, (void *)new_set, sizeof(*new_set));
    free(new_set);
   }
   it = strtok(((void *)0), delims);
  }
  free(tr_cp);
 }
 free(iter);
 if(!remove_infrequent_items(items, min_sup, tractions->length))
  return 0;
 return 1;
}

variable_types:
items
struct list *

variable_types: match int

variable_types:
it
char *

variable_types:
delims
char *

user_defined_types: struct linked_node { void *data; struct linked_node *next; struct linked_node *prev; }


original_code:
void find_subsets(list_p items, int set_size, list_p sets, char *arr[], int q, int r) {
 int i;
 set_p new_set;
 char sub[256] = "";
 list_iter_p iter;
 if(q == set_size) {
  for(i=0; i<set_size; i++) {
   if(strlen(sub))
    strcat(sub, ",");
   strcat(sub, arr[i]);
  }
  new_set = (set_p) malloc(sizeof(struct set));
  if(!new_set) {
   perror("malloc:");
   exit(1);
  }
  list_add(sets, (void*)new_set, sizeof(*new_set));
  free(new_set);
  ((set_p)list_last(sets))->item = my_strdup(sub);
  ((set_p)list_last(sets))->sup_cnt = 0;
  *sub = '\0';
 }
 else {
  i = 0;
  iter = list_iterator(items, 0);
  while(i != r) {
   list_next(iter);
   i++;
  }
  while(list_next(iter)) {
   arr[q]=((set_p)list_current(iter))->item;
   find_subsets(items, set_size, sets, arr, q+1, i+1);
   i++;
  }
  free(iter);
 }
}

canonical_original_code:
void find_subsets(struct list *items, int set_size, struct list *sets, char *arr[], int q, int r) {
 int i;
 struct set *new_set;
 char sub[256] = "";
 struct list_iter *iter;
 if(q == set_size) {
  for(i=0; i<set_size; i++) {
   if(strlen(sub))
    strcat(sub, ",");
   strcat(sub, arr[i]);
  }
  new_set = (struct set *) malloc(sizeof(struct set));
  if(!new_set) {
   perror("malloc:");
   exit(1);
  }
  list_add(sets, (void *)new_set, sizeof(*new_set));
  free(new_set);
  ((struct set *)list_last(sets))->item = my_strdup(sub);
  ((struct set *)list_last(sets))->sup_cnt = 0;
  *sub = '\0';
 }
 else {
  i = 0;
  iter = list_iterator(items, 0);
  while(i != r) {
   list_next(iter);
   i++;
  }
  while(list_next(iter)) {
   arr[q]=((struct set *)list_current(iter))->item;
   find_subsets(items, set_size, sets, arr, q+1, i+1);
   i++;
  }
  free(iter);
 }
}

variable_types:
sets
struct list *

variable_types:
arr
char *[]

variable_types: q int

variable_types: r int

variable_types:
sub
char [256]


decompiled_code:
void __fastcall remove_unused(_DWORD *a1, _DWORD *a2)
{
void *v2; // rbp
__int64 v3; // rax
void *v4; // rbx
const char *v5; // r14
const char **v6; // rax

v2 = (void *)list_iterator(a1, 0LL);
if ( *a1 && *a2 )
{
while ( list_next(v2) )
{
v4 = (void *)list_iterator(a2, 0LL);
if ( list_current(v4) )
{
while ( list_next(v4) )
{
v5 = *(const char **)list_current(v4);
v6 = (const char **)list_current(v2);
if ( strstr(*v6, v5) )
goto LABEL_5;
}
v3 = list_current(v2);
list_remove(a1, v3);
}
LABEL_5:
free(v4);
}
}
free(v2);
}

canonical_decompiled_code:
void __fastcall func7(_DWORD *a1, _DWORD *a2)
{
void *v2; // rbp
__int64 v3; // rax
void *v4; // rbx
const char *v5; // r14
const char **v6; // rax

v2 = (void *)list_iterator(a1, 0LL);
if ( *a1 && *a2 )
{
while ( list_next(v2) )
{
v4 = (void *)list_iterator(a2, 0LL);
if ( list_current(v4) )
{
while ( list_next(v4) )
{
v5 = *(const char **)list_current(v4);
v6 = (const char **)list_current(v2);
if ( strstr(*v6, v5) )
goto LABEL_5;
}
v3 = list_current(v2);
list_remove(a1, v3);
}
LABEL_5:
free(v4);
}
}
free(v2);
}

original_code:
void remove_unused(list_p from, list_p in) {
 list_iter_p from_iter = list_iterator(from, 0);
 list_iter_p in_iter;
 int found;
 if(from->length && in->length) {
  while(list_next(from_iter)) {
   in_iter = list_iterator(in, 0);
   if(list_current(in_iter) != ((void *)0)) {
    found = 0;
    while(list_next(in_iter)) {
     if(strstr(((set_p)list_current(from_iter))->item, ((set_p)list_current(in_iter))->item)) {
      found = 1;
      break;
     }
    }
    if(!found) {
     list_remove(from, (void*)list_current(from_iter));
    }
   }
   free(in_iter);
  }
 }
 free(from_iter);
}

canonical_original_code:
void remove_unused(struct list *from, struct list *in) {
 struct list_iter *from_iter = list_iterator(from, 0);
 struct list_iter *in_iter;
 int found;
 if(from->length && in->length) {
  while(list_next(from_iter)) {
   in_iter = list_iterator(in, 0);
   if(list_current(in_iter) != ((void *)0)) {
    found = 0;
    while(list_next(in_iter)) {
     if(strstr(((struct set *)list_current(from_iter))->item, ((struct set *)list_current(in_iter))->item)) {
      found = 1;
      break;
     }
    }
    if(!found) {
     list_remove(from, (void *)list_current(from_iter));
    }
   }
   free(in_iter);
  }
 }
 free(from_iter);
}

variable_types:
in
struct list *

variable_types: found int


decompiled_code:
__int64 __fastcall remove_infrequent_subsets(_DWORD *a1, _DWORD *a2, __int64 a3, int a4)
{
_DWORD *v6; // r13
void *v7; // r12
void *v8; // rsp
void *v9; // rbx
const char *v10; // r15
const char **v11; // rax
__int64 v12; // rax
const char *v14; // [rsp+0h] [rbp-30h] BYREF

v6 = (_DWORD *)create_list();
v7 = (void *)list_iterator(a3, 0LL);
v8 = alloca(8LL * (*a1 + 1));
find_subsets((__int64)a1, a4, (__int64)v6, &v14, 0, 0);
while ( list_next(v7) )
{
v9 = (void *)list_iterator(v6, 0LL);
while ( list_next(v9) )
{
v10 = *(const char **)list_current(v9);
v11 = (const char **)list_current(v7);
if ( !strcmp(*v11, v10) )
{
v12 = list_current(v9);
list_remove(v6, v12);
}
}
free(v9);
}
free(v7);
remove_unused(a2, v6);
return destroy_list(v6);
}

canonical_decompiled_code:
__int64 __fastcall func8(_DWORD *a1, _DWORD *a2, __int64 a3, int a4)
{
_DWORD *v6; // r13
void *v7; // r12
void *v8; // rsp
void *v9; // rbx
const char *v10; // r15
const char **v11; // rax
__int64 v12; // rax
const char *v14; // [rsp+0h] [rbp-30h] BYREF

v6 = (_DWORD *)create_list();
v7 = (void *)list_iterator(a3, 0LL);
v8 = alloca(8LL * (*a1 + 1));
func6((__int64)a1, a4, (__int64)v6, &v14, 0, 0);
while ( list_next(v7) )
{
v9 = (void *)list_iterator(v6, 0LL);
while ( list_next(v9) )
{
v10 = *(const char **)list_current(v9);
v11 = (const char **)list_current(v7);
if ( !strcmp(*v11, v10) )
{
v12 = list_current(v9);
list_remove(v6, v12);
}
}
free(v9);
}
free(v7);
func7(a2, v6);
return destroy_list(v6);
}

original_code:
void remove_infrequent_subsets(list_p items, list_p sets, list_p prev_freq_sets, int size) {
 list_p subsets = create_list();
 list_iter_p sub_iter;
 list_iter_p pset_iter = list_iterator(prev_freq_sets, 0);
 char *arr[items->length + 1];
 find_subsets(items, size, subsets, arr, 0, 0);
 while(list_next(pset_iter)) {
  sub_iter = list_iterator(subsets, 0);
  while(list_next(sub_iter)) {
   if(!strcmp(((set_p)list_current(pset_iter))->item, ((set_p)list_current(sub_iter))->item)) {
    list_remove(subsets, (void*)list_current(sub_iter));
   }
  }
  free(sub_iter);
 }
 free(pset_iter);
 remove_unused(sets, subsets);
 destroy_list(subsets);
}

canonical_original_code:
void remove_infrequent_subsets(struct list *items, struct list *sets, struct list *prev_freq_sets, int size) {
 struct list *subsets = create_list();
 struct list_iter *sub_iter;
 struct list_iter *pset_iter = list_iterator(prev_freq_sets, 0);
 char *arr[-1];
 find_subsets(items, size, subsets, arr, 0, 0);
 while(list_next(pset_iter)) {
  sub_iter = list_iterator(subsets, 0);
  while(list_next(sub_iter)) {
   if(!strcmp(((struct set *)list_current(pset_iter))->item, ((struct set *)list_current(sub_iter))->item)) {
    list_remove(subsets, (void *)list_current(sub_iter));
   }
  }
  free(sub_iter);
 }
 free(pset_iter);
 remove_unused(sets, subsets);
 destroy_list(subsets);
}

variable_types: size int

variable_types:
arr
char *[-1]


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

result = malloc(0x20uLL);
*(_DWORD *)result = 0;
result[1] = 0LL;
result[2] = 0LL;
result[3] = &free;
return result;
}

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

result = malloc(0x20uLL);
*(_DWORD *)result = 0;
result[1] = 0LL;
result[2] = 0LL;
result[3] = &free;
return result;
}

original_code:
list_p create_list(){
 list_p list = (list_p) malloc(sizeof(struct list));
 list->length = 0;
 list->first = ((void *)0);
 list->last = ((void *)0);
 list->destructor = free;
 return list;
}

canonical_original_code:
struct list *create_list(){
 struct list *list = (list_p) malloc(sizeof(struct list));
 list->length = 0;
 list->first = ((void *)0);
 list->last = ((void *)0);
 list->destructor = free;
 return list;
}

variable_types: struct list { int length; struct linked_node { void *data; struct linked_node *next; struct linked_node *prev; } *first; struct linked_node *last; void (*destructor)(void *); } *


decompiled_code:
__int64 __fastcall list_first(__int64 a1)
{
return **(_QWORD **)(a1 + 8);
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1)
{
return **(_QWORD **)(a1 + 8);
}

original_code:
void* list_first(list_p list){
 return list->first->data;
}

canonical_original_code:
void *list_first(struct list *list){
 return list->first->data;
}

return_type: void *


decompiled_code:
__int64 __fastcall list_last(__int64 a1)
{
return **(_QWORD **)(a1 + 16);
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1)
{
return **(_QWORD **)(a1 + 16);
}

original_code:
void* list_last(list_p list){
 return list->last->data;
}

canonical_original_code:
void *list_last(struct list *list){
 return list->last->data;
}


original_code:
void* list_pop(list_p list){
 lnode_p last = list->last;
 if(last == ((void *)0))
  return ((void *)0);
 void* data = last->data;
 if(last->prev) {
  list->last = last->prev;
  last->prev->next = ((void *)0);
 }
 free(last);
 return data;
}

canonical_original_code:
void *list_pop(struct list *list){
 struct linked_node *last = list->last;
 if(last == ((void *)0))
  return ((void *)0);
 void *data = last->data;
 if(last->prev) {
  list->last = last->prev;
  last->prev->next = ((void *)0);
 }
 free(last);
 return data;
}

variable_types: struct linked_node { void *data; struct linked_node *next; struct linked_node *prev; } *

variable_types:
data
void *


original_code:
void* list_poll(list_p list){
 lnode_p first = list->first;
 if(!first)
  return ((void *)0);
 void* data = first->data;
 if(first->next) {
  list->first = first->next;
  first->next->prev = ((void *)0);
 }
 free(first);
 return data;
}

canonical_original_code:
void *list_poll(struct list *list){
 struct linked_node *first = list->first;
 if(!first)
  return ((void *)0);
 void *data = first->data;
 if(first->next) {
  list->first = first->next;
  first->next->prev = ((void *)0);
 }
 free(first);
 return data;
}


decompiled_code:
void __fastcall destroy_list(void *ptr)
{
_QWORD *v1; // rbx
_QWORD *v2; // r12

v1 = (_QWORD *)*((_QWORD *)ptr + 1);
while ( v1 )
{
v2 = v1;
v1 = (_QWORD *)v1[1];
if ( *(_DWORD *)ptr )
{
(*((void (__fastcall **)(_QWORD))ptr + 3))(*v2);
free(v2);
}
}
free(ptr);
}

canonical_decompiled_code:
void __fastcall func6(void *ptr)
{
_QWORD *v1; // rbx
_QWORD *v2; // r12

v1 = (_QWORD *)*((_QWORD *)ptr + 1);
while ( v1 )
{
v2 = v1;
v1 = (_QWORD *)v1[1];
if ( *(_DWORD *)ptr )
{
(*((void (__fastcall **)(_QWORD))ptr + 3))(*v2);
free(v2);
}
}
free(ptr);
}

original_code:
void destroy_list(list_p list) {
 lnode_p cur = list->first;
 lnode_p next;
 while(cur) {
  next = cur->next;
  if(list->length != 0) {
   list->destructor(cur->data);
   free(cur);
  }
  cur = next;
 }
 free(list);
}

canonical_original_code:
void destroy_list(struct list *list) {
 struct linked_node *cur = list->first;
 struct linked_node *next;
 while(cur) {
  next = cur->next;
  if(list->length != 0) {
   list->destructor(cur->data);
   free(cur);
  }
  cur = next;
 }
 free(list);
}


original_code:
void* list_remove_middle(lnode_p node) {
 void *data = node->data;
 node->prev->next = node->next;
 node->next->prev = node->prev;
 free(node);
 return data;
}

canonical_original_code:
void *list_remove_middle(struct linked_node *node) {
 void *data = node->data;
 node->prev->next = node->next;
 node->next->prev = node->prev;
 free(node);
 return data;
}


decompiled_code:
__int64 __fastcall list_remove(__int64 a1, __int64 a2)
{
__int64 result; // rax
__int64 *v4; // rdi
__int64 v5; // rdi

result = *(_QWORD *)(a1 + 8);
if ( result )
{
v4 = *(__int64 **)(a1 + 8);
while ( *v4 != a2 )
{
v4 = (__int64 *)v4[1];
if ( !v4 )
return result;
}
if ( (__int64 *)result == v4 )
{
result = list_poll(a1);
v5 = result;
}
else
{
if ( *(__int64 **)(a1 + 16) == v4 )
result = list_pop(a1);
else
result = list_remove_middle(v4);
v5 = result;
}
if ( v5 )
{
result = (*(__int64 (**)(void))(a1 + 24))();
--*(_DWORD *)a1;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func8(__int64 a1, __int64 a2)
{
__int64 result; // rax
__int64 *v4; // rdi
__int64 v5; // rdi

result = *(_QWORD *)(a1 + 8);
if ( result )
{
v4 = *(__int64 **)(a1 + 8);
while ( *v4 != a2 )
{
v4 = (__int64 *)v4[1];
if ( !v4 )
return result;
}
if ( (__int64 *)result == v4 )
{
result = func5(a1);
v5 = result;
}
else
{
if ( *(__int64 **)(a1 + 16) == v4 )
result = func4(a1);
else
result = func7(v4);
v5 = result;
}
if ( v5 )
{
result = (*(__int64 (**)(void))(a1 + 24))();
--*(_DWORD *)a1;
}
}
return result;
}

original_code:
void list_remove(list_p list, void *data) {
 void *tmp = ((void *)0);
 lnode_p cur = list->first;
 if(!cur) {
  return;
 }
 while(cur) {
  if(cur->data == data) {
   if(cur == list->first) {
    tmp = list_poll(list);
    break;
   }
   else if(cur == list->last) {
    tmp = list_pop(list);
    break;
   }
   else {
    tmp = list_remove_middle(cur);
    break;
   }
  }
  cur = cur->next;
 }
 if(tmp) {
  list->destructor(tmp);
  list->length--;
 }
}

canonical_original_code:
void list_remove(struct list *list, void *data) {
 void *tmp = ((void *)0);
 struct linked_node *cur = list->first;
 if(!cur) {
  return;
 }
 while(cur) {
  if(cur->data == data) {
   if(cur == list->first) {
    tmp = list_poll(list);
    break;
   }
   else if(cur == list->last) {
    tmp = list_pop(list);
    break;
   }
   else {
    tmp = list_remove_middle(cur);
    break;
   }
  }
  cur = cur->next;
 }
 if(tmp) {
  list->destructor(tmp);
  list->length--;
 }
}

variable_types:
tmp
void *


panic

decompiled_code:
void __fastcall __noreturn panic(const char *a1)
{
perror(a1);
exit(1);
}

canonical_decompiled_code:
void __fastcall __noreturn func0(const char *a1)
{
perror(a1);
exit(1);
}

original_code:
void panic(char* str)
{
  perror(str);
  exit(1);
}

canonical_original_code:
void panic(char *str)
{
  perror(str);
  exit(1);
}

variable_types:
str
char *


decompiled_code:
void __fastcall sha256_update_mpz(__int64 a1, __int64 a2)
{
__int64 v2; // rax
void *v3; // rbx
__int64 v4[4]; // [rsp+10h] [rbp-20h] BYREF

v4[0] = 0LL;
v2 = _gmpz_export(0LL, v4, 1LL, 1LL, 0LL, 0LL, a2);
if ( !v2 )
panic("sha256_update_mpz export");
v3 = (void *)v2;
nettle_sha256_update(a1, v4[0], v2);
free(v3);
}

canonical_decompiled_code:
void __fastcall func2(__int64 a1, __int64 a2)
{
__int64 v2; // rax
void *v3; // rbx
__int64 v4[4]; // [rsp+10h] [rbp-20h] BYREF

v4[0] = 0LL;
v2 = _gmpz_export(0LL, v4, 1LL, 1LL, 0LL, 0LL, a2);
if ( !v2 )
func0("sha256_update_mpz export");
v3 = (void *)v2;
nettle_sha256_update(a1, v4[0], v2);
free(v3);
}

original_code:
void sha256_update_mpz( struct sha256_ctx* context, const mpz_t luku )
{
  size_t luku_len = 0;
  void* luku_data = __gmpz_export( ((void *)0), &luku_len, 1, 1, 0, 0, luku );
  if( luku_data == ((void *)0) ) panic( "sha256_update_mpz export" );
  nettle_sha256_update( context, luku_len, luku_data );
  free( luku_data );
}

canonical_original_code:
void sha256_update_mpz(struct sha256_ctx *context, struct __mpz_struct luku[1])
{
  unsigned long luku_len = 0;
  void *luku_data = __gmpz_export( ((void *)0), &luku_len, 1, 1, 0, 0, luku );
  if( luku_data == ((void *)0) ) panic( "sha256_update_mpz export" );
  nettle_sha256_update( context, luku_len, luku_data );
  free( luku_data );
}

variable_types: struct sha256_ctx { unsigned int state[8]; unsigned long count; unsigned char block[64]; unsigned int index; } *

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


decompiled_code:
__int64 __fastcall sha256_s(const char *a1, __int64 a2)
{
size_t v2; // rbp
_BYTE v4[112]; // [rsp+0h] [rbp-A8h] BYREF
char v5[56]; // [rsp+70h] [rbp-38h] BYREF

if ( !a1 )
_assert_fail("s != NULL", "util.c", 0x49u, "sha256_s");
v2 = strlen(a1);
if ( !v2 )
_assert_fail("s_len > 0", "util.c", 0x4Eu, "sha256_s");
nettle_sha256_init(v4);
nettle_sha256_update(v4, v2, a1);
nettle_sha256_digest(v4, 32LL, v5);
return _gmpz_import(a2, 32LL, 1LL, 1LL, 0LL, 0LL, v5);
}

canonical_decompiled_code:
__int64 __fastcall func3(const char *a1, __int64 a2)
{
size_t v2; // rbp
_BYTE v4[112]; // [rsp+0h] [rbp-A8h] BYREF
char v5[56]; // [rsp+70h] [rbp-38h] BYREF

if ( !a1 )
_assert_fail("s != NULL", "util.c", 0x49u, "sha256_s");
v2 = strlen(a1);
if ( !v2 )
_assert_fail("s_len > 0", "util.c", 0x4Eu, "sha256_s");
nettle_sha256_init(v4);
nettle_sha256_update(v4, v2, a1);
nettle_sha256_digest(v4, 32LL, v5);
return _gmpz_import(a2, 32LL, 1LL, 1LL, 0LL, 0LL, v5);
}

original_code:
void sha256_s( const unsigned char* const s, mpz_t retval )
{
  unsigned char digest[32];
  ((s != ((void *)0)) ? (void) (0) : __assert_fail ("s != NULL", "util.c", 73, __extension__ __PRETTY_FUNCTION__));
  { struct sha256_ctx sha_puskuri;
    size_t s_len = strlen( (char*) s );
    ((s_len > 0) ? (void) (0) : __assert_fail ("s_len > 0", "util.c", 78, __extension__ __PRETTY_FUNCTION__));
    nettle_sha256_init( &sha_puskuri );
    nettle_sha256_update( &sha_puskuri, s_len, s );
    nettle_sha256_digest( &sha_puskuri, 32, digest );
  }
  __gmpz_import( retval, 32, 1, 1, 0, 0, digest );
}

canonical_original_code:
void sha256_s(unsigned char *s, struct __mpz_struct retval[1])
{
  unsigned char digest[32];
  ((s != ((void *)0)) ? (void) (0) : __assert_fail ("s != NULL", "util.c", 73, __extension__ __PRETTY_FUNCTION__));
  { struct sha256_ctx sha_puskuri;
    unsigned long s_len = strlen( (char*) s );
    ((s_len > 0) ? (void) (0) : __assert_fail ("s_len > 0", "util.c", 78, __extension__ __PRETTY_FUNCTION__));
    nettle_sha256_init( &sha_puskuri );
    nettle_sha256_update( &sha_puskuri, s_len, s );
    nettle_sha256_digest( &sha_puskuri, 32, digest );
  }
  __gmpz_import( retval, 32, 1, 1, 0, 0, digest );
}

variable_types:
s
unsigned char *

variable_types:
digest
unsigned char [32]

variable_types: struct sha256_ctx { unsigned int state[8]; unsigned long count; unsigned char block[64]; unsigned int index; }


decompiled_code:
__int64 __fastcall sha256_zs(__int64 a1, const char *a2, __int64 a3)
{
size_t v4; // r12
_BYTE v6[112]; // [rsp+0h] [rbp-B8h] BYREF
char v7[72]; // [rsp+70h] [rbp-48h] BYREF

if ( !a2 )
_assert_fail("s != NULL", "util.c", 0x65u, "sha256_zs");
if ( !(unsigned int)_gmpz_cmpabs_ui(a1, 0LL) )
_assert_fail("mpz_cmpabs_ui( z, 0 ) != 0", "util.c", 0x66u, "sha256_zs");
v4 = strlen(a2);
if ( !v4 )
_assert_fail("s_len > 0", "util.c", 0x6Bu, "sha256_zs");
nettle_sha256_init(v6);
sha256_update_mpz((__int64)v6, a1);
nettle_sha256_update(v6, v4, a2);
nettle_sha256_digest(v6, 32LL, v7);
return _gmpz_import(a3, 32LL, 1LL, 1LL, 0LL, 0LL, v7);
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1, const char *a2, __int64 a3)
{
size_t v4; // r12
_BYTE v6[112]; // [rsp+0h] [rbp-B8h] BYREF
char v7[72]; // [rsp+70h] [rbp-48h] BYREF

if ( !a2 )
_assert_fail("s != NULL", "util.c", 0x65u, "sha256_zs");
if ( !(unsigned int)_gmpz_cmpabs_ui(a1, 0LL) )
_assert_fail("mpz_cmpabs_ui( z, 0 ) != 0", "util.c", 0x66u, "sha256_zs");
v4 = strlen(a2);
if ( !v4 )
_assert_fail("s_len > 0", "util.c", 0x6Bu, "sha256_zs");
nettle_sha256_init(v6);
func2((__int64)v6, a1);
nettle_sha256_update(v6, v4, a2);
nettle_sha256_digest(v6, 32LL, v7);
return _gmpz_import(a3, 32LL, 1LL, 1LL, 0LL, 0LL, v7);
}

original_code:
void sha256_zs( mpz_t z, const unsigned char* const s, mpz_t retval )
{
  unsigned char digest[32];
  ((s != ((void *)0)) ? (void) (0) : __assert_fail ("s != NULL", "util.c", 101, __extension__ __PRETTY_FUNCTION__));
  ((__gmpz_cmpabs_ui( z, 0 ) != 0) ? (void) (0) : __assert_fail ("mpz_cmpabs_ui( z, 0 ) != 0", "util.c", 102, __extension__ __PRETTY_FUNCTION__));
  { struct sha256_ctx sha_puskuri;
    size_t s_len = strlen( (char*) s );
    ((s_len > 0) ? (void) (0) : __assert_fail ("s_len > 0", "util.c", 107, __extension__ __PRETTY_FUNCTION__));
    nettle_sha256_init( &sha_puskuri );
    sha256_update_mpz( &sha_puskuri, z );
    nettle_sha256_update( &sha_puskuri, s_len, s );
    nettle_sha256_digest( &sha_puskuri, 32, digest );
  }
  __gmpz_import( retval, 32, 1, 1, 0, 0, digest );
}

canonical_original_code:
void sha256_zs(struct __mpz_struct z[1], unsigned char *s, struct __mpz_struct retval[1])
{
  unsigned char digest[32];
  ((s != ((void *)0)) ? (void) (0) : __assert_fail ("s != NULL", "util.c", 101, __extension__ __PRETTY_FUNCTION__));
  ((__gmpz_cmpabs_ui( z, 0 ) != 0) ? (void) (0) : __assert_fail ("mpz_cmpabs_ui( z, 0 ) != 0", "util.c", 102, __extension__ __PRETTY_FUNCTION__));
  { struct sha256_ctx sha_puskuri;
    unsigned long s_len = strlen( (char*) s );
    ((s_len > 0) ? (void) (0) : __assert_fail ("s_len > 0", "util.c", 107, __extension__ __PRETTY_FUNCTION__));
    nettle_sha256_init( &sha_puskuri );
    sha256_update_mpz( &sha_puskuri, z );
    nettle_sha256_update( &sha_puskuri, s_len, s );
    nettle_sha256_digest( &sha_puskuri, 32, digest );
  }
  __gmpz_import( retval, 32, 1, 1, 0, 0, digest );
}

variable_types:
retval
struct __mpz_struct [1]

user_defined_types: struct sha256_ctx { unsigned int state[8]; unsigned long count; unsigned char block[64]; unsigned int index; }


decompiled_code:
__int64 __fastcall sha256_z(__int64 a1, __int64 a2)
{
_BYTE v3[112]; // [rsp+0h] [rbp-A8h] BYREF
char v4[56]; // [rsp+70h] [rbp-38h] BYREF

if ( !(unsigned int)_gmpz_cmpabs_ui(a1, 0LL) )
_assert_fail("mpz_cmpabs_ui( a, 0 ) != 0", "util.c", 0x82u, "sha256_z");
nettle_sha256_init(v3);
sha256_update_mpz((__int64)v3, a1);
nettle_sha256_digest(v3, 32LL, v4);
return _gmpz_import(a2, 32LL, 1LL, 1LL, 0LL, 0LL, v4);
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1, __int64 a2)
{
_BYTE v3[112]; // [rsp+0h] [rbp-A8h] BYREF
char v4[56]; // [rsp+70h] [rbp-38h] BYREF

if ( !(unsigned int)_gmpz_cmpabs_ui(a1, 0LL) )
_assert_fail("mpz_cmpabs_ui( a, 0 ) != 0", "util.c", 0x82u, "sha256_z");
nettle_sha256_init(v3);
func2((__int64)v3, a1);
nettle_sha256_digest(v3, 32LL, v4);
return _gmpz_import(a2, 32LL, 1LL, 1LL, 0LL, 0LL, v4);
}

original_code:
void sha256_z( mpz_t a, mpz_t retval )
{
  unsigned char digest[32];
  ((__gmpz_cmpabs_ui( a, 0 ) != 0) ? (void) (0) : __assert_fail ("mpz_cmpabs_ui( a, 0 ) != 0", "util.c", 130, __extension__ __PRETTY_FUNCTION__));
  { struct sha256_ctx sha_puskuri;
    nettle_sha256_init( &sha_puskuri );
    sha256_update_mpz( &sha_puskuri, a );
    nettle_sha256_digest( &sha_puskuri, 32, digest );
  }
  __gmpz_import( retval, 32, 1, 1, 0, 0, digest );
}

canonical_original_code:
void sha256_z(struct __mpz_struct a[1], struct __mpz_struct retval[1])
{
  unsigned char digest[32];
  ((__gmpz_cmpabs_ui( a, 0 ) != 0) ? (void) (0) : __assert_fail ("mpz_cmpabs_ui( a, 0 ) != 0", "util.c", 130, __extension__ __PRETTY_FUNCTION__));
  { struct sha256_ctx sha_puskuri;
    nettle_sha256_init( &sha_puskuri );
    sha256_update_mpz( &sha_puskuri, a );
    nettle_sha256_digest( &sha_puskuri, 32, digest );
  }
  __gmpz_import( retval, 32, 1, 1, 0, 0, digest );
}


decompiled_code:
__int64 __fastcall sha256_zz(__int64 a1, __int64 a2, __int64 a3)
{
_BYTE v5[112]; // [rsp+0h] [rbp-A8h] BYREF
char v6[56]; // [rsp+70h] [rbp-38h] BYREF

if ( !(unsigned int)_gmpz_cmpabs_ui(a1, 0LL) )
_assert_fail("mpz_cmpabs_ui( a, 0 ) != 0", "util.c", 0x9Bu, "sha256_zz");
nettle_sha256_init(v5);
sha256_update_mpz((__int64)v5, a1);
sha256_update_mpz((__int64)v5, a2);
nettle_sha256_digest(v5, 32LL, v6);
return _gmpz_import(a3, 32LL, 1LL, 1LL, 0LL, 0LL, v6);
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1, __int64 a2, __int64 a3)
{
_BYTE v5[112]; // [rsp+0h] [rbp-A8h] BYREF
char v6[56]; // [rsp+70h] [rbp-38h] BYREF

if ( !(unsigned int)_gmpz_cmpabs_ui(a1, 0LL) )
_assert_fail("mpz_cmpabs_ui( a, 0 ) != 0", "util.c", 0x9Bu, "sha256_zz");
nettle_sha256_init(v5);
func2((__int64)v5, a1);
func2((__int64)v5, a2);
nettle_sha256_digest(v5, 32LL, v6);
return _gmpz_import(a3, 32LL, 1LL, 1LL, 0LL, 0LL, v6);
}

original_code:
void sha256_zz( mpz_t a, mpz_t b, mpz_t retval )
{
  unsigned char digest[32];
  ((__gmpz_cmpabs_ui( a, 0 ) != 0) ? (void) (0) : __assert_fail ("mpz_cmpabs_ui( a, 0 ) != 0", "util.c", 155, __extension__ __PRETTY_FUNCTION__));
  ((__gmpz_cmpabs_ui( a, 0 ) != 0) ? (void) (0) : __assert_fail ("mpz_cmpabs_ui( a, 0 ) != 0", "util.c", 156, __extension__ __PRETTY_FUNCTION__));
  { struct sha256_ctx sha_puskuri;
    nettle_sha256_init( &sha_puskuri );
    sha256_update_mpz( &sha_puskuri, a );
    sha256_update_mpz( &sha_puskuri, b );
    nettle_sha256_digest( &sha_puskuri, 32, digest );
  }
  __gmpz_import( retval, 32, 1, 1, 0, 0, digest );
}

canonical_original_code:
void sha256_zz(struct __mpz_struct a[1], struct __mpz_struct b[1], struct __mpz_struct retval[1])
{
  unsigned char digest[32];
  ((__gmpz_cmpabs_ui( a, 0 ) != 0) ? (void) (0) : __assert_fail ("mpz_cmpabs_ui( a, 0 ) != 0", "util.c", 155, __extension__ __PRETTY_FUNCTION__));
  ((__gmpz_cmpabs_ui( a, 0 ) != 0) ? (void) (0) : __assert_fail ("mpz_cmpabs_ui( a, 0 ) != 0", "util.c", 156, __extension__ __PRETTY_FUNCTION__));
  { struct sha256_ctx sha_puskuri;
    nettle_sha256_init( &sha_puskuri );
    sha256_update_mpz( &sha_puskuri, a );
    sha256_update_mpz( &sha_puskuri, b );
    nettle_sha256_digest( &sha_puskuri, 32, digest );
  }
  __gmpz_import( retval, 32, 1, 1, 0, 0, digest );
}

variable_types:
b
struct __mpz_struct [1]


decompiled_code:
void *__fastcall sha256_binz(__int64 a1)
{
void *v1; // rax
void *v2; // rbx
_BYTE v4[136]; // [rsp+0h] [rbp-88h] BYREF

v1 = malloc(0x21uLL);
if ( !v1 )
panic("malloc failed");
v2 = v1;
if ( !(unsigned int)_gmpz_cmpabs_ui(a1, 0LL) )
_assert_fail("mpz_cmpabs_ui( a, 0 ) != 0", "util.c", 0xB9u, "sha256_binz");
nettle_sha256_init(v4);
sha256_update_mpz((__int64)v4, a1);
nettle_sha256_digest(v4, 32LL, v2);
return v2;
}

canonical_decompiled_code:
void *__fastcall func7(__int64 a1)
{
void *v1; // rax
void *v2; // rbx
_BYTE v4[136]; // [rsp+0h] [rbp-88h] BYREF

v1 = malloc(0x21uLL);
if ( !v1 )
func0("malloc failed");
v2 = v1;
if ( !(unsigned int)_gmpz_cmpabs_ui(a1, 0LL) )
_assert_fail("mpz_cmpabs_ui( a, 0 ) != 0", "util.c", 0xB9u, "sha256_binz");
nettle_sha256_init(v4);
func2((__int64)v4, a1);
nettle_sha256_digest(v4, 32LL, v2);
return v2;
}

original_code:
BYTE* sha256_binz( mpz_t a )
{
  BYTE* retval = malloc( 32 + 1 );
  if( retval == ((void *)0) ) {
    panic("malloc failed");
  }
  ((__gmpz_cmpabs_ui( a, 0 ) != 0) ? (void) (0) : __assert_fail ("mpz_cmpabs_ui( a, 0 ) != 0", "util.c", 185, __extension__ __PRETTY_FUNCTION__));
  { struct sha256_ctx sha_puskuri;
    nettle_sha256_init( &sha_puskuri );
    sha256_update_mpz( &sha_puskuri, a );
    nettle_sha256_digest( &sha_puskuri, 32, retval );
  }
  return retval;
}

canonical_original_code:
unsigned char *sha256_binz(struct __mpz_struct a[1])
{
  unsigned char *retval = malloc( 32 + 1 );
  if( retval == ((void *)0) ) {
    panic("malloc failed");
  }
  ((__gmpz_cmpabs_ui( a, 0 ) != 0) ? (void) (0) : __assert_fail ("mpz_cmpabs_ui( a, 0 ) != 0", "util.c", 185, __extension__ __PRETTY_FUNCTION__));
  { struct sha256_ctx sha_puskuri;
    nettle_sha256_init( &sha_puskuri );
    sha256_update_mpz( &sha_puskuri, a );
    nettle_sha256_digest( &sha_puskuri, 32, retval );
  }
  return retval;
}

variable_types:
retval
unsigned char *

return_type: unsigned char *


main

canonical_name: main

decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
InitKernel(argc, argv, envp);
mymain();
}

canonical_decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
func25(argc, argv, envp);
func19();
}

original_code:
int main(void)
{
  InitKernel();
  ;
  mymain();
  return 0;
}

canonical_original_code:
int main()
{
  InitKernel();
  ;
  mymain();
  return 0;
}


myprint

decompiled_code:
int __fastcall myprint(const char *a1)
{
return printf(a1);
}

canonical_decompiled_code:
int __fastcall func7(const char *a1)
{
return printf(a1);
}

original_code:
void myprint(char *text)
{
  printf(text);
}

variable_types:
text
char *


InitTD

decompiled_code:
int __fastcall InitTD(_DWORD *a1, int a2, int a3, int a4)
{
int result; // eax

if ( !a1 )
return myprint("Tried to initialize NULL pointer\n");
a1[4] = a2;
a1[3] = a3;
a1[5] = 3;
a1[6] = a4;
return result;
}

canonical_decompiled_code:
int __fastcall func8(_DWORD *a1, int a2, int a3, int a4)
{
int result; // eax

if ( !a1 )
return func7("Tried to initialize NULL pointer\n");
a1[4] = a2;
a1[3] = a3;
a1[5] = 3;
a1[6] = a4;
return result;
}

original_code:
void InitTD(TD *td, uval32 pc, uval32 sp, uval32 priority)
{
  if(td != ((void *)0)) {
    td->regs.pc = pc;
    td->regs.sp = sp;
    td->regs.sr = 0x0003;
    td->priority = priority;
  } else {
    myprint("Tried to initialize NULL pointer\n");
  }
}

canonical_original_code:
void InitTD(struct type_TD *td, unsigned int pc, unsigned int sp, unsigned int priority)
{
  if(td != ((void *)0)) {
    td->regs.pc = pc;
    td->regs.sp = sp;
    td->regs.sr = 0x0003;
    td->priority = priority;
  } else {
    myprint("Tried to initialize NULL pointer\n");
  }
}

variable_types: struct type_TD { struct type_TD *link; unsigned int tid; struct type_REGS { unsigned int sp; unsigned int pc; unsigned int sr; } regs; unsigned int priority; int waittime; enum RC { RC_SUCCESS=0, RC_FAILED=1 } returnCode; struct type_LL { struct type_TD *head; struct type_TD *tail; enum ListType { UNDEF=0, L_PRIORITY=1, L_LIFO=2, L_WAITING=3, L_CIRCULAR=4 } type; } *inlist; } *

variable_types:
pc
unsigned int

variable_types:
sp
unsigned int

variable_types:
priority
unsigned int

user_defined_types: struct type_TD { struct type_TD *link; unsigned int tid; struct type_REGS regs; unsigned int priority; int waittime; enum RC returnCode; struct type_LL *inlist; }

user_defined_types: struct type_LL { struct type_TD *head; struct type_TD *tail; enum ListType type; }


FreeQEnqueue

original_code:
int FreeQEnqueue(TD *td, LL *list) {
 if ((list->head != ((void *)0)) && (list->tail != ((void *)0))) {
  list->tail->link = td;
  td->link = list->head;
  list->tail = td;
  return 0;
 } else {
  list->head = td;
  list->tail = td;
  td->link = td;
  return 0;
 }
 return 1;
}

canonical_original_code:
int FreeQEnqueue(struct type_TD *td, struct type_LL *list) {
 if ((list->head != ((void *)0)) && (list->tail != ((void *)0))) {
  list->tail->link = td;
  td->link = list->head;
  list->tail = td;
  return 0;
 } else {
  list->head = td;
  list->tail = td;
  td->link = td;
  return 0;
 }
 return 1;
}

variable_types:
list
struct type_LL *

user_defined_types: struct type_REGS { unsigned int sp; unsigned int pc; unsigned int sr; }

user_defined_types: enum ListType { UNDEF=0, L_PRIORITY=1, L_LIFO=2, L_WAITING=3, L_CIRCULAR=4 }


FreeQDequeue

decompiled_code:
__int64 __fastcall FreeQDequeue(__int64 **a1)
{
__int64 *v1; // rax
__int64 *v2; // rdx
__int64 v3; // rcx
__int64 result; // rax

v1 = *a1;
v2 = a1[1];
if ( *a1 == v2 )
{
*a1 = 0LL;
a1[1] = 0LL;
result = *((unsigned int *)v1 + 2);
}
else if ( v2 && v1 )
{
v3 = *v1;
*a1 = (__int64 *)*v1;
*v2 = v3;
result = *((unsigned int *)v1 + 2);
}
else
{
result = 0LL;
}
return result;
}

original_code:
int FreeQDequeue(LL *list) {
 if (list->head == list->tail) {
  TD *head = list->head;
  list->head = ((void *)0);
  list->tail = ((void *)0);
  return head->tid;
 } else if ((list->head != ((void *)0)) && (list->tail != ((void *)0))) {
  TD *head = list->head;
  list->head = list->head->link;
  list->tail->link = list->head;
  return head->tid;
 } else {
  return 0;
 }
}

canonical_original_code:
int FreeQDequeue(struct type_LL *list) {
 if (list->head == list->tail) {
  struct type_TD *head = list->head;
  list->head = ((void *)0);
  list->tail = ((void *)0);
  return head->tid;
 } else if ((list->head != ((void *)0)) && (list->tail != ((void *)0))) {
  struct type_TD *head = list->head;
  list->head = list->head->link;
  list->tail->link = list->head;
  return head->tid;
 } else {
  return 0;
 }
}

variable_types: struct type_LL { struct type_TD { struct type_TD *link; unsigned int tid; struct type_REGS { unsigned int sp; unsigned int pc; unsigned int sr; } regs; unsigned int priority; int waittime; enum RC { RC_SUCCESS=0, RC_FAILED=1 } returnCode; struct type_LL *inlist; } *head; struct type_TD *tail; enum ListType { UNDEF=0, L_PRIORITY=1, L_LIFO=2, L_WAITING=3, L_CIRCULAR=4 } type; } *


Dequeue

decompiled_code:
__int64 __fastcall Dequeue(__int64 *a1, __int64 *a2)
{
__int64 result; // rax
_QWORD *v3; // rdx

result = *a2;
if ( !*a2 )
return 0LL;
if ( (__int64 *)result == a1 )
{
*a2 = *a1;
result = 1LL;
}
else
{
while ( 1 )
{
v3 = (_QWORD *)result;
result = *(_QWORD *)result;
if ( !result )
break;
if ( (__int64 *)result == a1 )
{
*v3 = *a1;
return 1LL;
}
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func11(__int64 *a1, __int64 *a2)
{
__int64 result; // rax
_QWORD *v3; // rdx

result = *a2;
if ( !*a2 )
return 0LL;
if ( (__int64 *)result == a1 )
{
*a2 = *a1;
result = 1LL;
}
else
{
while ( 1 )
{
v3 = (_QWORD *)result;
result = *(_QWORD *)result;
if ( !result )
break;
if ( (__int64 *)result == a1 )
{
*v3 = *a1;
return 1LL;
}
}
}
return result;
}

original_code:
int Dequeue( TD *td, LL *list ) {
 TD * ptr;
 if ((ptr = list->head) == ((void *)0)) {
  return 0;
 } else if (ptr == td) {
  list->head = td->link;
  return 1;
 } else {
  while (ptr->link != ((void *)0)) {
   if (ptr->link == td) {
    ptr->link = td->link;
    return 1;
   }
   ptr = ptr->link;
  }
 }
 return 0;
}

canonical_original_code:
int Dequeue(struct type_TD *td, struct type_LL *list) {
 struct type_TD *ptr;
 if ((ptr = list->head) == ((void *)0)) {
  return 0;
 } else if (ptr == td) {
  list->head = td->link;
  return 1;
 } else {
  while (ptr->link != ((void *)0)) {
   if (ptr->link == td) {
    ptr->link = td->link;
    return 1;
   }
   ptr = ptr->link;
  }
 }
 return 0;
}


DestroyList

decompiled_code:
__int64 __fastcall DestroyList(void *ptr)
{
_QWORD *v1; // rax

if ( !ptr )
return 1LL;
while ( *(_QWORD *)ptr )
{
v1 = DequeueHead((_QWORD **)ptr);
free(v1);
}
free(ptr);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func12(void *ptr)
{
_QWORD *v1; // rax

if ( !ptr )
return 1LL;
while ( *(_QWORD *)ptr )
{
v1 = DequeueHead((_QWORD **)ptr);
free(v1);
}
free(ptr);
return 0LL;
}

original_code:
RC DestroyList( LL *list )
{
  if(!list){
    return RC_FAILED;
  }
  if(list->head){
    TD* current = list->head;
    while(current){
      TD* old_head = DequeueHead(list);
      free(old_head);
      current = list->head;
    }
  }
  if (!list->head) {
    free(list);
    return RC_SUCCESS;
  }
  free(list);
  return RC_FAILED;
}

canonical_original_code:
enum RC DestroyList(struct type_LL *list)
{
  if(!list){
    return RC_FAILED;
  }
  if(list->head){
    struct type_TD *current = list->head;
    while(current){
      struct type_TD *old_head = DequeueHead(list);
      free(old_head);
      current = list->head;
    }
  }
  if (!list->head) {
    free(list);
    return RC_SUCCESS;
  }
  free(list);
  return RC_FAILED;
}

return_type: enum RC { RC_SUCCESS=0, RC_FAILED=1 }


PriorityEnqueue

original_code:
RC PriorityEnqueue(TD *td, LL *list)
{
  TD *cur, *prev;
    if(!td || !list || list->type != L_PRIORITY){
      return RC_FAILED;
    }
    td->inlist = list;
    if(!list->head){
      list->head = td;
    } else{
      prev = ((void *)0);
      cur = list->head;
      while(cur){
        if(cur->priority >= td->priority){
          if(!prev){
            td->link = list->head;
            list->head = td;
          } else{
            td->link = cur;
            prev->link = td;
          }
          break;
        }
        prev = cur;
        cur = cur->link;
      }
    }
    return RC_SUCCESS;
}

canonical_original_code:
enum RC PriorityEnqueue(struct type_TD *td, struct type_LL *list)
{
  struct type_TD *cur; struct type_TD *prev;
    if(!td || !list || list->type != L_PRIORITY){
      return RC_FAILED;
    }
    td->inlist = list;
    if(!list->head){
      list->head = td;
    } else{
      prev = ((void *)0);
      cur = list->head;
      while(cur){
        if(cur->priority >= td->priority){
          if(!prev){
            td->link = list->head;
            list->head = td;
          } else{
            td->link = cur;
            prev->link = td;
          }
          break;
        }
        prev = cur;
        cur = cur->link;
      }
    }
    return RC_SUCCESS;
}


EnqueueAtHead

decompiled_code:
__int64 __fastcall EnqueueAtHead(_QWORD *a1, __int64 a2)
{
__int64 result; // rax

if ( !a1 || !a2 )
return 1LL;
result = 1LL;
if ( *(_DWORD *)(a2 + 16) == 2 )
{
*a1 = *(_QWORD *)a2;
*(_QWORD *)a2 = a1;
a1[5] = a2;
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func14(_QWORD *a1, __int64 a2)
{
__int64 result; // rax

if ( !a1 || !a2 )
return 1LL;
result = 1LL;
if ( *(_DWORD *)(a2 + 16) == 2 )
{
*a1 = *(_QWORD *)a2;
*(_QWORD *)a2 = a1;
a1[5] = a2;
result = 0LL;
}
return result;
}

original_code:
RC EnqueueAtHead(TD *td, LL *list)
{
    if(!td || !list || list->type != L_LIFO){
      return RC_FAILED;
    }
    td->link = list->head;
    list->head = td;
    td->inlist = list;
    return RC_SUCCESS;
}

canonical_original_code:
enum RC EnqueueAtHead(struct type_TD *td, struct type_LL *list)
{
    if(!td || !list || list->type != L_LIFO){
      return RC_FAILED;
    }
    td->link = list->head;
    list->head = td;
    td->inlist = list;
    return RC_SUCCESS;
}


WaitlistEnqueue

original_code:
RC WaitlistEnqueue(TD *td, int waittime, LL *list)
{
    TD *cur, *prev;
    if(!td || !list){
      return RC_FAILED;
    }
    if(list->type != L_WAITING){
      return RC_FAILED;
    }
    if (list->head == ((void *)0)) {
    list->head = td;
  } else if (waittime < (list->head)->waittime){
    td->link = list->head;
    list->head = td;
  } else {
    prev = list->head;
    cur = prev->link;
    waittime -= prev->waittime;
    while ((cur != ((void *)0)) && (waittime > cur->waittime))
    {
      prev = cur;
          cur = cur->link;
      waittime -= prev->waittime;
      }
      if (cur != ((void *)0)) {
      td->link = prev->link;
      prev->link = td;
    } else {
          prev->link = td;
    }
  }
  td->inlist = list;
  td->waittime = waittime;
  waitDiff(td->link, waittime);
  return RC_SUCCESS;
}

canonical_original_code:
enum RC WaitlistEnqueue(struct type_TD *td, int waittime, struct type_LL *list)
{
    struct type_TD *cur; struct type_TD *prev;
    if(!td || !list){
      return RC_FAILED;
    }
    if(list->type != L_WAITING){
      return RC_FAILED;
    }
    if (list->head == ((void *)0)) {
    list->head = td;
  } else if (waittime < (list->head)->waittime){
    td->link = list->head;
    list->head = td;
  } else {
    prev = list->head;
    cur = prev->link;
    waittime -= prev->waittime;
    while ((cur != ((void *)0)) && (waittime > cur->waittime))
    {
      prev = cur;
          cur = cur->link;
      waittime -= prev->waittime;
      }
      if (cur != ((void *)0)) {
      td->link = prev->link;
      prev->link = td;
    } else {
          prev->link = td;
    }
  }
  td->inlist = list;
  td->waittime = waittime;
  waitDiff(td->link, waittime);
  return RC_SUCCESS;
}

variable_types: waittime int


DequeueTD

original_code:
void DequeueTD(TD* td){
  if(!td){
    return;
  }
  if (td->inlist) {
    if(td->inlist->head == td){
      td->inlist->head = td->link;
    } else {
      TD *prev, *next;
      prev = FindPrevTD(td->tid, td->inlist);
      next = prev->link->link;
      prev->link = next;
    }
  }
}

canonical_original_code:
void DequeueTD(struct type_TD *td){
  if(!td){
    return;
  }
  if (td->inlist) {
    if(td->inlist->head == td){
      td->inlist->head = td->link;
    } else {
      struct type_TD *prev; struct type_TD *next;
      prev = FindPrevTD(td->tid, td->inlist);
      next = prev->link->link;
      prev->link = next;
    }
  }
}


SysCall

decompiled_code:
__int64 __fastcall SysCall(__int64 a1, unsigned int a2, unsigned int a3, unsigned int a4)
{
myprint("Here\n");
CreateThread(a2, a3, a4);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func18(__int64 a1, unsigned int a2, unsigned int a3, unsigned int a4)
{
func7("Here\n");
func26(a2, a3, a4);
return 0LL;
}

original_code:
RC SysCall(SysCallType type, uval32 arg0, uval32 arg1, uval32 arg2)
{
  uval32 returnCode;
  myprint("Here\n");
  CreateThread(arg0, arg1, arg2);
  returnCode = RC_SUCCESS;
  return returnCode;
}

canonical_original_code:
enum RC SysCall(enum SysCallType type, unsigned int arg0, unsigned int arg1, unsigned int arg2)
{
  unsigned int returnCode;
  myprint("Here\n");
  CreateThread(arg0, arg1, arg2);
  returnCode = RC_SUCCESS;
  return returnCode;
}

variable_types: enum SysCallType { SYS_CREATE=0, SYS_DIST=1, SYS_YIELD=2, SYS_SUSP=3, SYS_RESUME=4, SYS_CHANGE_PRI=5 }

variable_types:
returnCode
unsigned int


mymain

decompiled_code:
void __noreturn mymain()
{
if ( (unsigned int)SysCall(0LL, 0x1234u, 0, 0) )
__assert_fail("ret == RC_SUCCESS", "user.c", 0x2Fu, "mymain");
myprint("DONE\n");
while ( 1 )
;
}

canonical_decompiled_code:
void __noreturn func19()
{
if ( (unsigned int)func18(0LL, 0x1234u, 0, 0) )
__assert_fail("ret == RC_SUCCESS", "user.c", 0x2Fu, "mymain");
func7("DONE\n");
while ( 1 )
;
}

original_code:
void mymain()
{
  RC ret;
  ret = SysCall(SYS_CREATE, 0x1234, 0, 0);
  ((void) sizeof ((ret == RC_SUCCESS) ? 1 : 0), __extension__ ({ if (ret == RC_SUCCESS) ; else __assert_fail ("ret == RC_SUCCESS", "user.c", 47, __extension__ __PRETTY_FUNCTION__); }));
  myprint("DONE\n");
  while(1);
}

canonical_original_code:
void mymain()
{
  enum RC ret;
  ret = SysCall(SYS_CREATE, 0x1234, 0, 0);
  ((void) sizeof ((ret == RC_SUCCESS) ? 1 : 0), __extension__ ({ if (ret == RC_SUCCESS) ; else __assert_fail ("ret == RC_SUCCESS", "user.c", 47, __extension__ __PRETTY_FUNCTION__); }));
  myprint("DONE\n");
  while(1);
}

variable_types:
ret
enum RC { RC_SUCCESS=0, RC_FAILED=1 }


getTid

decompiled_code:
__int64 getTid()
{
return FreeQDequeue((__int64 **)FreeQ);
}

canonical_decompiled_code:
__int64 func20()
{
return func10((__int64 **)FreeQ);
}

original_code:
uval32 getTid(){
 return FreeQDequeue(FreeQ);
}

canonical_original_code:
unsigned int getTid(){
 return FreeQDequeue(FreeQ);
}

return_type: unsigned int


tidInUse

decompiled_code:
__int64 __fastcall tidInUse(int a1)
{
__int64 result; // rax
_QWORD *v2; // rdx
_QWORD *v3; // rax

result = 0LL;
if ( (unsigned int)(a1 - 1) <= 0x3FF )
{
v2 = *(_QWORD **)FreeQ;
result = 1LL;
if ( *(_DWORD *)(*(_QWORD *)FreeQ + 24LL) != a1 )
{
v3 = (_QWORD *)*v2;
if ( v2 == (_QWORD *)*v2 )
{
result = 0LL;
}
else
{
while ( *((_DWORD *)v3 + 6) != a1 )
{
v3 = (_QWORD *)*v3;
if ( v2 == v3 )
return 0LL;
}
result = 1LL;
}
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func21(int a1)
{
__int64 result; // rax
_QWORD *v2; // rdx
_QWORD *v3; // rax

result = 0LL;
if ( (unsigned int)(a1 - 1) <= 0x3FF )
{
v2 = *(_QWORD **)FreeQ;
result = 1LL;
if ( *(_DWORD *)(*(_QWORD *)FreeQ + 24LL) != a1 )
{
v3 = (_QWORD *)*v2;
if ( v2 == (_QWORD *)*v2 )
{
result = 0LL;
}
else
{
while ( *((_DWORD *)v3 + 6) != a1 )
{
v3 = (_QWORD *)*v3;
if ( v2 == v3 )
return 0LL;
}
result = 1LL;
}
}
}
return result;
}

original_code:
int tidInUse(ThreadId tid) {
 if ((tid > 1024) || (tid < 1)) {
  return 0;
 } else {
  TD *ptr = FreeQ->head;
  if (ptr->priority == tid) {
   return 1;
  } else {
   ptr = ptr->link;
  }
  while (ptr != FreeQ->head) {
   if (ptr->priority == tid) {
    return 1;
   } else {
    ptr = ptr->link;
   }
  }
  return 0;
 }
}

canonical_original_code:
int tidInUse(unsigned int tid) {
 if ((tid > 1024) || (tid < 1)) {
  return 0;
 } else {
  struct type_TD *ptr = FreeQ->head;
  if (ptr->priority == tid) {
   return 1;
  } else {
   ptr = ptr->link;
  }
  while (ptr != FreeQ->head) {
   if (ptr->priority == tid) {
    return 1;
   } else {
    ptr = ptr->link;
   }
  }
  return 0;
 }
}

variable_types:
tid
unsigned int


ChangeThreadPriority

decompiled_code:
__int64 __fastcall ChangeThreadPriority(int a1, int a2)
{
int v2; // edx
__int64 result; // rax
__int64 *v4; // rbx

v2 = tidInUse(a1);
result = 3LL;
if ( v2 )
{
v4 = getTD(a1);
*((_DWORD *)v4 + 6) = a2;
result = 6LL;
if ( v4[5] == ReadyQ )
{
if ( (unsigned int)Dequeue(v4, (__int64 *)ReadyQ) )
PriorityEnqueue(v4, (__int64 **)ReadyQ);
else
myprint("Dequeue error\n");
result = 6LL;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func22(int a1, int a2)
{
int v2; // edx
__int64 result; // rax
__int64 *v4; // rbx

v2 = func21(a1);
result = 3LL;
if ( v2 )
{
v4 = getTD(a1);
*((_DWORD *)v4 + 6) = a2;
result = 6LL;
if ( v4[5] == ReadyQ )
{
if ( (unsigned int)func11(v4, (__int64 *)ReadyQ) )
func13(v4, (__int64 **)ReadyQ);
else
func7("Dequeue error\n");
result = 6LL;
}
}
return result;
}

original_code:
T_RC ChangeThreadPriority(ThreadId tid, int newPriority) {
 TD * td;
 if (!tidInUse(tid)) {
  return TID_ERROR;
 } else {
  td = getTD(tid);
 }
 if ((newPriority < 1) & (newPriority > 128)) {
  return PRIORITY_ERROR;
 }
 td->priority = newPriority;
 if (td->inlist == ReadyQ){
  if (Dequeue(td, ReadyQ)) {
   PriorityEnqueue(td, ReadyQ);
  } else {
   myprint("Dequeue error\n");
  }
 }
 return OK;
}

canonical_original_code:
enum T_RC ChangeThreadPriority(unsigned int tid, int newPriority) {
 struct type_TD *td;
 if (!tidInUse(tid)) {
  return TID_ERROR;
 } else {
  td = getTD(tid);
 }
 if ((newPriority < 1) & (newPriority > 128)) {
  return PRIORITY_ERROR;
 }
 td->priority = newPriority;
 if (td->inlist == ReadyQ){
  if (Dequeue(td, ReadyQ)) {
   PriorityEnqueue(td, ReadyQ);
  } else {
   myprint("Dequeue error\n");
  }
 }
 return OK;
}

variable_types: newPriority int

return_type: enum T_RC { RESOURCE_ERROR=0, STACK_ERROR=1, PRIORITY_ERROR=2, TID_ERROR=3, NOT_BLOCKED=4, FAILED=5, OK=6 }


DestroyThread

decompiled_code:
__int64 __fastcall DestroyThread(int a1)
{
__int64 *v2; // rdi
_QWORD *v3; // rax

if ( !a1 || *(_DWORD *)(Active + 8) == a1 )
{
Active = 0LL;
Active = (__int64)DequeueHead((_QWORD **)ReadyQ);
}
v2 = FindTD(a1, (__int64 **)ReadyQ);
if ( !v2 )
{
v2 = FindTD(a1, (__int64 **)BlockedQ);
if ( !v2 )
return 3LL;
}
DequeueTD((__int64)v2);
v3 = CreateTD(a1);
EnqueueAtHead(v3, FreeQ);
return 6LL;
}

canonical_decompiled_code:
__int64 __fastcall func23(int a1)
{
__int64 *v2; // rdi
_QWORD *v3; // rax

if ( !a1 || *(_DWORD *)(Active + 8) == a1 )
{
Active = 0LL;
Active = (__int64)DequeueHead((_QWORD **)ReadyQ);
}
v2 = FindTD(a1, (__int64 **)ReadyQ);
if ( !v2 )
{
v2 = FindTD(a1, (__int64 **)BlockedQ);
if ( !v2 )
return 3LL;
}
func17((__int64)v2);
v3 = CreateTD(a1);
func14(v3, FreeQ);
return 6LL;
}

original_code:
T_RC DestroyThread(ThreadId tid) {
 TD* td_tid;
 if (tid == 0 || tid == Active->tid) {
  Active = ((void *)0);
  Active = DequeueHead(ReadyQ);
 }
 if ((td_tid = FindTD(tid, ReadyQ)) == ((void *)0)) {
  if ((td_tid = FindTD(tid, BlockedQ)) == ((void *)0)) {
   return TID_ERROR;
  }
 }
 DequeueTD(td_tid);
 td_tid = CreateTD(tid);
 EnqueueAtHead(td_tid, FreeQ);
 return OK;
}

canonical_original_code:
enum T_RC DestroyThread(unsigned int tid) {
 struct type_TD *td_tid;
 if (tid == 0 || tid == Active->tid) {
  Active = ((void *)0);
  Active = DequeueHead(ReadyQ);
 }
 if ((td_tid = FindTD(tid, ReadyQ)) == ((void *)0)) {
  if ((td_tid = FindTD(tid, BlockedQ)) == ((void *)0)) {
   return TID_ERROR;
  }
 }
 DequeueTD(td_tid);
 td_tid = CreateTD(tid);
 EnqueueAtHead(td_tid, FreeQ);
 return OK;
}

user_defined_types: enum T_RC { RESOURCE_ERROR=0, STACK_ERROR=1, PRIORITY_ERROR=2, TID_ERROR=3, NOT_BLOCKED=4, FAILED=5, OK=6 }


Yield

decompiled_code:
__int64 Yield()
{
PriorityEnqueue((__int64 *)Active, (__int64 **)ReadyQ);
Active = (__int64)DequeueHead((_QWORD **)ReadyQ);
return 6LL;
}

canonical_decompiled_code:
__int64 func24()
{
func13((__int64 *)Active, (__int64 **)ReadyQ);
Active = (__int64)DequeueHead((_QWORD **)ReadyQ);
return 6LL;
}

canonical_original_code:
enum T_RC Yield() {
 PriorityEnqueue(Active, ReadyQ);
 Active = DequeueHead(ReadyQ);
 return OK;
}


InitKernel

decompiled_code:
__int64 InitKernel()
{
__int64 *v0; // rbx
int v1; // ebp
_DWORD *v2; // rbx

ReadyQ = (__int64)CreateList(1);
BlockedQ = (__int64)CreateList(0);
FreeQ = (__int64)CreateList(4);
v0 = (__int64 *)CreateTD(1);
InitTD(v0, (int)Idle, (int)&Kernel, 128);
PriorityEnqueue(v0, (__int64 **)ReadyQ);
v1 = 0;
do
{
v2 = CreateTD(++v1);
InitTD(v2, 0, 0, 0);
FreeQEnqueue(v2, (_QWORD *)FreeQ);
}
while ( v1 != 1024 );
return Yield();
}

canonical_decompiled_code:
__int64 func25()
{
__int64 *v0; // rbx
int v1; // ebp
_DWORD *v2; // rbx

ReadyQ = (__int64)CreateList(1);
BlockedQ = (__int64)CreateList(0);
FreeQ = (__int64)CreateList(4);
v0 = (__int64 *)CreateTD(1);
func8(v0, (int)Idle, (int)&Kernel, 128);
func13(v0, (__int64 **)ReadyQ);
v1 = 0;
do
{
v2 = CreateTD(++v1);
func8(v2, 0, 0, 0);
func9(v2, (_QWORD *)FreeQ);
}
while ( v1 != 1024 );
return func24();
}

original_code:
void InitKernel(void) {
 int i;
 ReadyQ = CreateList(L_PRIORITY);
 BlockedQ = CreateList(UNDEF);
 FreeQ = CreateList(L_CIRCULAR);
 TD* idle_td = CreateTD(1);
 InitTD(idle_td, (uval32) Idle, (uval32) &(KernelStack.stack[8192]), 128);
 PriorityEnqueue(idle_td, ReadyQ);
 for(i=0;i<1024;i++){
  TD* free_td;
  free_td = CreateTD(i+1);
  InitTD(free_td, 0,0,0);
  FreeQEnqueue(free_td, FreeQ);
 }
 Yield();
}

canonical_original_code:
void InitKernel() {
 int i;
 ReadyQ = CreateList(L_PRIORITY);
 BlockedQ = CreateList(UNDEF);
 FreeQ = CreateList(L_CIRCULAR);
 struct type_TD *idle_td = CreateTD(1);
 InitTD(idle_td, (unsigned int) Idle, (uval32) &(KernelStack.stack[8192]), 128);
 PriorityEnqueue(idle_td, ReadyQ);
 for(i=0;i<1024;i++){
  struct type_TD *free_td;
  free_td = CreateTD(i+1);
  InitTD(free_td, 0,0,0);
  FreeQEnqueue(free_td, FreeQ);
 }
 Yield();
}

variable_types: i int