euclidianGCD

repo: warpling/RSA-Security-Assignment

decompiled_code:
size_t __fastcall euclidianGCD(__int64 a1, __int64 a2, __int64 a3)
{
size_t result; // rax
int v5; // [rsp+14h] [rbp-34h]

__gmpz_init();
__gmpz_init();
if ( *(int *)(a2 + 4) <= 0 || *(int *)(a3 + 4) <= 0 )
return fwrite("Cannot calculate GCD of non positive integer. GCD has not been set.\n", 1uLL, 0x44uLL, _bss_start);
if ( (int)__gmpz_cmp() < 0 )
{
__gmpz_set();
__gmpz_set();
__gmpz_set();
}
while ( 1 )
{
__gmpz_tdiv_qr();
if ( !v5 )
break;
__gmpz_set();
result = __gmpz_set();
if ( v5 <= 0 )
return result;
}
return __gmpz_set();
}

canonical_decompiled_code:
size_t __fastcall func7(__int64 a1, __int64 a2, __int64 a3)
{
size_t result; // rax
int v5; // [rsp+14h] [rbp-34h]

__gmpz_init();
__gmpz_init();
if ( *(int *)(a2 + 4) <= 0 || *(int *)(a3 + 4) <= 0 )
return fwrite("Cannot calculate GCD of non positive integer. GCD has not been set.\n", 1uLL, 0x44uLL, _bss_start);
if ( (int)__gmpz_cmp() < 0 )
{
__gmpz_set();
__gmpz_set();
__gmpz_set();
}
while ( 1 )
{
__gmpz_tdiv_qr();
if ( !v5 )
break;
__gmpz_set();
result = __gmpz_set();
if ( v5 <= 0 )
return result;
}
return __gmpz_set();
}

original_code:
void euclidianGCD(mpz_t *gcd, mpz_t numA, mpz_t numB) {
    mpz_t quotient; __gmpz_init(quotient);
    mpz_t remainder; __gmpz_init(remainder);
    if ((__builtin_constant_p (0) && (0) == 0 ? ((numA)->_mp_size < 0 ? -1 : (numA)->_mp_size > 0) : __gmpz_cmp_ui (numA,0)) <= 0 || (__builtin_constant_p (0) && (0) == 0 ? ((numB)->_mp_size < 0 ? -1 : (numB)->_mp_size > 0) : __gmpz_cmp_ui (numB,0)) <= 0) {
        fprintf(stderr, "Cannot calculate GCD of non positive integer. GCD has not been set.\n");
        return;
    }
    if (__gmpz_cmp(numA, numB) < 0) {
        mpz_t temp;
        __gmpz_set(temp, numA);
        __gmpz_set(numA, numB);
        __gmpz_set(numB, temp);
    }
    do {
        __gmpz_tdiv_qr(quotient, remainder, numA, numB);
        if((__builtin_constant_p (0) && (0) == 0 ? ((remainder)->_mp_size < 0 ? -1 : (remainder)->_mp_size > 0) : __gmpz_cmp_ui (remainder,0)) == 0) {
            __gmpz_set(*gcd, numB);
            return;
        }
        else {
            __gmpz_set(numA, numB);
            __gmpz_set(numB, remainder);
        }
    } while ((__builtin_constant_p (0) && (0) == 0 ? ((remainder)->_mp_size < 0 ? -1 : (remainder)->_mp_size > 0) : __gmpz_cmp_ui (remainder,0)) > 0);
}

canonical_original_code:
void euclidianGCD(struct __mpz_struct (*gcd)[1], struct __mpz_struct numA[1], struct __mpz_struct numB[1]) {
    struct __mpz_struct quotient[1]; __gmpz_init(quotient);
    struct __mpz_struct remainder[1]; __gmpz_init(remainder);
    if ((__builtin_constant_p (0) && (0) == 0 ? ((numA)->_mp_size < 0 ? -1 : (numA)->_mp_size > 0) : __gmpz_cmp_ui (numA,0)) <= 0 || (__builtin_constant_p (0) && (0) == 0 ? ((numB)->_mp_size < 0 ? -1 : (numB)->_mp_size > 0) : __gmpz_cmp_ui (numB,0)) <= 0) {
        fprintf(stderr, "Cannot calculate GCD of non positive integer. GCD has not been set.\n");
        return;
    }
    if (__gmpz_cmp(numA, numB) < 0) {
        struct __mpz_struct temp[1];
        __gmpz_set(temp, numA);
        __gmpz_set(numA, numB);
        __gmpz_set(numB, temp);
    }
    do {
        __gmpz_tdiv_qr(quotient, remainder, numA, numB);
        if((__builtin_constant_p (0) && (0) == 0 ? ((remainder)->_mp_size < 0 ? -1 : (remainder)->_mp_size > 0) : __gmpz_cmp_ui (remainder,0)) == 0) {
            __gmpz_set(*gcd, numB);
            return;
        }
        else {
            __gmpz_set(numA, numB);
            __gmpz_set(numB, remainder);
        }
    } while ((__builtin_constant_p (0) && (0) == 0 ? ((remainder)->_mp_size < 0 ? -1 : (remainder)->_mp_size > 0) : __gmpz_cmp_ui (remainder,0)) > 0);
}

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

variable_types:
numA
struct __mpz_struct [1]

variable_types:
numB
struct __mpz_struct [1]

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


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v4; // [rsp+0h] [rbp-38h] BYREF
char v5[16]; // [rsp+10h] [rbp-28h] BYREF
char v6[24]; // [rsp+20h] [rbp-18h] BYREF

__gmpz_init();
__gmpz_init();
__gmpz_init();
__gmp_printf();
__gmp_scanf();
__gmp_printf();
__gmp_scanf();
__gmp_printf();
euclidianGCD((__int64)&v4, (__int64)v6, (__int64)v5);
__gmp_printf();
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v4; // [rsp+0h] [rbp-38h] BYREF
char v5[16]; // [rsp+10h] [rbp-28h] BYREF
char v6[24]; // [rsp+20h] [rbp-18h] BYREF

__gmpz_init();
__gmpz_init();
__gmpz_init();
__gmp_printf();
__gmp_scanf();
__gmp_printf();
__gmp_scanf();
__gmp_printf();
func7((__int64)&v4, (__int64)v6, (__int64)v5);
__gmp_printf();
return 0;
}

original_code:
int main(int argc, char const *argv[])
{
    mpz_t numA, numB, gcd;
    __gmpz_init(numA);
    __gmpz_init(numB);
    __gmpz_init(gcd);
    __gmp_printf("Input first number: ");
    __gmp_scanf("%Zd", numA);
    __gmp_printf("Input second number: ");
    __gmp_scanf("%Zd", numB);
    __gmp_printf("GDC of %Zd and %Zd is ", numA, numB);
    euclidianGCD(&gcd, numA, numB);
    __gmp_printf(" %Zd!\n", gcd);
    return 0;
}

canonical_original_code:
int main(int argc, char *argv[])
{
    struct __mpz_struct numA[1]; struct __mpz_struct numB[1]; struct __mpz_struct gcd[1];
    __gmpz_init(numA);
    __gmpz_init(numB);
    __gmpz_init(gcd);
    __gmp_printf("Input first number: ");
    __gmp_scanf("%Zd", numA);
    __gmp_printf("Input second number: ");
    __gmp_scanf("%Zd", numB);
    __gmp_printf("GDC of %Zd and %Zd is ", numA, numB);
    euclidianGCD(&gcd, numA, numB);
    __gmp_printf(" %Zd!\n", gcd);
    return 0;
}

variable_types: argc int

variable_types:
argv
char *[]

return_type: int

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


repo: wartalker/flowers-by-opengl

decompiled_code:
__int64 __fastcall glcreate_shader(const char *a1, unsigned int a2)
{
__int64 v2; // rbx
unsigned int v4; // er12
char *v5; // rbp
const char *v6; // [rsp+8h] [rbp-30h] BYREF
int v7; // [rsp+18h] [rbp-20h] BYREF
int v8[7]; // [rsp+1Ch] [rbp-1Ch] BYREF

v6 = a1;
v2 = (unsigned int)glCreateShader(a2);
glShaderSource(v2, 1LL, &v6, 0LL);
glCompileShader((unsigned int)v2);
glGetShaderiv((unsigned int)v2, 35713LL, v8);
if ( !v8[0] )
{
glGetShaderiv((unsigned int)v2, 35716LL, &v7);
v4 = v7;
v5 = (char *)malloc(v7);
glGetShaderInfoLog((unsigned int)v2, v4, 0LL, v5);
fprintf(stdout, "%s\n\n%s", v5, v6);
free(v5);
if ( !v8[0] )
LODWORD(v2) = 0;
}
return (unsigned int)v2;
}

canonical_decompiled_code:
__int64 __fastcall func0(const char *a1, unsigned int a2)
{
__int64 v2; // rbx
unsigned int v4; // er12
char *v5; // rbp
const char *v6; // [rsp+8h] [rbp-30h] BYREF
int v7; // [rsp+18h] [rbp-20h] BYREF
int v8[7]; // [rsp+1Ch] [rbp-1Ch] BYREF

v6 = a1;
v2 = (unsigned int)glCreateShader(a2);
glShaderSource(v2, 1LL, &v6, 0LL);
glCompileShader((unsigned int)v2);
glGetShaderiv((unsigned int)v2, 35713LL, v8);
if ( !v8[0] )
{
glGetShaderiv((unsigned int)v2, 35716LL, &v7);
v4 = v7;
v5 = (char *)malloc(v7);
glGetShaderInfoLog((unsigned int)v2, v4, 0LL, v5);
fprintf(stdout, "%s\n\n%s", v5, v6);
free(v5);
if ( !v8[0] )
LODWORD(v2) = 0;
}
return (unsigned int)v2;
}

original_code:
static glshader
glcreate_shader(const glchar * src, glshader_type type) {
 glshader shid;
 glbool status;
 GLint n;
 char * log;
 shid = glCreateShader(type);
 glShaderSource(shid, 1, (const GLchar**)&src, ((void *)0));
 glCompileShader(shid);
 glGetShaderiv(shid, 0x8B81, &status);
 if (!status) {
  glGetShaderiv(shid, 0x8B84, &n);
  log = (char *) malloc(n);
  glGetShaderInfoLog(shid, n, ((void *)0), log);
  fprintf(stdout, "%s\n\n%s", log, src);
  free(log);
 }
 return (!status) ? 0 : shid;
}

canonical_original_code:
static unsigned int glcreate_shader(char *src, unsigned int type) {
 unsigned int shid;
 int status;
 int n;
 char *log;
 shid = glCreateShader(type);
 glShaderSource(shid, 1, (char **)&src, ((void *)0));
 glCompileShader(shid);
 glGetShaderiv(shid, 0x8B81, &status);
 if (!status) {
  glGetShaderiv(shid, 0x8B84, &n);
  log = (char *) malloc(n);
  glGetShaderInfoLog(shid, n, ((void *)0), log);
  fprintf(stdout, "%s\n\n%s", log, src);
  free(log);
 }
 return (!status) ? 0 : shid;
}

variable_types:
src
char *

variable_types:
type
unsigned int

variable_types:
shid
unsigned int

variable_types: status int

variable_types: n int

variable_types:
log
char *

return_type: unsigned int


decompiled_code:
void __fastcall glfree_vector(void *a1)
{
if ( a1 )
free(a1);
}

canonical_decompiled_code:
void __fastcall func2(void *a1)
{
if ( a1 )
free(a1);
}

original_code:
void
glfree_vector(glvector * v) {
 if (((void *)0) != v) free(v);
}

canonical_original_code:
void glfree_vector(struct _glvector *v) {
 if (((void *)0) != v) free(v);
}

variable_types: struct _glvector { unsigned long size; unsigned long total; float vec[]; } *

return_type: void


decompiled_code:
__int64 __fastcall glget_vector_size(__int64 a1)
{
return *(_QWORD *)a1;
}

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

original_code:
size_t
glget_vector_size(glvector * v) {
 return v->size;
}

canonical_original_code:
unsigned long glget_vector_size(struct _glvector *v) {
 return v->size;
}

return_type: unsigned long

user_defined_types: struct _glvector { unsigned long size; unsigned long total; float vec[]; }


decompiled_code:
__int64 __fastcall glget_vector_array(__int64 a1)
{
return a1 + 16;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1)
{
return a1 + 16;
}

original_code:
glfloat *
glget_vector_array(glvector * v) {
 return v->vec;
}

canonical_original_code:
float *glget_vector_array(struct _glvector *v) {
 return v->vec;
}

return_type: float *


original_code:
void
glpush_vector(glvector * * pv, glfloat e) {
 glvector * t;
 size_t size = (*pv)->size;
 size_t total = (*pv)->total;
 if (size*sizeof(glfloat) >= total) {
  t = glalloc_vector(2*total);
  t->size = size;
  t->total = 2*total;
  memcpy(t->vec, (*pv)->vec, total);
  glfree_vector(*pv);
  *pv = t;
  t = ((void *)0);
 }
 (*pv)->vec[size] = e;
 (*pv)->size++;
}

canonical_original_code:
void glpush_vector(struct _glvector **pv, float e) {
 struct _glvector *t;
 unsigned long size = (*pv)->size;
 unsigned long total = (*pv)->total;
 if (size*sizeof(glfloat) >= total) {
  t = glalloc_vector(2*total);
  t->size = size;
  t->total = 2*total;
  memcpy(t->vec, (*pv)->vec, total);
  glfree_vector(*pv);
  *pv = t;
  t = ((void *)0);
 }
 (*pv)->vec[size] = e;
 (*pv)->size++;
}

variable_types: struct _glvector { unsigned long size; unsigned long total; float vec[]; } **

variable_types: e float

variable_types:
size
unsigned long

variable_types:
total
unsigned long


decompiled_code:
void *__fastcall glpush_vec3(void **a1, unsigned int *a2)
{
glpush_vector(a1, (__m128i)*a2);
glpush_vector(a1, (__m128i)a2[1]);
return glpush_vector(a1, (__m128i)a2[2]);
}

canonical_decompiled_code:
void *__fastcall func6(void **a1, unsigned int *a2)
{
func5(a1, (__m128i)*a2);
func5(a1, (__m128i)a2[1]);
return func5(a1, (__m128i)a2[2]);
}

original_code:
void
glpush_vec3(glvector * * pv, glvec3 * pp) {
 glpush_vector(pv, pp->x);
 glpush_vector(pv, pp->y);
 glpush_vector(pv, pp->z);
}

canonical_original_code:
void glpush_vec3(struct _glvector **pv, struct _glvec3 *pp) {
 glpush_vector(pv, pp->x);
 glpush_vector(pv, pp->y);
 glpush_vector(pv, pp->z);
}

variable_types: struct _glvec3 { float x; float y; float z; } *


decompiled_code:
void *__fastcall glpush_2vec3(void **a1, unsigned int *a2, unsigned int *a3)
{
glpush_vec3(a1, a2);
return glpush_vec3(a1, a3);
}

canonical_decompiled_code:
void *__fastcall func7(void **a1, unsigned int *a2, unsigned int *a3)
{
func6(a1, a2);
return func6(a1, a3);
}

original_code:
void
glpush_2vec3(glvector * * pv, glvec3 * pp1, glvec3 * pp2) {
 glpush_vec3(pv, pp1);
 glpush_vec3(pv, pp2);
}

canonical_original_code:
void glpush_2vec3(struct _glvector **pv, struct _glvec3 *pp1, struct _glvec3 *pp2) {
 glpush_vec3(pv, pp1);
 glpush_vec3(pv, pp2);
}

user_defined_types: struct _glvec3 { float x; float y; float z; }


original_code:
void
glappend_vector(glvector * * pv, glvector * v) {
 glvector * t;
 size_t sdst = (*pv)->size;
 size_t ssrc = v->size;
 size_t tdst = (*pv)->total;
 size_t size = sdst + ssrc;
 if (size*sizeof(glfloat) >= tdst) {
  t = glalloc_vector(size*sizeof(glfloat));
  t->size = sdst;
  t->total = size*sizeof(glfloat);
  memcpy(t->vec, (*pv)->vec, tdst);
  glfree_vector(*pv);
  *pv = t;
  t = ((void *)0);
 }
 memcpy((char *)((*pv)->vec) + sizeof(glfloat)*(*pv)->size, (char *)(v->vec), sizeof(glfloat)*v->size);
 (*pv)->size = size;
}

canonical_original_code:
void glappend_vector(struct _glvector **pv, struct _glvector *v) {
 struct _glvector *t;
 unsigned long sdst = (*pv)->size;
 unsigned long ssrc = v->size;
 unsigned long tdst = (*pv)->total;
 unsigned long size = sdst + ssrc;
 if (size*sizeof(glfloat) >= tdst) {
  t = glalloc_vector(size*sizeof(glfloat));
  t->size = sdst;
  t->total = size*sizeof(glfloat);
  memcpy(t->vec, (*pv)->vec, tdst);
  glfree_vector(*pv);
  *pv = t;
  t = ((void *)0);
 }
 memcpy((char *)((*pv)->vec) + sizeof(glfloat)*(*pv)->size, (char *)(v->vec), sizeof(glfloat)*v->size);
 (*pv)->size = size;
}

variable_types:
v
struct _glvector *

variable_types:
sdst
unsigned long

variable_types:
ssrc
unsigned long

variable_types:
tdst
unsigned long


decompiled_code:
unsigned __int64 __fastcall glprint_vector(__int64 a1)
{
unsigned __int64 i; // rbx
unsigned __int64 result; // rax

for ( i = 0LL; ; i += 3LL )
{
result = glget_vector_size(a1);
if ( result <= i )
break;
fprintf(stdout, "%f %f %f\n", *(float *)(a1 + 4 * i + 16), *(float *)(a1 + 4 * i + 20), *(float *)(a1 + 4 * i + 24));
}
return result;
}

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

for ( i = 0LL; ; i += 3LL )
{
result = func3(a1);
if ( result <= i )
break;
fprintf(stdout, "%f %f %f\n", *(float *)(a1 + 4 * i + 16), *(float *)(a1 + 4 * i + 20), *(float *)(a1 + 4 * i + 24));
}
return result;
}

original_code:
void
glprint_vector(glvector * v) {
 size_t i;
 for (i = 0; i < glget_vector_size(v); i += 3) {
  fprintf(stdout, "%f %f %f\n", v->vec[i], v->vec[i+1], v->vec[i+2]);
 }
}

canonical_original_code:
void glprint_vector(struct _glvector *v) {
 unsigned long i;
 for (i = 0; i < glget_vector_size(v); i += 3) {
  fprintf(stdout, "%f %f %f\n", v->vec[i], v->vec[i+1], v->vec[i+2]);
 }
}

variable_types:
i
unsigned long


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

result = malloc(0xCuLL);
if ( result )
{
*(_QWORD *)result = 0LL;
result[2] = 0;
}
return result;
}

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

result = malloc(0xCuLL);
if ( result )
{
*(_QWORD *)result = 0LL;
result[2] = 0;
}
return result;
}

original_code:
glprograme *
glalloc_programe() {
 glprograme * p = (glprograme *) malloc(sizeof(*p));
 if (p) memset(p, 0, sizeof(*p));
 return p;
}

canonical_original_code:
struct _glprograme *glalloc_programe() {
 struct _glprograme *p = (glprograme *) malloc(sizeof(*p));
 if (p) memset(p, 0, sizeof(*p));
 return p;
}

variable_types: struct _glprograme { unsigned int pid; unsigned int vid; unsigned int fid; } *


decompiled_code:
__int64 __fastcall glcreate_programe(_DWORD *a1, const char *a2, const char *a3)
{
unsigned int v4; // ebx
__int64 result; // rax
unsigned int v6; // ebp
__int64 v7; // r13
int v8[11]; // [rsp+Ch] [rbp-2Ch] BYREF

v4 = glcreate_shader(a2, 0x8B31u);
result = 0LL;
if ( v4 )
{
v6 = glcreate_shader(a3, 0x8B30u);
result = 0LL;
if ( v6 )
{
v7 = (unsigned int)glCreateProgram();
glAttachShader(v7, v4);
glAttachShader((unsigned int)v7, v6);
glLinkProgram((unsigned int)v7);
glGetProgramiv((unsigned int)v7, 35714LL, v8);
result = 0LL;
if ( v8[0] )
{
*a1 = v7;
a1[1] = v4;
a1[2] = v6;
result = 1LL;
}
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func11(_DWORD *a1, const char *a2, const char *a3)
{
unsigned int v4; // ebx
__int64 result; // rax
unsigned int v6; // ebp
__int64 v7; // r13
int v8[11]; // [rsp+Ch] [rbp-2Ch] BYREF

v4 = func0(a2, 0x8B31u);
result = 0LL;
if ( v4 )
{
v6 = func0(a3, 0x8B30u);
result = 0LL;
if ( v6 )
{
v7 = (unsigned int)glCreateProgram();
glAttachShader(v7, v4);
glAttachShader((unsigned int)v7, v6);
glLinkProgram((unsigned int)v7);
glGetProgramiv((unsigned int)v7, 35714LL, v8);
result = 0LL;
if ( v8[0] )
{
*a1 = v7;
a1[1] = v4;
a1[2] = v6;
result = 1LL;
}
}
}
return result;
}

original_code:
bool
glcreate_programe(glprograme * p, const glchar * vsource, const glchar * fsource) {
 glshader vid, fid;
 glpid pid;
 glbool status;
 vid = glcreate_shader(vsource, 0x8B31);
 if (0 == vid) return 0;
 fid = glcreate_shader(fsource, 0x8B30);
 if (0 == fid) return 0;
 pid = glCreateProgram();
 glAttachShader(pid, vid);
 glAttachShader(pid, fid);
 glLinkProgram(pid);
 glGetProgramiv(pid, 0x8B82, &status);
 if (!status) return 0;
 p->pid = pid;
 p->vid = vid;
 p->fid = fid;
 return 1;
}

canonical_original_code:
unsigned char glcreate_programe(struct _glprograme *p, char *vsource, char *fsource) {
 unsigned int vid; unsigned int fid;
 unsigned int pid;
 int status;
 vid = glcreate_shader(vsource, 0x8B31);
 if (0 == vid) return 0;
 fid = glcreate_shader(fsource, 0x8B30);
 if (0 == fid) return 0;
 pid = glCreateProgram();
 glAttachShader(pid, vid);
 glAttachShader(pid, fid);
 glLinkProgram(pid);
 glGetProgramiv(pid, 0x8B82, &status);
 if (!status) return 0;
 p->pid = pid;
 p->vid = vid;
 p->fid = fid;
 return 1;
}

variable_types:
vsource
char *

variable_types:
fsource
char *

variable_types:
vid
unsigned int

variable_types:
fid
unsigned int

variable_types:
pid
unsigned int

return_type: unsigned char

user_defined_types: struct _glprograme { unsigned int pid; unsigned int vid; unsigned int fid; }


decompiled_code:
__int64 __fastcall glfree_programe(unsigned int *a1)
{
__int64 result; // rax

if ( a1 )
{
glUseProgram(0LL);
glDetachShader(*a1, a1[1]);
glDetachShader(*a1, a1[2]);
glDeleteShader(a1[1]);
glDeleteShader(a1[2]);
result = glDeleteProgram(*a1);
*(_QWORD *)a1 = 0LL;
a1[2] = 0;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func12(unsigned int *a1)
{
__int64 result; // rax

if ( a1 )
{
glUseProgram(0LL);
glDetachShader(*a1, a1[1]);
glDetachShader(*a1, a1[2]);
glDeleteShader(a1[1]);
glDeleteShader(a1[2]);
result = glDeleteProgram(*a1);
*(_QWORD *)a1 = 0LL;
a1[2] = 0;
}
return result;
}

original_code:
void
glfree_programe(glprograme * p) {
 if (((void *)0) == p) return;
 glUseProgram(0);
 glDetachShader(p->pid, p->vid);
 glDetachShader(p->pid, p->fid);
 glDeleteShader(p->vid);
 glDeleteShader(p->fid);
 glDeleteProgram(p->pid);
 memset(p, 0, sizeof(*p));
}

canonical_original_code:
void glfree_programe(struct _glprograme *p) {
 if (((void *)0) == p) return;
 glUseProgram(0);
 glDetachShader(p->pid, p->vid);
 glDetachShader(p->pid, p->fid);
 glDeleteShader(p->vid);
 glDeleteShader(p->fid);
 glDeleteProgram(p->pid);
 memset(p, 0, sizeof(*p));
}


decompiled_code:
void __fastcall glset_vec3(float *a1, float a2, float a3, float a4)
{
*a1 = a2;
a1[1] = a3;
a1[2] = a4;
}

canonical_decompiled_code:
void __fastcall func13(float *a1, float a2, float a3, float a4)
{
*a1 = a2;
a1[1] = a3;
a1[2] = a4;
}

original_code:
void
glset_vec3(glvec3 * pp, glfloat x, glfloat y, glfloat z) {
 pp->x = x;
 pp->y = y;
 pp->z = z;
}

canonical_original_code:
void glset_vec3(struct _glvec3 *pp, float x, float y, float z) {
 pp->x = x;
 pp->y = y;
 pp->z = z;
}

variable_types: x float

variable_types: y float

variable_types: z float


decompiled_code:
void __fastcall glassign_vec3(float *a1, float *a2)
{
glset_vec3(a1, *a2, a2[1], a2[2]);
}

canonical_decompiled_code:
void __fastcall func14(float *a1, float *a2)
{
func13(a1, *a2, a2[1], a2[2]);
}

original_code:
void
glassign_vec3(glvec3 * pdes, glvec3 * psrc) {
 glset_vec3(pdes, psrc->x, psrc->y, psrc->z);
}

canonical_original_code:
void glassign_vec3(struct _glvec3 *pdes, struct _glvec3 *psrc) {
 glset_vec3(pdes, psrc->x, psrc->y, psrc->z);
}

variable_types:
psrc
struct _glvec3 *


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

result = malloc(0x40uLL);
*result = 0LL;
result[1] = 0LL;
result[2] = 0LL;
result[3] = 0LL;
result[4] = 0LL;
result[5] = 0LL;
result[6] = 0LL;
result[7] = 0LL;
return result;
}

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

result = malloc(0x40uLL);
*result = 0LL;
result[1] = 0LL;
result[2] = 0LL;
result[3] = 0LL;
result[4] = 0LL;
result[5] = 0LL;
result[6] = 0LL;
result[7] = 0LL;
return result;
}

original_code:
glmat4 *
glalloc_mat4() {
 glmat4 * m;
 m = (glmat4 *) malloc(sizeof(*m));
 memset((void *)m, 0, sizeof(*m));
 return m;
}

canonical_original_code:
struct _glmat4 *glalloc_mat4() {
 struct _glmat4 *m;
 m = (struct _glmat4 *) malloc(sizeof(*m));
 memset((void *)m, 0, sizeof(*m));
 return m;
}

variable_types:
m
struct _glmat4 { float vecs[16]; } *

return_type: struct _glmat4 { float vecs[16]; } *


decompiled_code:
void __fastcall glfree_mat4(void *a1)
{
free(a1);
}

canonical_decompiled_code:
void __fastcall func16(void *a1)
{
free(a1);
}

original_code:
void
glfree_mat4(glmat4 * m) {
 free((void *)m);
}

canonical_original_code:
void glfree_mat4(struct _glmat4 *m) {
 free((void *)m);
}


decompiled_code:
_QWORD *glcreate_identify_mat4()
{
_QWORD *v0; // rbx

v0 = glalloc_mat4();
glset_identify_mat4((__int64)v0);
return v0;
}

canonical_decompiled_code:
_QWORD *func18()
{
_QWORD *v0; // rbx

v0 = func15();
func17((__int64)v0);
return v0;
}

original_code:
glmat4 *
glcreate_identify_mat4() {
 glmat4 * m;
 m = glalloc_mat4();
 glset_identify_mat4(m);
 return m;
}

canonical_original_code:
struct _glmat4 *glcreate_identify_mat4() {
 struct _glmat4 *m;
 m = glalloc_mat4();
 glset_identify_mat4(m);
 return m;
}


original_code:
void
glscale_mat4(glmat4 * m, glvec3 * s) {
 m->vecs[0] *= s->x;
 m->vecs[5] *= s->y;
 m->vecs[10] *= s->z;
}

canonical_original_code:
void glscale_mat4(struct _glmat4 *m, struct _glvec3 *s) {
 m->vecs[0] *= s->x;
 m->vecs[5] *= s->y;
 m->vecs[10] *= s->z;
}

variable_types: struct _glvec3 { float x; float y; float z; } *


decompiled_code:
void __fastcall glrotatefz_mat4(__int64 a1, float a2)
{
float v2; // xmm1_4
float v3; // xmm0_4
double v4; // [rsp+0h] [rbp-18h] BYREF
double sinx[2]; // [rsp+8h] [rbp-10h] BYREF

sincos(a2, sinx, &v4);
v2 = sinx[0];
v3 = v4;
*(float *)a1 = v3;
*(_DWORD *)(a1 + 4) = LODWORD(v2) ^ LC3;
*(float *)(a1 + 16) = v2;
*(float *)(a1 + 20) = v3;
}

canonical_decompiled_code:
void __fastcall func20(__int64 a1, float a2)
{
float v2; // xmm1_4
float v3; // xmm0_4
double v4; // [rsp+0h] [rbp-18h] BYREF
double sinx[2]; // [rsp+8h] [rbp-10h] BYREF

sincos(a2, sinx, &v4);
v2 = sinx[0];
v3 = v4;
*(float *)a1 = v3;
*(_DWORD *)(a1 + 4) = LODWORD(v2) ^ LC3;
*(float *)(a1 + 16) = v2;
*(float *)(a1 + 20) = v3;
}

original_code:
void glrotatefz_mat4(glmat4 * m, glfloat a) {
 glfloat sina = (glfloat) sin(a);
 glfloat cosa = (glfloat) cos(a);
 m->vecs[0] = cosa;
 m->vecs[1] = -sina;
 m->vecs[4] = sina;
 m->vecs[5] = cosa;
}

canonical_original_code:
void glrotatefz_mat4(struct _glmat4 *m, float a) {
 float sina = (glfloat) sin(a);
 float cosa = (glfloat) cos(a);
 m->vecs[0] = cosa;
 m->vecs[1] = -sina;
 m->vecs[4] = sina;
 m->vecs[5] = cosa;
}

variable_types: a float

variable_types: sina float

variable_types: cosa float


original_code:
void
glmove_mat4(glmat4 * m, glvec3 * v) {
 m->vecs[3] += v->x;
 m->vecs[7] += v->y;
 m->vecs[11] += v->z;
}

canonical_original_code:
void glmove_mat4(struct _glmat4 *m, struct _glvec3 *v) {
 m->vecs[3] += v->x;
 m->vecs[7] += v->y;
 m->vecs[11] += v->z;
}


decompiled_code:
void __fastcall glmvtrans_mat4(float *a1, float a2, float a3)
{
*a1 = (float)(*a1 / a2) - 0.5;
a1[5] = (float)(a1[5] / a3) - 0.5;
}

canonical_decompiled_code:
void __fastcall func22(float *a1, float a2, float a3)
{
*a1 = (float)(*a1 / a2) - 0.5;
a1[5] = (float)(a1[5] / a3) - 0.5;
}

original_code:
void
glmvtrans_mat4(glmat4 * m, glfloat w, glfloat h) {
 m->vecs[0] /= w;
 m->vecs[0] -= 0.50f;
 m->vecs[5] /= h;
 m->vecs[5] -= 0.50f;
}

canonical_original_code:
void glmvtrans_mat4(struct _glmat4 *m, float w, float h) {
 m->vecs[0] /= w;
 m->vecs[0] -= 0.50f;
 m->vecs[5] /= h;
 m->vecs[5] -= 0.50f;
}

variable_types: w float

variable_types: h float


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

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

original_code:
glfloat *
glget_mat4_array(glmat4 * m) {
 return m->vecs;
}

canonical_original_code:
float *glget_mat4_array(struct _glmat4 *m) {
 return m->vecs;
}


original_code:
void
glassign_mat4(glmat4 * dest, glmat4 * src) {
 memcpy((void *)dest, (void *)src, sizeof(*dest));
}

canonical_original_code:
void glassign_mat4(struct _glmat4 *dest, struct _glmat4 *src) {
 memcpy((void *)dest, (void *)src, sizeof(*dest));
}

variable_types:
dest
struct _glmat4 { float vecs[16]; } *

variable_types:
src
struct _glmat4 *


variable_types:
destm
struct _glmat4 { float vecs[16]; } *

variable_types:
srcm
struct _glmat4 *

variable_types:
dest
float *

variable_types:
src
float *


decompiled_code:
__int64 __fastcall glmutiply_scale_mat4(float *a1, float *a2)
{
glset_identify_mat4((__int64)mt_2);
glscale_mat4(mt_2, a2);
return glmutiply_mat4(a1, (__int64)mt_2);
}

canonical_decompiled_code:
__int64 __fastcall func26(float *a1, float *a2)
{
func17((__int64)mt_2);
func19(mt_2, a2);
return func25(a1, (__int64)mt_2);
}

original_code:
void
glmutiply_scale_mat4(glmat4 * m, glvec3 * v) {
 static glmat4 mt;
 glset_identify_mat4(&mt);
 glscale_mat4(&mt, v);
 glmutiply_mat4(m, &mt);
}

canonical_original_code:
void glmutiply_scale_mat4(struct _glmat4 *m, struct _glvec3 *v) {
 static struct _glmat4 mt;
 glset_identify_mat4(&mt);
 glscale_mat4(&mt, v);
 glmutiply_mat4(m, &mt);
}

variable_types:
mt
struct _glmat4 { float vecs[16]; }


decompiled_code:
__int64 __fastcall glmutiply_rotatez_mat4(float *a1, float a2)
{
glset_identify_mat4((__int64)&mt_1);
glrotatefz_mat4((__int64)&mt_1, a2);
return glmutiply_mat4(a1, (__int64)&mt_1);
}

canonical_decompiled_code:
__int64 __fastcall func27(float *a1, float a2)
{
func17((__int64)&mt_1);
func20((__int64)&mt_1, a2);
return func25(a1, (__int64)&mt_1);
}

original_code:
void
glmutiply_rotatez_mat4(glmat4 * m, glfloat a) {
 static glmat4 mt;
 glset_identify_mat4(&mt);
 glrotatefz_mat4(&mt, a);
 glmutiply_mat4(m, &mt);
}

canonical_original_code:
void glmutiply_rotatez_mat4(struct _glmat4 *m, float a) {
 static struct _glmat4 mt;
 glset_identify_mat4(&mt);
 glrotatefz_mat4(&mt, a);
 glmutiply_mat4(m, &mt);
}


decompiled_code:
__int64 __fastcall glmutiply_move_mat4(float *a1, float *a2)
{
glset_identify_mat4((__int64)mt_0);
glmove_mat4(mt_0, a2);
return glmutiply_mat4(a1, (__int64)mt_0);
}

canonical_decompiled_code:
__int64 __fastcall func28(float *a1, float *a2)
{
func17((__int64)mt_0);
func21(mt_0, a2);
return func25(a1, (__int64)mt_0);
}

original_code:
void glmutiply_move_mat4(glmat4 * m, glvec3 * v) {
 static glmat4 mt;
 glset_identify_mat4(&mt);
 glmove_mat4(&mt, v);
 glmutiply_mat4(m, &mt);
}

canonical_original_code:
void glmutiply_move_mat4(struct _glmat4 *m, struct _glvec3 *v) {
 static struct _glmat4 mt;
 glset_identify_mat4(&mt);
 glmove_mat4(&mt, v);
 glmutiply_mat4(m, &mt);
}


decompiled_code:
float __fastcall glang_transform(int a1)
{
return (float)((float)a1 * 3.1415925) / 180.0;
}

canonical_decompiled_code:
float __fastcall func29(int a1)
{
return (float)((float)a1 * 3.1415925) / 180.0;
}

original_code:
glfloat glang_transform(unsigned int a) {
 return (glfloat)(a*(3.1415926f)/180.f);
}

variable_types:
a
unsigned int

return_type: float


decompiled_code:
void __fastcall glrotatez_mat4(__int64 a1, int a2)
{
float v2; // xmm0_4

v2 = glang_transform(a2);
glrotatefz_mat4(a1, v2);
}

canonical_decompiled_code:
void __fastcall func30(__int64 a1, int a2)
{
float v2; // xmm0_4

v2 = func29(a2);
func20(a1, v2);
}

original_code:
void
glrotatez_mat4(glmat4 * m, glangle ang) {
 glfloat a = glang_transform(ang);
 glrotatefz_mat4(m, a);
}

canonical_original_code:
void glrotatez_mat4(struct _glmat4 *m, int ang) {
 float a = glang_transform(ang);
 glrotatefz_mat4(m, a);
}

variable_types: ang int


render

decompiled_code:
__int64 render()
{
glEnable(2884LL);
glEnable(2929LL);
glEnable(3042LL);
glClear(256LL);
glClearDepth(1.0);
glClear(0x4000LL);
glBlendFunc(770LL, 771LL);
glDepthFunc(513LL);
glClearColor(1.0, 1.0, 1.0);
glrender_tree_context();
return glutSwapBuffers();
}

canonical_decompiled_code:
__int64 func0()
{
glEnable(2884LL);
glEnable(2929LL);
glEnable(3042LL);
glClear(256LL);
glClearDepth(1.0);
glClear(0x4000LL);
glBlendFunc(770LL, 771LL);
glDepthFunc(513LL);
glClearColor(1.0, 1.0, 1.0);
glrender_tree_context();
return glutSwapBuffers();
}

original_code:
static void
render(void) {
 glEnable(0x0B44);
 glEnable(0x0B71);
 glEnable(0x0BE2);
 glClear(0x00000100);
 glClearDepth(1.0f);
 glClear(0x00004000);
 glBlendFunc(0x0302, 0x0303);
 glDepthFunc(0x0201);
 glClearColor(1.0, 1.0, 1.0, 1.0);
 glrender_tree_context();
 glutSwapBuffers();
}

canonical_original_code:
static void render() {
 glEnable(0x0B44);
 glEnable(0x0B71);
 glEnable(0x0BE2);
 glClear(0x00000100);
 glClearDepth(1.0f);
 glClear(0x00004000);
 glBlendFunc(0x0302, 0x0303);
 glDepthFunc(0x0201);
 glClearColor(1.0, 1.0, 1.0, 1.0);
 glrender_tree_context();
 glutSwapBuffers();
}


main

decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
int v3[3]; // [rsp+Ch] [rbp-Ch] BYREF

v3[0] = argc;
glutInit(v3, argv, envp);
glutInitDisplayMode(18LL);
glutInitWindowSize(800LL, 800LL);
glutCreateWindow("flower");
glutDisplayFunc(render);
glinit_tree_context();
glClearColor(1.0, 1.0, 1.0);
glutMainLoop();
exit(0);
}

original_code:
int
main(int argc, char** argv)
{
 glutInit(&argc, argv);
 glutInitDisplayMode(0x0000 | 0x0002 | 0x0010);
 glutInitWindowSize(800, 800);
 glutCreateWindow("flower");
 glutDisplayFunc(&render);
 glinit_tree_context();
 glClearColor(1.0, 1.0, 1.0, 1.0);
 glutMainLoop();
 exit(0);
}

canonical_original_code:
int main(int argc, char **argv)
{
 glutInit(&argc, argv);
 glutInitDisplayMode(0x0000 | 0x0002 | 0x0010);
 glutInitWindowSize(800, 800);
 glutCreateWindow("flower");
 glutDisplayFunc(&render);
 glinit_tree_context();
 glClearColor(1.0, 1.0, 1.0, 1.0);
 glutMainLoop();
 exit(0);
}

variable_types: argc int

variable_types:
argv
char **


repo: watsonjiang/hybirdthread

decompiled_code:
void __fastcall ht_ring_init(__int64 a1)
{
if ( a1 )
{
*(_QWORD *)a1 = 0LL;
*(_DWORD *)(a1 + 8) = 0;
}
}

original_code:
void
ht_ring_init(ht_ring_t *r)
{
    if (r == ((void *)0))
        return;
    r->r_hook = ((void *)0);
    r->r_nodes = 0;
    return;
}

canonical_original_code:
void ht_ring_init(struct ht_ring_st *r)
{
    if (r == ((void *)0))
        return;
    r->r_hook = ((void *)0);
    r->r_nodes = 0;
    return;
}

variable_types: struct ht_ring_st { struct ht_ringnode_st { struct ht_ringnode_st *rn_next; struct ht_ringnode_st *rn_prev; } *r_hook; unsigned int r_nodes; } *

user_defined_types: struct ht_ring_st { struct ht_ringnode_st *r_hook; unsigned int r_nodes; }


original_code:
void
ht_ring_insert_after(ht_ring_t *r, ht_ringnode_t *rn1, ht_ringnode_t *rn2)
{
    if (r == ((void *)0) || rn1 == ((void *)0) || rn2 == ((void *)0))
        return;
    rn2->rn_prev = rn1;
    rn2->rn_next = rn1->rn_next;
    rn2->rn_prev->rn_next = rn2;
    rn2->rn_next->rn_prev = rn2;
    r->r_nodes++;
    return;
}

canonical_original_code:
void ht_ring_insert_after(struct ht_ring_st *r, struct ht_ringnode_st *rn1, struct ht_ringnode_st *rn2)
{
    if (r == ((void *)0) || rn1 == ((void *)0) || rn2 == ((void *)0))
        return;
    rn2->rn_prev = rn1;
    rn2->rn_next = rn1->rn_next;
    rn2->rn_prev->rn_next = rn2;
    rn2->rn_next->rn_prev = rn2;
    r->r_nodes++;
    return;
}

user_defined_types: struct ht_ringnode_st { struct ht_ringnode_st *rn_next; struct ht_ringnode_st *rn_prev; }


original_code:
void
ht_ring_insert_before(ht_ring_t *r, ht_ringnode_t *rn1, ht_ringnode_t *rn2)
{
    if (r == ((void *)0) || rn1 == ((void *)0) || rn2 == ((void *)0))
        return;
    rn2->rn_next = rn1;
    rn2->rn_prev = rn1->rn_prev;
    rn2->rn_prev->rn_next = rn2;
    rn2->rn_next->rn_prev = rn2;
    r->r_nodes++;
    return;
}

canonical_original_code:
void ht_ring_insert_before(struct ht_ring_st *r, struct ht_ringnode_st *rn1, struct ht_ringnode_st *rn2)
{
    if (r == ((void *)0) || rn1 == ((void *)0) || rn2 == ((void *)0))
        return;
    rn2->rn_next = rn1;
    rn2->rn_prev = rn1->rn_prev;
    rn2->rn_prev->rn_next = rn2;
    rn2->rn_next->rn_prev = rn2;
    r->r_nodes++;
    return;
}


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

if ( !a1 )
return 0LL;
if ( !*a1 )
return 0LL;
result = 1LL;
if ( (_QWORD *)*a1 != a2 )
{
ht_ring_delete((__int64)a1, a2);
ht_ring_prepend(a1, a2);
result = 1LL;
}
return result;
}

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

if ( !a1 )
return 0LL;
if ( !*a1 )
return 0LL;
result = 1LL;
if ( (_QWORD *)*a1 != a2 )
{
ht_ring_delete((__int64)a1, a2);
func3(a1, a2);
result = 1LL;
}
return result;
}

original_code:
int
ht_ring_favorite(ht_ring_t *r, ht_ringnode_t *rn)
{
    if (r == ((void *)0))
        return (0);
    if (r->r_hook == ((void *)0))
        return (0);
    if (r->r_hook == rn)
        return (!(0));
    ht_ring_delete(r, rn);
    ht_ring_prepend(r, rn);
    return (!(0));
}

canonical_original_code:
int ht_ring_favorite(struct ht_ring_st *r, struct ht_ringnode_st *rn)
{
    if (r == ((void *)0))
        return (0);
    if (r->r_hook == ((void *)0))
        return (0);
    if (r->r_hook == rn)
        return (!(0));
    ht_ring_delete(r, rn);
    ht_ring_prepend(r, rn);
    return (!(0));
}

variable_types:
rn
struct ht_ringnode_st *


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

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

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

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

original_code:
int
ht_ring_contains(ht_ring_t *r, ht_ringnode_t *rns)
{
    ht_ringnode_t *rn;
    int rc;
    if (r == ((void *)0) || rns == ((void *)0))
        return ((*__errno_location ()) = (22), ((0)));
    rc = (0);
    rn = r->r_hook;
    if (rn != ((void *)0)) {
        do {
            if (rn == rns) {
                rc = (!(0));
                break;
            }
            rn = rn->rn_next;
        } while (rn != r->r_hook);
    }
    return rc;
}

canonical_original_code:
int ht_ring_contains(struct ht_ring_st *r, struct ht_ringnode_st *rns)
{
    struct ht_ringnode_st *rn;
    int rc;
    if (r == ((void *)0) || rns == ((void *)0))
        return ((*__errno_location ()) = (22), ((0)));
    rc = (0);
    rn = r->r_hook;
    if (rn != ((void *)0)) {
        do {
            if (rn == rns) {
                rc = (!(0));
                break;
            }
            rn = rn->rn_next;
        } while (rn != r->r_hook);
    }
    return rc;
}

variable_types:
rns
struct ht_ringnode_st *

variable_types: struct ht_ringnode_st { struct ht_ringnode_st *rn_next; struct ht_ringnode_st *rn_prev; } *

variable_types: rc int


decompiled_code:
_BOOL8 ht_exit_cb()
{
return ht_SQ[2] + ht_WQ[2] + ht_NQ[2] + ht_RQ[2] == 1;
}

canonical_decompiled_code:
_BOOL8 func0()
{
return ht_SQ[2] + ht_WQ[2] + ht_NQ[2] + ht_RQ[2] == 1;
}

variable_types:
arg
void *


decompiled_code:
__int64 ht_version()
{
return 2097671LL;
}

original_code:
long ht_version(void)
{
    return 0x200207;
}

canonical_original_code:
long ht_version()
{
    return 0x200207;
}

return_type: long


decompiled_code:
__int64 ht_init()
{
unsigned int v0; // ebp
unsigned int v1; // ebx
__int64 v3; // rbp
int *v4; // r12

v0 = ht_initialized;
if ( ht_initialized )
{
*_errno_location() = 1;
v1 = 0;
}
else
{
ht_initialized = 1;
v1 = ht_scheduler_init();
if ( v1 )
{
v1 = ht_worker_init(3LL);
if ( v1 )
{
*_errno_location() = 11;
v1 = v0;
}
else
{
v3 = ht_attr_new();
ht_attr_set(v3, 0LL, 5LL);
ht_attr_set(v3, 1LL, "**SCHEDULER**");
ht_attr_set(v3, 2LL, 0LL);
ht_attr_set(v3, 3LL, 2LL);
ht_attr_set(v3, 4LL, 0x10000LL);
ht_attr_set(v3, 5LL, 0LL);
ht_sched = ht_spawn(v3, &ht_scheduler, 0LL);
if ( ht_sched
&& (ht_attr_set(v3, 0LL, 0LL),
ht_attr_set(v3, 1LL, "main"),
ht_attr_set(v3, 2LL, 1LL),
ht_attr_set(v3, 3LL, 9LL),
ht_attr_set(v3, 4LL, 0LL),
ht_attr_set(v3, 5LL, 0LL),
(ht_main = ht_spawn(v3, (void *)0xFFFFFFFFFFFFFFFFLL, 0LL)) != 0LL) )
{
ht_attr_destroy(v3);
ht_current = ht_sched;
swapcontext((ucontext_t *)(ht_main + 128LL), (const ucontext_t *)(ht_sched + 128LL));
v1 = 1;
}
else
{
v4 = _errno_location();
ht_errno_storage = *v4;
ht_errno_flag = 1;
ht_attr_destroy(v3);
ht_scheduler_kill();
*v4 = ht_errno_storage;
ht_errno_flag = 0;
}
}
}
else
{
*_errno_location() = 11;
}
}
return v1;
}

canonical_decompiled_code:
__int64 func4()
{
unsigned int v0; // ebp
unsigned int v1; // ebx
__int64 v3; // rbp
int *v4; // r12

v0 = ht_initialized;
if ( ht_initialized )
{
*_errno_location() = 1;
v1 = 0;
}
else
{
ht_initialized = 1;
v1 = ht_scheduler_init();
if ( v1 )
{
v1 = ht_worker_init(3LL);
if ( v1 )
{
*_errno_location() = 11;
v1 = v0;
}
else
{
v3 = ht_attr_new();
ht_attr_set(v3, 0LL, 5LL);
ht_attr_set(v3, 1LL, "**SCHEDULER**");
ht_attr_set(v3, 2LL, 0LL);
ht_attr_set(v3, 3LL, 2LL);
ht_attr_set(v3, 4LL, 0x10000LL);
ht_attr_set(v3, 5LL, 0LL);
ht_sched = func3(v3, &ht_scheduler, 0LL);
if ( ht_sched
&& (ht_attr_set(v3, 0LL, 0LL),
ht_attr_set(v3, 1LL, "main"),
ht_attr_set(v3, 2LL, 1LL),
ht_attr_set(v3, 3LL, 9LL),
ht_attr_set(v3, 4LL, 0LL),
ht_attr_set(v3, 5LL, 0LL),
(ht_main = func3(v3, (void *)0xFFFFFFFFFFFFFFFFLL, 0LL)) != 0LL) )
{
ht_attr_destroy(v3);
ht_current = ht_sched;
swapcontext((ucontext_t *)(ht_main + 128LL), (const ucontext_t *)(ht_sched + 128LL));
v1 = 1;
}
else
{
v4 = _errno_location();
ht_errno_storage = *v4;
ht_errno_flag = 1;
ht_attr_destroy(v3);
ht_scheduler_kill();
*v4 = ht_errno_storage;
ht_errno_flag = 0;
}
}
}
else
{
*_errno_location() = 11;
}
}
return v1;
}

original_code:
int
ht_init(void)
{
    ht_attr_t t_attr;
    if (ht_initialized)
        return ((*__errno_location ()) = (1), ((0)));
    else
        ht_initialized = (!(0));
    ;
    if (!ht_scheduler_init()) {
        return ((*__errno_location ()) = (11), ((0)));
    }
    if (ht_worker_init(3)) {
       return ((*__errno_location ()) = (11), ((0)));
    }
    t_attr = ht_attr_new();
    ht_attr_set(t_attr, HT_ATTR_PRIO, +5);
    ht_attr_set(t_attr, HT_ATTR_NAME, "**SCHEDULER**");
    ht_attr_set(t_attr, HT_ATTR_JOINABLE, (0));
    ht_attr_set(t_attr, HT_ATTR_CANCEL_STATE, (1<<(1)));
    ht_attr_set(t_attr, HT_ATTR_STACK_SIZE, 64*1024);
    ht_attr_set(t_attr, HT_ATTR_STACK_ADDR, ((void *)0));
    ht_sched = ht_spawn(t_attr, ht_scheduler, ((void *)0));
    if (ht_sched == ((void *)0)) {
        for ( ht_errno_storage = (*__errno_location ()), ht_errno_flag = (!(0)); ht_errno_flag; (*__errno_location ()) = ht_errno_storage, ht_errno_flag = (0) ) {
            ht_attr_destroy(t_attr);
            ht_scheduler_kill();
        }
        return (0);
    }
    ht_attr_set(t_attr, HT_ATTR_PRIO, 0);
    ht_attr_set(t_attr, HT_ATTR_NAME, "main");
    ht_attr_set(t_attr, HT_ATTR_JOINABLE, (!(0)));
    ht_attr_set(t_attr, HT_ATTR_CANCEL_STATE, (1<<(0))|(1<<(3)));
    ht_attr_set(t_attr, HT_ATTR_STACK_SIZE, 0 );
    ht_attr_set(t_attr, HT_ATTR_STACK_ADDR, ((void *)0));
    ht_main = ht_spawn(t_attr, (void *(*)(void *))(-1), ((void *)0));
    if (ht_main == ((void *)0)) {
        for ( ht_errno_storage = (*__errno_location ()), ht_errno_flag = (!(0)); ht_errno_flag; (*__errno_location ()) = ht_errno_storage, ht_errno_flag = (0) ) {
            ht_attr_destroy(t_attr);
            ht_scheduler_kill();
        }
        return (0);
    }
    ht_attr_destroy(t_attr);
    ht_current = ht_sched;
    swapcontext(&((&ht_main->mctx)->uc), &((&ht_sched->mctx)->uc));;
    ;
    return (!(0));
}

canonical_original_code:
int ht_init()
{
    struct ht_attr_st *t_attr;
    if (ht_initialized)
        return ((*__errno_location ()) = (1), ((0)));
    else
        ht_initialized = (!(0));
    ;
    if (!ht_scheduler_init()) {
        return ((*__errno_location ()) = (11), ((0)));
    }
    if (ht_worker_init(3)) {
       return ((*__errno_location ()) = (11), ((0)));
    }
    t_attr = ht_attr_new();
    ht_attr_set(t_attr, HT_ATTR_PRIO, +5);
    ht_attr_set(t_attr, HT_ATTR_NAME, "**SCHEDULER**");
    ht_attr_set(t_attr, HT_ATTR_JOINABLE, (0));
    ht_attr_set(t_attr, HT_ATTR_CANCEL_STATE, (1<<(1)));
    ht_attr_set(t_attr, HT_ATTR_STACK_SIZE, 64*1024);
    ht_attr_set(t_attr, HT_ATTR_STACK_ADDR, ((void *)0));
    ht_sched = ht_spawn(t_attr, ht_scheduler, ((void *)0));
    if (ht_sched == ((void *)0)) {
        for ( ht_errno_storage = (*__errno_location ()), ht_errno_flag = (!(0)); ht_errno_flag; (*__errno_location ()) = ht_errno_storage, ht_errno_flag = (0) ) {
            ht_attr_destroy(t_attr);
            ht_scheduler_kill();
        }
        return (0);
    }
    ht_attr_set(t_attr, HT_ATTR_PRIO, 0);
    ht_attr_set(t_attr, HT_ATTR_NAME, "main");
    ht_attr_set(t_attr, HT_ATTR_JOINABLE, (!(0)));
    ht_attr_set(t_attr, HT_ATTR_CANCEL_STATE, (1<<(0))|(1<<(3)));
    ht_attr_set(t_attr, HT_ATTR_STACK_SIZE, 0 );
    ht_attr_set(t_attr, HT_ATTR_STACK_ADDR, ((void *)0));
    ht_main = ht_spawn(t_attr, (void *(*)(void *))(-1), ((void *)0));
    if (ht_main == ((void *)0)) {
        for ( ht_errno_storage = (*__errno_location ()), ht_errno_flag = (!(0)); ht_errno_flag; (*__errno_location ()) = ht_errno_storage, ht_errno_flag = (0) ) {
            ht_attr_destroy(t_attr);
            ht_scheduler_kill();
        }
        return (0);
    }
    ht_attr_destroy(t_attr);
    ht_current = ht_sched;
    swapcontext(&((&ht_main->mctx)->uc), &((&ht_sched->mctx)->uc));;
    ;
    return (!(0));
}

variable_types: struct ht_attr_st { struct ht_st { struct ht_st *q_next; struct ht_st *q_prev; int q_prio; int prio; char name[40]; int dispatches; enum ht_state_en { HT_STATE_SCHEDULER=0, HT_STATE_NEW=1, HT_STATE_READY=2, HT_STATE_WAITING=3, HT_STATE_WAITING_FOR_SCHED_TO_WORKER=4, HT_STATE_DEAD=5 } state; struct timeval { long tv_sec; long tv_usec; } spawned; struct timeval lastran; struct timeval running; struct ht_event_st { struct ht_event_st *ev_next; struct ht_event_st *ev_prev; enum ht_status_t { HT_STATUS_PENDING=0, HT_STATUS_OCCURRED=1, HT_STATUS_FAILED=2 } ev_status; int ev_type; int ev_goal; union { struct { int fd; } FD; struct { int *n; int nfd; struct fd_set { long __fds_bits[-1]; } *rfds; } SELECT; struct { int fini; } TASK; struct { struct timeval tv; } TIME; struct { struct ht_msgport_st { struct ht_ringnode_st { struct ht_ringnode_st *rn_next; struct ht_ringnode_st *rn_prev; } mp_node; char *mp_name; struct ht_st *mp_tid; struct ht_ring_st { struct ht_ringnode_st *r_hook; unsigned int r_nodes; } mp_queue; } *mp; } MSG; struct { struct ht_mutex_st { struct ht_ringnode_st mx_node; int mx_state; struct ht_st *mx_owner; unsigned long mx_count; } *mutex; } MUTEX; struct { struct ht_cond_st { unsigned long cn_state; unsigned int cn_waiters; } *cond; } COND; struct { struct ht_st *tid; } TID; struct { int (*func)(void *); void *arg; struct timeval tv; } FUNC; } ev_args; } *events; struct ht_mctx_st { struct ucontext_t { unsigned long uc_flags; struct ucontext_t *uc_link; struct stack_t { void *ss_sp; int ss_flags; unsigned long ss_size; } uc_stack; struct mcontext_t { long long gregs[23]; struct _libc_fpstate { unsigned short cwd; unsigned short swd; unsigned short ftw; unsigned short fop; unsigned long rip; unsigned long rdp; unsigned int mxcsr; unsigned int mxcr_mask; struct _libc_fpxreg { unsigned short significand[4]; unsigned short exponent; unsigned short __glibc_reserved1[3]; } _st[8]; struct _libc_xmmreg { unsigned int element[4]; } _xmm[16]; unsigned int __glibc_reserved1[24]; } *fpregs; unsigned long long __reserved1[8]; } uc_mcontext; struct __sigset_t { unsigned long __val[-1]; } uc_sigmask; struct _libc_fpstate __fpregs_mem; unsigned long long __ssp[4]; } uc; int restored; int error; } mctx; char *stack; unsigned int stacksize; long *stackguard; int stackloan; void *(*start_func)(void *); void *start_arg; int joinable; void *join_arg; void **data_value; int data_count; int cancelreq; unsigned int cancelstate; struct ht_cleanup_st { struct ht_cleanup_st *next; void (*func)(void *); void *arg; } *cleanups; struct ht_ring_st mutexring; } *a_tid; int a_prio; int a_dispatches; char a_name[40]; int a_joinable; unsigned int a_cancelstate; unsigned int a_stacksize; char *a_stackaddr; } *

user_defined_types: struct ht_attr_st { struct ht_st *a_tid; int a_prio; int a_dispatches; char a_name[40]; int a_joinable; unsigned int a_cancelstate; unsigned int a_stacksize; char *a_stackaddr; }

user_defined_types: struct ht_st { struct ht_st *q_next; struct ht_st *q_prev; int q_prio; int prio; char name[40]; int dispatches; enum ht_state_en state; struct timeval spawned; struct timeval lastran; struct timeval running; struct ht_event_st *events; struct ht_mctx_st mctx; char *stack; unsigned int stacksize; long *stackguard; int stackloan; void *(*start_func)(void *); void *start_arg; int joinable; void *join_arg; void **data_value; int data_count; int cancelreq; unsigned int cancelstate; struct ht_cleanup_st *cleanups; struct ht_ring_st mutexring; }

user_defined_types: struct ht_mctx_st { struct ucontext_t uc; int restored; int error; }

user_defined_types: struct ht_event_st { struct ht_event_st *ev_next; struct ht_event_st *ev_prev; enum ht_status_t ev_status; int ev_type; int ev_goal; union { struct { int fd; } FD; struct { int *n; int nfd; struct fd_set *rfds; } SELECT; struct { int fini; } TASK; struct { struct timeval tv; } TIME; struct { struct ht_msgport_st *mp; } MSG; struct { struct ht_mutex_st *mutex; } MUTEX; struct { struct ht_cond_st *cond; } COND; struct { struct ht_st *tid; } TID; struct { int (*func)(void *); void *arg; struct timeval tv; } FUNC; } ev_args; }

user_defined_types: struct ucontext_t { unsigned long uc_flags; struct ucontext_t *uc_link; struct stack_t uc_stack; struct mcontext_t uc_mcontext; struct __sigset_t uc_sigmask; struct _libc_fpstate __fpregs_mem; unsigned long long __ssp[4]; }

user_defined_types: struct mcontext_t { long long gregs[23]; struct _libc_fpstate *fpregs; unsigned long long __reserved1[8]; }

user_defined_types: struct _libc_fpstate { unsigned short cwd; unsigned short swd; unsigned short ftw; unsigned short fop; unsigned long rip; unsigned long rdp; unsigned int mxcsr; unsigned int mxcr_mask; struct _libc_fpxreg _st[8]; struct _libc_xmmreg _xmm[16]; unsigned int __glibc_reserved1[24]; }

user_defined_types: struct ht_msgport_st { struct ht_ringnode_st mp_node; char *mp_name; struct ht_st *mp_tid; struct ht_ring_st mp_queue; }


decompiled_code:
__int64 ht_self()
{
return ht_current;
}

canonical_decompiled_code:
__int64 func5()
{
return ht_current;
}

original_code:
ht_t
ht_self(void)
{
    return ht_current;
}

canonical_original_code:
struct ht_st *ht_self()
{
    return ht_current;
}

return_type: struct ht_st { struct ht_st *q_next; struct ht_st *q_prev; int q_prio; int prio; char name[40]; int dispatches; enum ht_state_en { HT_STATE_SCHEDULER=0, HT_STATE_NEW=1, HT_STATE_READY=2, HT_STATE_WAITING=3, HT_STATE_WAITING_FOR_SCHED_TO_WORKER=4, HT_STATE_DEAD=5 } state; struct timeval { long tv_sec; long tv_usec; } spawned; struct timeval lastran; struct timeval running; struct ht_event_st { struct ht_event_st *ev_next; struct ht_event_st *ev_prev; enum ht_status_t { HT_STATUS_PENDING=0, HT_STATUS_OCCURRED=1, HT_STATUS_FAILED=2 } ev_status; int ev_type; int ev_goal; union { struct { int fd; } FD; struct { int *n; int nfd; struct fd_set { long __fds_bits[-1]; } *rfds; } SELECT; struct { int fini; } TASK; struct { struct timeval tv; } TIME; struct { struct ht_msgport_st { struct ht_ringnode_st { struct ht_ringnode_st *rn_next; struct ht_ringnode_st *rn_prev; } mp_node; char *mp_name; struct ht_st *mp_tid; struct ht_ring_st { struct ht_ringnode_st *r_hook; unsigned int r_nodes; } mp_queue; } *mp; } MSG; struct { struct ht_mutex_st { struct ht_ringnode_st mx_node; int mx_state; struct ht_st *mx_owner; unsigned long mx_count; } *mutex; } MUTEX; struct { struct ht_cond_st { unsigned long cn_state; unsigned int cn_waiters; } *cond; } COND; struct { struct ht_st *tid; } TID; struct { int (*func)(void *); void *arg; struct timeval tv; } FUNC; } ev_args; } *events; struct ht_mctx_st { struct ucontext_t { unsigned long uc_flags; struct ucontext_t *uc_link; struct stack_t { void *ss_sp; int ss_flags; unsigned long ss_size; } uc_stack; struct mcontext_t { long long gregs[23]; struct _libc_fpstate { unsigned short cwd; unsigned short swd; unsigned short ftw; unsigned short fop; unsigned long rip; unsigned long rdp; unsigned int mxcsr; unsigned int mxcr_mask; struct _libc_fpxreg { unsigned short significand[4]; unsigned short exponent; unsigned short __glibc_reserved1[3]; } _st[8]; struct _libc_xmmreg { unsigned int element[4]; } _xmm[16]; unsigned int __glibc_reserved1[24]; } *fpregs; unsigned long long __reserved1[8]; } uc_mcontext; struct __sigset_t { unsigned long __val[-1]; } uc_sigmask; struct _libc_fpstate __fpregs_mem; unsigned long long __ssp[4]; } uc; int restored; int error; } mctx; char *stack; unsigned int stacksize; long *stackguard; int stackloan; void *(*start_func)(void *); void *start_arg; int joinable; void *join_arg; void **data_value; int data_count; int cancelreq; unsigned int cancelstate; struct ht_cleanup_st { struct ht_cleanup_st *next; void (*func)(void *); void *arg; } *cleanups; struct ht_ring_st mutexring; } *


decompiled_code:
__int64 __fastcall ht_thread_exists(__int64 a1)
{
unsigned int v1; // ebp

v1 = 1;
if ( !(unsigned int)ht_pqueue_contains(ht_NQ, a1)
&& !(unsigned int)ht_pqueue_contains(ht_RQ, a1)
&& !(unsigned int)ht_pqueue_contains(ht_WQ, a1)
&& !(unsigned int)ht_pqueue_contains(ht_SQ, a1) )
{
v1 = ht_pqueue_contains(ht_DQ, a1);
if ( v1 )
v1 = 1;
else
*_errno_location() = 3;
}
return v1;
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1)
{
unsigned int v1; // ebp

v1 = 1;
if ( !(unsigned int)ht_pqueue_contains(ht_NQ, a1)
&& !(unsigned int)ht_pqueue_contains(ht_RQ, a1)
&& !(unsigned int)ht_pqueue_contains(ht_WQ, a1)
&& !(unsigned int)ht_pqueue_contains(ht_SQ, a1) )
{
v1 = ht_pqueue_contains(ht_DQ, a1);
if ( v1 )
v1 = 1;
else
*_errno_location() = 3;
}
return v1;
}

original_code:
int
ht_thread_exists(ht_t t)
{
    if (!ht_pqueue_contains(&ht_NQ, t))
        if (!ht_pqueue_contains(&ht_RQ, t))
            if (!ht_pqueue_contains(&ht_WQ, t))
                if (!ht_pqueue_contains(&ht_SQ, t))
                    if (!ht_pqueue_contains(&ht_DQ, t))
                        return ((*__errno_location ()) = (3), ((0)));
    return (!(0));
}

canonical_original_code:
int ht_thread_exists(struct ht_st *t)
{
    if (!ht_pqueue_contains(&ht_NQ, t))
        if (!ht_pqueue_contains(&ht_RQ, t))
            if (!ht_pqueue_contains(&ht_WQ, t))
                if (!ht_pqueue_contains(&ht_SQ, t))
                    if (!ht_pqueue_contains(&ht_DQ, t))
                        return ((*__errno_location ()) = (3), ((0)));
    return (!(0));
}

variable_types: struct ht_st { struct ht_st *q_next; struct ht_st *q_prev; int q_prio; int prio; char name[40]; int dispatches; enum ht_state_en { HT_STATE_SCHEDULER=0, HT_STATE_NEW=1, HT_STATE_READY=2, HT_STATE_WAITING=3, HT_STATE_WAITING_FOR_SCHED_TO_WORKER=4, HT_STATE_DEAD=5 } state; struct timeval { long tv_sec; long tv_usec; } spawned; struct timeval lastran; struct timeval running; struct ht_event_st { struct ht_event_st *ev_next; struct ht_event_st *ev_prev; enum ht_status_t { HT_STATUS_PENDING=0, HT_STATUS_OCCURRED=1, HT_STATUS_FAILED=2 } ev_status; int ev_type; int ev_goal; union { struct { int fd; } FD; struct { int *n; int nfd; struct fd_set { long __fds_bits[-1]; } *rfds; } SELECT; struct { int fini; } TASK; struct { struct timeval tv; } TIME; struct { struct ht_msgport_st { struct ht_ringnode_st { struct ht_ringnode_st *rn_next; struct ht_ringnode_st *rn_prev; } mp_node; char *mp_name; struct ht_st *mp_tid; struct ht_ring_st { struct ht_ringnode_st *r_hook; unsigned int r_nodes; } mp_queue; } *mp; } MSG; struct { struct ht_mutex_st { struct ht_ringnode_st mx_node; int mx_state; struct ht_st *mx_owner; unsigned long mx_count; } *mutex; } MUTEX; struct { struct ht_cond_st { unsigned long cn_state; unsigned int cn_waiters; } *cond; } COND; struct { struct ht_st *tid; } TID; struct { int (*func)(void *); void *arg; struct timeval tv; } FUNC; } ev_args; } *events; struct ht_mctx_st { struct ucontext_t { unsigned long uc_flags; struct ucontext_t *uc_link; struct stack_t { void *ss_sp; int ss_flags; unsigned long ss_size; } uc_stack; struct mcontext_t { long long gregs[23]; struct _libc_fpstate { unsigned short cwd; unsigned short swd; unsigned short ftw; unsigned short fop; unsigned long rip; unsigned long rdp; unsigned int mxcsr; unsigned int mxcr_mask; struct _libc_fpxreg { unsigned short significand[4]; unsigned short exponent; unsigned short __glibc_reserved1[3]; } _st[8]; struct _libc_xmmreg { unsigned int element[4]; } _xmm[16]; unsigned int __glibc_reserved1[24]; } *fpregs; unsigned long long __reserved1[8]; } uc_mcontext; struct __sigset_t { unsigned long __val[-1]; } uc_sigmask; struct _libc_fpstate __fpregs_mem; unsigned long long __ssp[4]; } uc; int restored; int error; } mctx; char *stack; unsigned int stacksize; long *stackguard; int stackloan; void *(*start_func)(void *); void *start_arg; int joinable; void *join_arg; void **data_value; int data_count; int cancelreq; unsigned int cancelstate; struct ht_cleanup_st { struct ht_cleanup_st *next; void (*func)(void *); void *arg; } *cleanups; struct ht_ring_st mutexring; } *


decompiled_code:
__int64 __fastcall ht_thread_cleanup(__int64 a1)
{
if ( *(_QWORD *)(a1 + 1192) )
ht_cleanup_popall(a1, 1LL);
if ( *(_QWORD *)(a1 + 1168) )
ht_key_destroydata(a1);
return ht_mutex_releaseall(a1);
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1)
{
if ( *(_QWORD *)(a1 + 1192) )
ht_cleanup_popall(a1, 1LL);
if ( *(_QWORD *)(a1 + 1168) )
ht_key_destroydata(a1);
return ht_mutex_releaseall(a1);
}

original_code:
void
ht_thread_cleanup(ht_t thread)
{
    if (thread->cleanups != ((void *)0))
        ht_cleanup_popall(thread, (!(0)));
    if (thread->data_value != ((void *)0))
        ht_key_destroydata(thread);
    ht_mutex_releaseall(thread);
    return;
}

canonical_original_code:
void ht_thread_cleanup(struct ht_st *thread)
{
    if (thread->cleanups != ((void *)0))
        ht_cleanup_popall(thread, (!(0)));
    if (thread->data_value != ((void *)0))
        ht_key_destroydata(thread);
    ht_mutex_releaseall(thread);
    return;
}

user_defined_types: enum ht_state_en { HT_STATE_SCHEDULER=0, HT_STATE_NEW=1, HT_STATE_READY=2, HT_STATE_WAITING=3, HT_STATE_WAITING_FOR_SCHED_TO_WORKER=4, HT_STATE_DEAD=5 }

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

user_defined_types: struct ht_cleanup_st { struct ht_cleanup_st *next; void (*func)(void *); void *arg; }

user_defined_types: enum ht_status_t { HT_STATUS_PENDING=0, HT_STATUS_OCCURRED=1, HT_STATUS_FAILED=2 }

user_defined_types: struct stack_t { void *ss_sp; int ss_flags; unsigned long ss_size; }

user_defined_types: struct __sigset_t { unsigned long __val[-1]; }

user_defined_types: struct ht_mutex_st { struct ht_ringnode_st mx_node; int mx_state; struct ht_st *mx_owner; unsigned long mx_count; }

user_defined_types: struct ht_cond_st { unsigned long cn_state; unsigned int cn_waiters; }

user_defined_types: struct _libc_fpxreg { unsigned short significand[4]; unsigned short exponent; unsigned short __glibc_reserved1[3]; }

user_defined_types: struct _libc_xmmreg { unsigned int element[4]; }


decompiled_code:
__int64 ht_kill()
{
unsigned int v0; // ebx

v0 = ht_initialized;
if ( ht_initialized )
{
if ( ht_current == ht_main )
{
ht_worker_kill();
ht_thread_cleanup(ht_main);
ht_scheduler_kill();
ht_initialized = 0;
ht_tcb_free(ht_sched);
ht_tcb_free(ht_main);
v0 = 1;
}
else
{
*_errno_location() = 1;
v0 = 0;
}
}
else
{
*_errno_location() = 22;
}
return v0;
}

canonical_decompiled_code:
__int64 func8()
{
unsigned int v0; // ebx

v0 = ht_initialized;
if ( ht_initialized )
{
if ( ht_current == ht_main )
{
ht_worker_kill();
func7(ht_main);
ht_scheduler_kill();
ht_initialized = 0;
ht_tcb_free(ht_sched);
ht_tcb_free(ht_main);
v0 = 1;
}
else
{
*_errno_location() = 1;
v0 = 0;
}
}
else
{
*_errno_location() = 22;
}
return v0;
}

original_code:
int
ht_kill(void)
{
    if (!ht_initialized)
        return ((*__errno_location ()) = (22), ((0)));
    if (ht_current != ht_main)
        return ((*__errno_location ()) = (1), ((0)));
    ;
    ht_worker_kill();
    ht_thread_cleanup(ht_main);
    ht_scheduler_kill();
    ht_initialized = (0);
    ht_tcb_free(ht_sched);
    ht_tcb_free(ht_main);
    ;
    return (!(0));
}

canonical_original_code:
int ht_kill()
{
    if (!ht_initialized)
        return ((*__errno_location ()) = (22), ((0)));
    if (ht_current != ht_main)
        return ((*__errno_location ()) = (1), ((0)));
    ;
    ht_worker_kill();
    ht_thread_cleanup(ht_main);
    ht_scheduler_kill();
    ht_initialized = (0);
    ht_tcb_free(ht_sched);
    ht_tcb_free(ht_main);
    ;
    return (!(0));
}


decompiled_code:
void __fastcall __noreturn ht_exit(__int64 status)
{
__int64 v1; // rax
__int64 v2; // rbp

if ( ht_current == ht_main && !ht_exit_cb() )
{
v2 = ht_event(512LL, ht_exit_cb);
ht_wait(v2);
ht_event_free(v2, 0LL);
}
ht_thread_cleanup(ht_current);
v1 = ht_current;
if ( ht_current == ht_main )
{
ht_kill();
exit(status);
}
*(_QWORD *)(ht_current + 1160) = status;
*(_DWORD *)(v1 + 68) = 5;
swapcontext((ucontext_t *)(v1 + 128), (const ucontext_t *)(ht_sched + 128LL));
abort();
}

canonical_decompiled_code:
void __fastcall __noreturn func9(__int64 status)
{
__int64 v1; // rax
__int64 v2; // rbp

if ( ht_current == ht_main && !func0() )
{
v2 = ht_event(512LL, ht_exit_cb);
ht_wait(v2);
ht_event_free(v2, 0LL);
}
func7(ht_current);
v1 = ht_current;
if ( ht_current == ht_main )
{
func8();
exit(status);
}
*(_QWORD *)(ht_current + 1160) = status;
*(_DWORD *)(v1 + 68) = 5;
swapcontext((ucontext_t *)(v1 + 128), (const ucontext_t *)(ht_sched + 128LL));
abort();
}

original_code:
void
ht_exit(void *value)
{
    ht_event_t ev;
    ;
    if (ht_current == ht_main) {
        if (!ht_exit_cb(((void *)0))) {
            ev = ht_event((1<<(9)), ht_exit_cb);
            ht_wait(ev);
            ht_event_free(ev, HT_FREE_THIS);
        }
    }
    ht_thread_cleanup(ht_current);
    if (ht_current != ht_main) {
        ht_current->join_arg = value;
        ht_current->state = HT_STATE_DEAD;
        ;
        swapcontext(&((&ht_current->mctx)->uc), &((&ht_sched->mctx)->uc));;
    }
    else {
        ht_kill();
        exit((int)((long)value));
    }
    abort();
}

canonical_original_code:
void ht_exit(void *value)
{
    struct ht_event_st *ev;
    ;
    if (ht_current == ht_main) {
        if (!ht_exit_cb(((void *)0))) {
            ev = ht_event((1<<(9)), ht_exit_cb);
            ht_wait(ev);
            ht_event_free(ev, HT_FREE_THIS);
        }
    }
    ht_thread_cleanup(ht_current);
    if (ht_current != ht_main) {
        ht_current->join_arg = value;
        ht_current->state = HT_STATE_DEAD;
        ;
        swapcontext(&((&ht_current->mctx)->uc), &((&ht_sched->mctx)->uc));;
    }
    else {
        ht_kill();
        exit((int)((long)value));
    }
    abort();
}

variable_types:
value
void *

variable_types: struct ht_event_st { struct ht_event_st *ev_next; struct ht_event_st *ev_prev; enum ht_status_t { HT_STATUS_PENDING=0, HT_STATUS_OCCURRED=1, HT_STATUS_FAILED=2 } ev_status; int ev_type; int ev_goal; union { struct { int fd; } FD; struct { int *n; int nfd; struct fd_set { long __fds_bits[-1]; } *rfds; } SELECT; struct { int fini; } TASK; struct { struct timeval { long tv_sec; long tv_usec; } tv; } TIME; struct { struct ht_msgport_st { struct ht_ringnode_st { struct ht_ringnode_st *rn_next; struct ht_ringnode_st *rn_prev; } mp_node; char *mp_name; struct ht_st { struct ht_st *q_next; struct ht_st *q_prev; int q_prio; int prio; char name[40]; int dispatches; enum ht_state_en { HT_STATE_SCHEDULER=0, HT_STATE_NEW=1, HT_STATE_READY=2, HT_STATE_WAITING=3, HT_STATE_WAITING_FOR_SCHED_TO_WORKER=4, HT_STATE_DEAD=5 } state; struct timeval spawned; struct timeval lastran; struct timeval running; struct ht_event_st *events; struct ht_mctx_st { struct ucontext_t { unsigned long uc_flags; struct ucontext_t *uc_link; struct stack_t { void *ss_sp; int ss_flags; unsigned long ss_size; } uc_stack; struct mcontext_t { long long gregs[23]; struct _libc_fpstate { unsigned short cwd; unsigned short swd; unsigned short ftw; unsigned short fop; unsigned long rip; unsigned long rdp; unsigned int mxcsr; unsigned int mxcr_mask; struct _libc_fpxreg { unsigned short significand[4]; unsigned short exponent; unsigned short __glibc_reserved1[3]; } _st[8]; struct _libc_xmmreg { unsigned int element[4]; } _xmm[16]; unsigned int __glibc_reserved1[24]; } *fpregs; unsigned long long __reserved1[8]; } uc_mcontext; struct __sigset_t { unsigned long __val[-1]; } uc_sigmask; struct _libc_fpstate __fpregs_mem; unsigned long long __ssp[4]; } uc; int restored; int error; } mctx; char *stack; unsigned int stacksize; long *stackguard; int stackloan; void *(*start_func)(void *); void *start_arg; int joinable; void *join_arg; void **data_value; int data_count; int cancelreq; unsigned int cancelstate; struct ht_cleanup_st { struct ht_cleanup_st *next; void (*func)(void *); void *arg; } *cleanups; struct ht_ring_st { struct ht_ringnode_st *r_hook; unsigned int r_nodes; } mutexring; } *mp_tid; struct ht_ring_st mp_queue; } *mp; } MSG; struct { struct ht_mutex_st { struct ht_ringnode_st mx_node; int mx_state; struct ht_st *mx_owner; unsigned long mx_count; } *mutex; } MUTEX; struct { struct ht_cond_st { unsigned long cn_state; unsigned int cn_waiters; } *cond; } COND; struct { struct ht_st *tid; } TID; struct { int (*func)(void *); void *arg; struct timeval tv; } FUNC; } ev_args; } *

user_defined_types: struct ht_st { struct ht_st *q_next; struct ht_st *q_prev; int q_prio; int prio; char name[40]; int dispatches; enum ht_state_en state; struct timeval spawned; struct timeval lastran; struct timeval running; struct ht_event_st *events; struct ht_mctx_st mctx; char *stack; unsigned int stacksize; long *stackguard; int stackloan; void *(*start_func)(void *); void *start_arg; int joinable; void *join_arg; void **data_value; int data_count; int cancelreq; unsigned int cancelstate; struct ht_cleanup_st *cleanups; struct ht_ring_st mutexring; }


decompiled_code:
void __noreturn ht_spawn_trampoline()
{
__int64 v0; // rax

v0 = (*(__int64 (__fastcall **)(_QWORD))(ht_current + 1136))(*(_QWORD *)(ht_current + 1144));
ht_exit(v0);
}

canonical_decompiled_code:
void __noreturn func10()
{
__int64 v0; // rax

v0 = (*(__int64 (__fastcall **)(_QWORD))(ht_current + 1136))(*(_QWORD *)(ht_current + 1144));
func9(v0);
}

original_code:
static
void
ht_spawn_trampoline(void)
{
    void *data;
    data = (*ht_current->start_func)(ht_current->start_arg);
    ht_exit(data);
    abort();
}

canonical_original_code:
static void ht_spawn_trampoline()
{
    void *data;
    data = (*ht_current->start_func)(ht_current->start_arg);
    ht_exit(data);
    abort();
}

variable_types:
data
void *


decompiled_code:
__int64 __fastcall ht_join(__int64 a1, _DWORD *a2, __int64 a3, __int64 a4, __int64 a5, __int64 a6)
{
__int64 v6; // rbx
unsigned int v7; // ebp
__int64 v8; // rax
__int64 v10; // rax

if ( ht_current == a1 )
goto LABEL_10;
v6 = a1;
if ( a1 )
{
v7 = *(_DWORD *)(a1 + 1152);
if ( !v7 )
{
*_errno_location() = 22;
return v7;
}
if ( ht_ctrl(1008, a2, a3, a4, a5, a6) != 1 )
goto LABEL_5;
LABEL_10:
*_errno_location() = 35;
return 0;
}
if ( ht_ctrl(1008, a2, a3, a4, a5, a6) == 1 )
goto LABEL_10;
v6 = *(_QWORD *)ht_DQ;
if ( !*(_QWORD *)ht_DQ )
{
v10 = ht_event(4456704LL, &ev_key_1);
ht_wait(v10);
v6 = *(_QWORD *)ht_DQ;
if ( !*(_QWORD *)ht_DQ )
goto LABEL_8;
goto LABEL_7;
}
LABEL_5:
if ( *(_DWORD *)(v6 + 68) == 5 )
goto LABEL_13;
v8 = ht_event(4456704LL, &ev_key_1);
ht_wait(v8);
LABEL_7:
if ( *(_DWORD *)(v6 + 68) != 5 )
{
LABEL_8:
*_errno_location() = 5;
return 0;
}
LABEL_13:
if ( a2 )
*(_QWORD *)a2 = *(_QWORD *)(v6 + 1160);
ht_pqueue_delete(ht_DQ, v6);
ht_tcb_free(v6);
return 1;
}

canonical_decompiled_code:
__int64 __fastcall func11(__int64 a1, _DWORD *a2, __int64 a3, __int64 a4, __int64 a5, __int64 a6)
{
__int64 v6; // rbx
unsigned int v7; // ebp
__int64 v8; // rax
__int64 v10; // rax

if ( ht_current == a1 )
goto LABEL_10;
v6 = a1;
if ( a1 )
{
v7 = *(_DWORD *)(a1 + 1152);
if ( !v7 )
{
*_errno_location() = 22;
return v7;
}
if ( func2(1008, a2, a3, a4, a5, a6) != 1 )
goto LABEL_5;
LABEL_10:
*_errno_location() = 35;
return 0;
}
if ( func2(1008, a2, a3, a4, a5, a6) == 1 )
goto LABEL_10;
v6 = *(_QWORD *)ht_DQ;
if ( !*(_QWORD *)ht_DQ )
{
v10 = ht_event(4456704LL, &ev_key_1);
ht_wait(v10);
v6 = *(_QWORD *)ht_DQ;
if ( !*(_QWORD *)ht_DQ )
goto LABEL_8;
goto LABEL_7;
}
LABEL_5:
if ( *(_DWORD *)(v6 + 68) == 5 )
goto LABEL_13;
v8 = ht_event(4456704LL, &ev_key_1);
ht_wait(v8);
LABEL_7:
if ( *(_DWORD *)(v6 + 68) != 5 )
{
LABEL_8:
*_errno_location() = 5;
return 0;
}
LABEL_13:
if ( a2 )
*(_QWORD *)a2 = *(_QWORD *)(v6 + 1160);
ht_pqueue_delete(ht_DQ, v6);
ht_tcb_free(v6);
return 1;
}

variable_types:
value
void **

user_defined_types: struct ht_mctx_st { struct ucontext_t uc; int restored; int error; }

user_defined_types: struct ht_ringnode_st { struct ht_ringnode_st *rn_next; struct ht_ringnode_st *rn_prev; }

user_defined_types: struct ht_ring_st { struct ht_ringnode_st *r_hook; unsigned int r_nodes; }


decompiled_code:
__int64 __fastcall ht_yield(__int64 a1)
{
int v1; // eax
_DWORD *v2; // rbp

if ( !a1 )
goto LABEL_7;
v1 = *(_DWORD *)(a1 + 68);
if ( v1 == 1 )
{
v2 = ht_NQ;
}
else
{
if ( v1 != 2 )
goto LABEL_9;
v2 = ht_RQ;
}
if ( (unsigned int)ht_pqueue_contains(v2, a1) )
{
ht_pqueue_favorite(v2, a1);
LABEL_7:
swapcontext((ucontext_t *)(ht_current + 128), (const ucontext_t *)(ht_sched + 128LL));
return 1LL;
}
LABEL_9:
*_errno_location() = 22;
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func12(__int64 a1)
{
int v1; // eax
_DWORD *v2; // rbp

if ( !a1 )
goto LABEL_7;
v1 = *(_DWORD *)(a1 + 68);
if ( v1 == 1 )
{
v2 = ht_NQ;
}
else
{
if ( v1 != 2 )
goto LABEL_9;
v2 = ht_RQ;
}
if ( (unsigned int)ht_pqueue_contains(v2, a1) )
{
ht_pqueue_favorite(v2, a1);
LABEL_7:
swapcontext((ucontext_t *)(ht_current + 128), (const ucontext_t *)(ht_sched + 128LL));
return 1LL;
}
LABEL_9:
*_errno_location() = 22;
return 0LL;
}

original_code:
int
ht_yield(ht_t to)
{
    ht_pqueue_t *q = ((void *)0);
    ;
    if (to != ((void *)0)) {
        switch (to->state) {
            case HT_STATE_NEW: q = &ht_NQ; break;
            case HT_STATE_READY: q = &ht_RQ; break;
            default: q = ((void *)0);
        }
        if (q == ((void *)0) || !ht_pqueue_contains(q, to))
            return ((*__errno_location ()) = (22), ((0)));
    }
    if (to != ((void *)0) && q != ((void *)0))
        ht_pqueue_favorite(q, to);
    if (to != ((void *)0))
        ;
    else
        ;
    swapcontext(&((&ht_current->mctx)->uc), &((&ht_sched->mctx)->uc));;
    ;
    ;
    return (!(0));
}

canonical_original_code:
int ht_yield(struct ht_st *to)
{
    struct ht_pqueue_st *q = ((void *)0);
    ;
    if (to != ((void *)0)) {
        switch (to->state) {
            case HT_STATE_NEW: q = &ht_NQ; break;
            case HT_STATE_READY: q = &ht_RQ; break;
            default: q = ((void *)0);
        }
        if (q == ((void *)0) || !ht_pqueue_contains(q, to))
            return ((*__errno_location ()) = (22), ((0)));
    }
    if (to != ((void *)0) && q != ((void *)0))
        ht_pqueue_favorite(q, to);
    if (to != ((void *)0))
        ;
    else
        ;
    swapcontext(&((&ht_current->mctx)->uc), &((&ht_sched->mctx)->uc));;
    ;
    ;
    return (!(0));
}

variable_types: struct ht_pqueue_st { struct ht_st { struct ht_st *q_next; struct ht_st *q_prev; int q_prio; int prio; char name[40]; int dispatches; enum ht_state_en { HT_STATE_SCHEDULER=0, HT_STATE_NEW=1, HT_STATE_READY=2, HT_STATE_WAITING=3, HT_STATE_WAITING_FOR_SCHED_TO_WORKER=4, HT_STATE_DEAD=5 } state; struct timeval { long tv_sec; long tv_usec; } spawned; struct timeval lastran; struct timeval running; struct ht_event_st { struct ht_event_st *ev_next; struct ht_event_st *ev_prev; enum ht_status_t { HT_STATUS_PENDING=0, HT_STATUS_OCCURRED=1, HT_STATUS_FAILED=2 } ev_status; int ev_type; int ev_goal; union { struct { int fd; } FD; struct { int *n; int nfd; struct fd_set { long __fds_bits[-1]; } *rfds; } SELECT; struct { int fini; } TASK; struct { struct timeval tv; } TIME; struct { struct ht_msgport_st { struct ht_ringnode_st { struct ht_ringnode_st *rn_next; struct ht_ringnode_st *rn_prev; } mp_node; char *mp_name; struct ht_st *mp_tid; struct ht_ring_st { struct ht_ringnode_st *r_hook; unsigned int r_nodes; } mp_queue; } *mp; } MSG; struct { struct ht_mutex_st { struct ht_ringnode_st mx_node; int mx_state; struct ht_st *mx_owner; unsigned long mx_count; } *mutex; } MUTEX; struct { struct ht_cond_st { unsigned long cn_state; unsigned int cn_waiters; } *cond; } COND; struct { struct ht_st *tid; } TID; struct { int (*func)(void *); void *arg; struct timeval tv; } FUNC; } ev_args; } *events; struct ht_mctx_st { struct ucontext_t { unsigned long uc_flags; struct ucontext_t *uc_link; struct stack_t { void *ss_sp; int ss_flags; unsigned long ss_size; } uc_stack; struct mcontext_t { long long gregs[23]; struct _libc_fpstate { unsigned short cwd; unsigned short swd; unsigned short ftw; unsigned short fop; unsigned long rip; unsigned long rdp; unsigned int mxcsr; unsigned int mxcr_mask; struct _libc_fpxreg { unsigned short significand[4]; unsigned short exponent; unsigned short __glibc_reserved1[3]; } _st[8]; struct _libc_xmmreg { unsigned int element[4]; } _xmm[16]; unsigned int __glibc_reserved1[24]; } *fpregs; unsigned long long __reserved1[8]; } uc_mcontext; struct __sigset_t { unsigned long __val[-1]; } uc_sigmask; struct _libc_fpstate __fpregs_mem; unsigned long long __ssp[4]; } uc; int restored; int error; } mctx; char *stack; unsigned int stacksize; long *stackguard; int stackloan; void *(*start_func)(void *); void *start_arg; int joinable; void *join_arg; void **data_value; int data_count; int cancelreq; unsigned int cancelstate; struct ht_cleanup_st { struct ht_cleanup_st *next; void (*func)(void *); void *arg; } *cleanups; struct ht_ring_st mutexring; } *q_head; int q_num; } *

user_defined_types: struct ht_pqueue_st { struct ht_st *q_head; int q_num; }

user_defined_types: struct ht_event_st { struct ht_event_st *ev_next; struct ht_event_st *ev_prev; enum ht_status_t ev_status; int ev_type; int ev_goal; union { struct { int fd; } FD; struct { int *n; int nfd; struct fd_set *rfds; } SELECT; struct { int fini; } TASK; struct { struct timeval tv; } TIME; struct { struct ht_msgport_st *mp; } MSG; struct { struct ht_mutex_st *mutex; } MUTEX; struct { struct ht_cond_st *cond; } COND; struct { struct ht_st *tid; } TID; struct { int (*func)(void *); void *arg; struct timeval tv; } FUNC; } ev_args; }

user_defined_types: struct ucontext_t { unsigned long uc_flags; struct ucontext_t *uc_link; struct stack_t uc_stack; struct mcontext_t uc_mcontext; struct __sigset_t uc_sigmask; struct _libc_fpstate __fpregs_mem; unsigned long long __ssp[4]; }

user_defined_types: struct mcontext_t { long long gregs[23]; struct _libc_fpstate *fpregs; unsigned long long __reserved1[8]; }


decompiled_code:
__int64 __fastcall ht_suspend(__int64 a1)
{
int v1; // eax
unsigned int v2; // ebp
_DWORD *v4; // r12

if ( a1 )
{
if ( ht_sched == a1 || ht_current == a1 )
goto LABEL_9;
v1 = *(_DWORD *)(a1 + 68);
switch ( v1 )
{
case 2:
v4 = ht_RQ;
break;
case 3:
v4 = ht_WQ;
break;
case 1:
v4 = ht_NQ;
break;
default:
LABEL_9:
*_errno_location() = 1;
return 0;
}
v2 = ht_pqueue_contains(v4, a1);
if ( v2 )
{
ht_pqueue_delete(v4, a1);
ht_pqueue_insert(ht_SQ, 0LL, a1);
v2 = 1;
}
else
{
*_errno_location() = 3;
}
}
else
{
*_errno_location() = 22;
v2 = 0;
}
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func13(__int64 a1)
{
int v1; // eax
unsigned int v2; // ebp
_DWORD *v4; // r12

if ( a1 )
{
if ( ht_sched == a1 || ht_current == a1 )
goto LABEL_9;
v1 = *(_DWORD *)(a1 + 68);
switch ( v1 )
{
case 2:
v4 = ht_RQ;
break;
case 3:
v4 = ht_WQ;
break;
case 1:
v4 = ht_NQ;
break;
default:
LABEL_9:
*_errno_location() = 1;
return 0;
}
v2 = ht_pqueue_contains(v4, a1);
if ( v2 )
{
ht_pqueue_delete(v4, a1);
ht_pqueue_insert(ht_SQ, 0LL, a1);
v2 = 1;
}
else
{
*_errno_location() = 3;
}
}
else
{
*_errno_location() = 22;
v2 = 0;
}
return v2;
}

original_code:
int
ht_suspend(ht_t t)
{
    ht_pqueue_t *q;
    if (t == ((void *)0))
        return ((*__errno_location ()) = (22), ((0)));
    if (t == ht_sched || t == ht_current)
        return ((*__errno_location ()) = (1), ((0)));
    switch (t->state) {
        case HT_STATE_NEW: q = &ht_NQ; break;
        case HT_STATE_READY: q = &ht_RQ; break;
        case HT_STATE_WAITING: q = &ht_WQ; break;
        default: q = ((void *)0);
    }
    if (q == ((void *)0))
        return ((*__errno_location ()) = (1), ((0)));
    if (!ht_pqueue_contains(q, t))
        return ((*__errno_location ()) = (3), ((0)));
    ht_pqueue_delete(q, t);
    ht_pqueue_insert(&ht_SQ, 0, t);
    ;
    return (!(0));
}

canonical_original_code:
int ht_suspend(struct ht_st *t)
{
    struct ht_pqueue_st *q;
    if (t == ((void *)0))
        return ((*__errno_location ()) = (22), ((0)));
    if (t == ht_sched || t == ht_current)
        return ((*__errno_location ()) = (1), ((0)));
    switch (t->state) {
        case HT_STATE_NEW: q = &ht_NQ; break;
        case HT_STATE_READY: q = &ht_RQ; break;
        case HT_STATE_WAITING: q = &ht_WQ; break;
        default: q = ((void *)0);
    }
    if (q == ((void *)0))
        return ((*__errno_location ()) = (1), ((0)));
    if (!ht_pqueue_contains(q, t))
        return ((*__errno_location ()) = (3), ((0)));
    ht_pqueue_delete(q, t);
    ht_pqueue_insert(&ht_SQ, 0, t);
    ;
    return (!(0));
}

user_defined_types: enum ht_state_en { HT_STATE_SCHEDULER=0, HT_STATE_NEW=1, HT_STATE_READY=2, HT_STATE_WAITING=3, HT_STATE_WAITING_FOR_SCHED_TO_WORKER=4, HT_STATE_DEAD=5 }

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

user_defined_types: struct _libc_fpstate { unsigned short cwd; unsigned short swd; unsigned short ftw; unsigned short fop; unsigned long rip; unsigned long rdp; unsigned int mxcsr; unsigned int mxcr_mask; struct _libc_fpxreg _st[8]; struct _libc_xmmreg _xmm[16]; unsigned int __glibc_reserved1[24]; }

user_defined_types: struct ht_msgport_st { struct ht_ringnode_st mp_node; char *mp_name; struct ht_st *mp_tid; struct ht_ring_st mp_queue; }


decompiled_code:
__int64 __fastcall ht_resume(__int64 a1)
{
unsigned int v2; // ebp
int v4; // eax
_DWORD *v5; // rdi

if ( a1 )
{
if ( ht_sched == a1 || ht_current == a1 )
{
*_errno_location() = 1;
v2 = 0;
}
else
{
v2 = ht_pqueue_contains(ht_SQ, a1);
if ( v2 )
{
ht_pqueue_delete(ht_SQ, a1);
v4 = *(_DWORD *)(a1 + 68);
if ( v4 == 2 )
{
v5 = ht_RQ;
}
else if ( v4 == 3 )
{
v5 = ht_WQ;
}
else
{
v5 = 0LL;
if ( v4 == 1 )
v5 = ht_NQ;
}
ht_pqueue_insert(v5, 0LL, a1);
v2 = 1;
}
else
{
*_errno_location() = 1;
}
}
}
else
{
*_errno_location() = 22;
v2 = 0;
}
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func14(__int64 a1)
{
unsigned int v2; // ebp
int v4; // eax
_DWORD *v5; // rdi

if ( a1 )
{
if ( ht_sched == a1 || ht_current == a1 )
{
*_errno_location() = 1;
v2 = 0;
}
else
{
v2 = ht_pqueue_contains(ht_SQ, a1);
if ( v2 )
{
ht_pqueue_delete(ht_SQ, a1);
v4 = *(_DWORD *)(a1 + 68);
if ( v4 == 2 )
{
v5 = ht_RQ;
}
else if ( v4 == 3 )
{
v5 = ht_WQ;
}
else
{
v5 = 0LL;
if ( v4 == 1 )
v5 = ht_NQ;
}
ht_pqueue_insert(v5, 0LL, a1);
v2 = 1;
}
else
{
*_errno_location() = 1;
}
}
}
else
{
*_errno_location() = 22;
v2 = 0;
}
return v2;
}

original_code:
int
ht_resume(ht_t t)
{
    ht_pqueue_t *q;
    if (t == ((void *)0))
        return ((*__errno_location ()) = (22), ((0)));
    if (t == ht_sched || t == ht_current)
        return ((*__errno_location ()) = (1), ((0)));
    if (!ht_pqueue_contains(&ht_SQ, t))
        return ((*__errno_location ()) = (1), ((0)));
    ht_pqueue_delete(&ht_SQ, t);
    switch (t->state) {
        case HT_STATE_NEW: q = &ht_NQ; break;
        case HT_STATE_READY: q = &ht_RQ; break;
        case HT_STATE_WAITING: q = &ht_WQ; break;
        default: q = ((void *)0);
    }
    ht_pqueue_insert(q, 0, t);
    ;
    return (!(0));
}

canonical_original_code:
int ht_resume(struct ht_st *t)
{
    struct ht_pqueue_st *q;
    if (t == ((void *)0))
        return ((*__errno_location ()) = (22), ((0)));
    if (t == ht_sched || t == ht_current)
        return ((*__errno_location ()) = (1), ((0)));
    if (!ht_pqueue_contains(&ht_SQ, t))
        return ((*__errno_location ()) = (1), ((0)));
    ht_pqueue_delete(&ht_SQ, t);
    switch (t->state) {
        case HT_STATE_NEW: q = &ht_NQ; break;
        case HT_STATE_READY: q = &ht_RQ; break;
        case HT_STATE_WAITING: q = &ht_WQ; break;
        default: q = ((void *)0);
    }
    ht_pqueue_insert(q, 0, t);
    ;
    return (!(0));
}

user_defined_types: struct ht_cleanup_st { struct ht_cleanup_st *next; void (*func)(void *); void *arg; }

user_defined_types: enum ht_status_t { HT_STATUS_PENDING=0, HT_STATUS_OCCURRED=1, HT_STATUS_FAILED=2 }

user_defined_types: struct stack_t { void *ss_sp; int ss_flags; unsigned long ss_size; }

user_defined_types: struct __sigset_t { unsigned long __val[-1]; }


decompiled_code:
unsigned int __fastcall ht_fdmode(int fd, int a2)
{
unsigned int result; // eax

result = fcntl(fd, 3, 0LL);
if ( result != -1 )
{
if ( (result & 0x800) != 0 )
{
if ( a2 == 1 )
{
BYTE1(result) &= 0xF7u;
fcntl(fd, 4, result);
}
result = 2;
}
else if ( a2 == 2 )
{
BYTE1(result) |= 8u;
fcntl(fd, 4, result);
result = 1;
}
else
{
result = 1;
}
}
return result;
}

canonical_decompiled_code:
unsigned int __fastcall func15(int fd, int a2)
{
unsigned int result; // eax

result = fcntl(fd, 3, 0LL);
if ( result != -1 )
{
if ( (result & 0x800) != 0 )
{
if ( a2 == 1 )
{
BYTE1(result) &= 0xF7u;
fcntl(fd, 4, result);
}
result = 2;
}
else if ( a2 == 2 )
{
BYTE1(result) |= 8u;
fcntl(fd, 4, result);
result = 1;
}
else
{
result = 1;
}
}
return result;
}

original_code:
int
ht_fdmode(int fd, int newmode)
{
    int fdmode;
    int oldmode;
    if ((fdmode = fcntl(fd, 3, ((void *)0))) == -1)
        oldmode = HT_FDMODE_ERROR;
    else if (fdmode & 04000)
        oldmode = HT_FDMODE_NONBLOCK;
    else
        oldmode = HT_FDMODE_BLOCK;
    if (oldmode == HT_FDMODE_BLOCK && newmode == HT_FDMODE_NONBLOCK)
        fcntl(fd, 4, (fdmode | 04000));
    if (oldmode == HT_FDMODE_NONBLOCK && newmode == HT_FDMODE_BLOCK)
        fcntl(fd, 4, (fdmode & ~(04000)));
    return oldmode;
}

variable_types: fd int

variable_types: newmode int

variable_types: fdmode int

variable_types: oldmode int


decompiled_code:
__int64 __fastcall ht_nap(__int64 a1, __int64 a2)
{
unsigned int v2; // ebx
__time_t v4; // rdx
__suseconds_t v5; // rax
__int64 v6; // rax
__int64 v7; // [rsp+0h] [rbp-28h] BYREF
__int64 v8; // [rsp+8h] [rbp-20h]
struct timeval tv; // [rsp+10h] [rbp-18h] BYREF

v7 = a1;
v8 = a2;
if ( (unsigned int)ht_time_cmp(&v7, ht_time_zero) )
{
gettimeofday(&tv, 0LL);
v4 = tv.tv_sec + v7;
tv.tv_sec += v7;
v5 = tv.tv_usec + v8;
tv.tv_usec = v5;
if ( v5 > 1000000 )
{
tv.tv_sec = v4 + 1;
tv.tv_usec = v5 - 1000000;
}
v6 = ht_event(4194320LL, &ev_key_0);
ht_wait(v6);
v2 = 1;
}
else
{
v2 = 0;
*_errno_location() = 22;
}
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func16(__int64 a1, __int64 a2)
{
unsigned int v2; // ebx
__time_t v4; // rdx
__suseconds_t v5; // rax
__int64 v6; // rax
__int64 v7; // [rsp+0h] [rbp-28h] BYREF
__int64 v8; // [rsp+8h] [rbp-20h]
struct timeval tv; // [rsp+10h] [rbp-18h] BYREF

v7 = a1;
v8 = a2;
if ( (unsigned int)ht_time_cmp(&v7, ht_time_zero) )
{
gettimeofday(&tv, 0LL);
v4 = tv.tv_sec + v7;
tv.tv_sec += v7;
v5 = tv.tv_usec + v8;
tv.tv_usec = v5;
if ( v5 > 1000000 )
{
tv.tv_sec = v4 + 1;
tv.tv_usec = v5 - 1000000;
}
v6 = ht_event(4194320LL, &ev_key_0);
ht_wait(v6);
v2 = 1;
}
else
{
v2 = 0;
*_errno_location() = 22;
}
return v2;
}

original_code:
int
ht_nap(ht_time_t naptime)
{
    ht_time_t until;
    ht_event_t ev;
    static ht_key_t ev_key = (-1);
    if (ht_time_cmp(&naptime, &ht_time_zero) == 0)
        return ((*__errno_location ()) = (22), ((0)));
    do { if (((ht_time_t *)(0)) == (ht_time_t *)(0)) gettimeofday((&until), ((void *)0)); else { (&until)->tv_sec = ((ht_time_t *)(0))->tv_sec; (&until)->tv_usec = ((ht_time_t *)(0))->tv_usec; } } while (0);
    (&until)->tv_sec += (&naptime)->tv_sec; (&until)->tv_usec += (&naptime)->tv_usec; if ((&until)->tv_usec > 1000000) { (&until)->tv_sec += 1; (&until)->tv_usec -= 1000000; };
    ev = ht_event((1<<(4))|(1<<(22)), &ev_key, until);
    ht_wait(ev);
    return (!(0));
}

canonical_original_code:
int ht_nap(struct timeval naptime)
{
    struct timeval until;
    struct ht_event_st *ev;
    static int ev_key = (-1);
    if (ht_time_cmp(&naptime, &ht_time_zero) == 0)
        return ((*__errno_location ()) = (22), ((0)));
    do { if (((struct timeval *)(0)) == (struct timeval *)(0)) gettimeofday((&until), ((void *)0)); else { (&until)->tv_sec = ((struct timeval *)(0))->tv_sec; (&until)->tv_usec = ((struct timeval *)(0))->tv_usec; } } while (0);
    (&until)->tv_sec += (&naptime)->tv_sec; (&until)->tv_usec += (&naptime)->tv_usec; if ((&until)->tv_usec > 1000000) { (&until)->tv_sec += 1; (&until)->tv_usec -= 1000000; };
    ev = ht_event((1<<(4))|(1<<(22)), &ev_key, until);
    ht_wait(ev);
    return (!(0));
}

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

user_defined_types: struct ht_mutex_st { struct ht_ringnode_st mx_node; int mx_state; struct ht_st *mx_owner; unsigned long mx_count; }

user_defined_types: struct ht_cond_st { unsigned long cn_state; unsigned int cn_waiters; }

user_defined_types: struct _libc_fpxreg { unsigned short significand[4]; unsigned short exponent; unsigned short __glibc_reserved1[3]; }

user_defined_types: struct _libc_xmmreg { unsigned int element[4]; }


decompiled_code:
__int64 __fastcall ht_once(_DWORD *a1, void (__fastcall *a2)(__int64), __int64 a3)
{
__int64 result; // rax

if ( a1 && a2 )
{
if ( *a1 != 1 )
a2(a3);
*a1 = 1;
result = 1LL;
}
else
{
*_errno_location() = 22;
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func17(_DWORD *a1, void (__fastcall *a2)(__int64), __int64 a3)
{
__int64 result; // rax

if ( a1 && a2 )
{
if ( *a1 != 1 )
a2(a3);
*a1 = 1;
result = 1LL;
}
else
{
*_errno_location() = 22;
result = 0LL;
}
return result;
}

original_code:
int
ht_once(ht_once_t *oncectrl, void (*constructor)(void *), void *arg)
{
    if (oncectrl == ((void *)0) || constructor == ((void *)0))
        return ((*__errno_location ()) = (22), ((0)));
    if (*oncectrl != (!(0)))
        constructor(arg);
    *oncectrl = (!(0));
    return (!(0));
}

canonical_original_code:
int ht_once(int *oncectrl, void (*constructor)(void *), void *arg)
{
    if (oncectrl == ((void *)0) || constructor == ((void *)0))
        return ((*__errno_location ()) = (22), ((0)));
    if (*oncectrl != (!(0)))
        constructor(arg);
    *oncectrl = (!(0));
    return (!(0));
}

variable_types:
oncectrl
int *

variable_types:
constructor
void (*)(void *)


decompiled_code:
void __noreturn ht_uctx_trampoline()
{
__int64 v0; // [rsp+10h] [rbp-28h]
void (__fastcall *v1)(__int64); // [rsp+18h] [rbp-20h]
__int64 v2; // [rsp+20h] [rbp-18h]

v0 = *((_QWORD *)&ht_uctx_trampoline_ctx + 2);
v1 = (void (__fastcall *)(__int64))*((_QWORD *)&ht_uctx_trampoline_ctx + 3);
v2 = *((_QWORD *)&ht_uctx_trampoline_ctx + 4);
swapcontext((ucontext_t *)(*((_QWORD *)&ht_uctx_trampoline_ctx + 1) + 32LL), ht_uctx_trampoline_ctx);
v1(v2);
if ( v0 )
{
*_errno_location() = *(_DWORD *)(v0 + 1004);
*(_DWORD *)(v0 + 1000) = 1;
setcontext((const ucontext_t *)(v0 + 32));
}
exit(0);
}

canonical_decompiled_code:
void __noreturn func0()
{
__int64 v0; // [rsp+10h] [rbp-28h]
void (__fastcall *v1)(__int64); // [rsp+18h] [rbp-20h]
__int64 v2; // [rsp+20h] [rbp-18h]

v0 = *((_QWORD *)&ht_uctx_trampoline_ctx + 2);
v1 = (void (__fastcall *)(__int64))*((_QWORD *)&ht_uctx_trampoline_ctx + 3);
v2 = *((_QWORD *)&ht_uctx_trampoline_ctx + 4);
swapcontext((ucontext_t *)(*((_QWORD *)&ht_uctx_trampoline_ctx + 1) + 32LL), ht_uctx_trampoline_ctx);
v1(v2);
if ( v0 )
{
*_errno_location() = *(_DWORD *)(v0 + 1004);
*(_DWORD *)(v0 + 1000) = 1;
setcontext((const ucontext_t *)(v0 + 32));
}
exit(0);
}

original_code:
static
void
ht_uctx_trampoline(void)
{
    volatile ht_uctx_trampoline_t ctx;
    ctx.mctx_parent = ht_uctx_trampoline_ctx.mctx_parent;
    ctx.uctx_this = ht_uctx_trampoline_ctx.uctx_this;
    ctx.uctx_after = ht_uctx_trampoline_ctx.uctx_after;
    ctx.start_func = ht_uctx_trampoline_ctx.start_func;
    ctx.start_arg = ht_uctx_trampoline_ctx.start_arg;
    swapcontext(&((&(ctx.uctx_this->uc_mctx))->uc), &((ctx.mctx_parent)->uc));;
    (*ctx.start_func)(ctx.start_arg);
    if (ctx.uctx_after != ((void *)0))
        ( (*__errno_location ()) = (&(ctx.uctx_after->uc_mctx))->error, (&(ctx.uctx_after->uc_mctx))->restored = 1, (void)setcontext(&(&(ctx.uctx_after->uc_mctx))->uc) );
    exit(0);
    return;
}

canonical_original_code:
static void ht_uctx_trampoline()
{
    struct ht_uctx_trampoline_t ctx;
    ctx.mctx_parent = ht_uctx_trampoline_ctx.mctx_parent;
    ctx.uctx_this = ht_uctx_trampoline_ctx.uctx_this;
    ctx.uctx_after = ht_uctx_trampoline_ctx.uctx_after;
    ctx.start_func = ht_uctx_trampoline_ctx.start_func;
    ctx.start_arg = ht_uctx_trampoline_ctx.start_arg;
    swapcontext(&((&(ctx.uctx_this->uc_mctx))->uc), &((ctx.mctx_parent)->uc));;
    (*ctx.start_func)(ctx.start_arg);
    if (ctx.uctx_after != ((void *)0))
        ( (*__errno_location ()) = (&(ctx.uctx_after->uc_mctx))->error, (&(ctx.uctx_after->uc_mctx))->restored = 1, (void)setcontext(&(&(ctx.uctx_after->uc_mctx))->uc) );
    exit(0);
    return;
}

variable_types: struct ht_uctx_trampoline_t { struct ht_mctx_st { struct ucontext_t { unsigned long uc_flags; struct ucontext_t *uc_link; struct stack_t { void *ss_sp; int ss_flags; unsigned long ss_size; } uc_stack; struct mcontext_t { long long gregs[23]; struct _libc_fpstate { unsigned short cwd; unsigned short swd; unsigned short ftw; unsigned short fop; unsigned long rip; unsigned long rdp; unsigned int mxcsr; unsigned int mxcr_mask; struct _libc_fpxreg { unsigned short significand[4]; unsigned short exponent; unsigned short __glibc_reserved1[3]; } _st[8]; struct _libc_xmmreg { unsigned int element[4]; } _xmm[16]; unsigned int __glibc_reserved1[24]; } *fpregs; unsigned long long __reserved1[8]; } uc_mcontext; struct __sigset_t { unsigned long __val[-1]; } uc_sigmask; struct _libc_fpstate __fpregs_mem; unsigned long long __ssp[4]; } uc; int restored; int error; } *mctx_parent; struct ht_uctx_st { int uc_stack_own; char *uc_stack_ptr; unsigned long uc_stack_len; int uc_mctx_set; struct ht_mctx_st uc_mctx; } *uctx_this; struct ht_uctx_st *uctx_after; void (*start_func)(void *); void *start_arg; }

user_defined_types: struct ht_uctx_trampoline_t { struct ht_mctx_st *mctx_parent; struct ht_uctx_st *uctx_this; struct ht_uctx_st *uctx_after; void (*start_func)(void *); void *start_arg; }

user_defined_types: struct ht_mctx_st { struct ucontext_t uc; int restored; int error; }


decompiled_code:
__int64 __fastcall ht_uctx_create(_QWORD *a1)
{
_QWORD *v1; // rax
__int64 result; // rax

if ( a1 )
{
v1 = malloc(0x3F0uLL);
if ( v1 )
{
*(_DWORD *)v1 = 0;
v1[1] = 0LL;
v1[2] = 0LL;
*((_DWORD *)v1 + 6) = 0;
memset(v1 + 4, 0, 0x3D0uLL);
*a1 = v1;
result = 1LL;
}
else
{
result = 0LL;
}
}
else
{
*_errno_location() = 22;
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(_QWORD *a1)
{
_QWORD *v1; // rax
__int64 result; // rax

if ( a1 )
{
v1 = malloc(0x3F0uLL);
if ( v1 )
{
*(_DWORD *)v1 = 0;
v1[1] = 0LL;
v1[2] = 0LL;
*((_DWORD *)v1 + 6) = 0;
memset(v1 + 4, 0, 0x3D0uLL);
*a1 = v1;
result = 1LL;
}
else
{
result = 0LL;
}
}
else
{
*_errno_location() = 22;
result = 0LL;
}
return result;
}

original_code:
int
ht_uctx_create(
    ht_uctx_t *puctx)
{
    ht_uctx_t uctx;
    if (puctx == ((void *)0))
        return ((*__errno_location ()) = (22), ((0)));
    if ((uctx = (ht_uctx_t)malloc(sizeof(struct ht_uctx_st))) == ((void *)0))
        return ((*__errno_location ()) = ((*__errno_location ())), ((0)));
    uctx->uc_stack_own = (0);
    uctx->uc_stack_ptr = ((void *)0);
    uctx->uc_stack_len = 0;
    uctx->uc_mctx_set = (0);
    memset((void *)&uctx->uc_mctx, 0, sizeof(ht_mctx_t));
    *puctx = uctx;
    return (!(0));
}

canonical_original_code:
int ht_uctx_create(struct ht_uctx_st **puctx)
{
    struct ht_uctx_st *uctx;
    if (puctx == ((void *)0))
        return ((*__errno_location ()) = (22), ((0)));
    if ((uctx = (struct ht_uctx_st *)malloc(sizeof(struct ht_uctx_st))) == ((void *)0))
        return ((*__errno_location ()) = ((*__errno_location ())), ((0)));
    uctx->uc_stack_own = (0);
    uctx->uc_stack_ptr = ((void *)0);
    uctx->uc_stack_len = 0;
    uctx->uc_mctx_set = (0);
    memset((void *)&uctx->uc_mctx, 0, sizeof(ht_mctx_t));
    *puctx = uctx;
    return (!(0));
}

variable_types: struct ht_uctx_st { int uc_stack_own; char *uc_stack_ptr; unsigned long uc_stack_len; int uc_mctx_set; struct ht_mctx_st { struct ucontext_t { unsigned long uc_flags; struct ucontext_t *uc_link; struct stack_t { void *ss_sp; int ss_flags; unsigned long ss_size; } uc_stack; struct mcontext_t { long long gregs[23]; struct _libc_fpstate { unsigned short cwd; unsigned short swd; unsigned short ftw; unsigned short fop; unsigned long rip; unsigned long rdp; unsigned int mxcsr; unsigned int mxcr_mask; struct _libc_fpxreg { unsigned short significand[4]; unsigned short exponent; unsigned short __glibc_reserved1[3]; } _st[8]; struct _libc_xmmreg { unsigned int element[4]; } _xmm[16]; unsigned int __glibc_reserved1[24]; } *fpregs; unsigned long long __reserved1[8]; } uc_mcontext; struct __sigset_t { unsigned long __val[-1]; } uc_sigmask; struct _libc_fpstate __fpregs_mem; unsigned long long __ssp[4]; } uc; int restored; int error; } uc_mctx; } **

user_defined_types: struct ht_uctx_st { int uc_stack_own; char *uc_stack_ptr; unsigned long uc_stack_len; int uc_mctx_set; struct ht_mctx_st uc_mctx; }


decompiled_code:
__int64 __fastcall ht_uctx_make(__int64 a1, char *a2, size_t a3, const sigset_t *a4, __int64 a5, __int64 a6, __int64 a7)
{
__int64 result; // rax
sigset_t v12; // [rsp+0h] [rbp-488h] BYREF
ucontext_t oucp; // [rsp+80h] [rbp-408h] BYREF

if ( a3 <= 0x3FFF || a5 == 0 || !a1 )
{
*_errno_location() = 22;
result = 0LL;
}
else
{
if ( a2 )
{
*(_DWORD *)a1 = 0;
}
else
{
a2 = (char *)malloc(a3);
if ( !a2 )
return 0LL;
*(_DWORD *)a1 = 1;
}
*(_QWORD *)(a1 + 8) = a2;
*(_QWORD *)(a1 + 16) = a3;
result = ht_mctx_set(a1 + 32, ht_uctx_trampoline, a2, &a2[a3]);
if ( (_DWORD)result )
{
ht_uctx_trampoline_ctx[0] = &oucp;
ht_uctx_trampoline_ctx[1] = a1;
ht_uctx_trampoline_ctx[2] = a7;
ht_uctx_trampoline_ctx[3] = a5;
ht_uctx_trampoline_ctx[4] = a6;
if ( a4 )
{
sigprocmask(2, a4, &v12);
swapcontext(&oucp, (const ucontext_t *)(a1 + 32));
sigprocmask(2, &v12, 0LL);
}
else
{
swapcontext(&oucp, (const ucontext_t *)(a1 + 32));
}
*(_DWORD *)(a1 + 24) = 1;
result = 1LL;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, char *a2, size_t a3, const sigset_t *a4, __int64 a5, __int64 a6, __int64 a7)
{
__int64 result; // rax
sigset_t v12; // [rsp+0h] [rbp-488h] BYREF
ucontext_t oucp; // [rsp+80h] [rbp-408h] BYREF

if ( a3 <= 0x3FFF || a5 == 0 || !a1 )
{
*_errno_location() = 22;
result = 0LL;
}
else
{
if ( a2 )
{
*(_DWORD *)a1 = 0;
}
else
{
a2 = (char *)malloc(a3);
if ( !a2 )
return 0LL;
*(_DWORD *)a1 = 1;
}
*(_QWORD *)(a1 + 8) = a2;
*(_QWORD *)(a1 + 16) = a3;
result = ht_mctx_set(a1 + 32, ht_uctx_trampoline, a2, &a2[a3]);
if ( (_DWORD)result )
{
ht_uctx_trampoline_ctx[0] = &oucp;
ht_uctx_trampoline_ctx[1] = a1;
ht_uctx_trampoline_ctx[2] = a7;
ht_uctx_trampoline_ctx[3] = a5;
ht_uctx_trampoline_ctx[4] = a6;
if ( a4 )
{
sigprocmask(2, a4, &v12);
swapcontext(&oucp, (const ucontext_t *)(a1 + 32));
sigprocmask(2, &v12, 0LL);
}
else
{
swapcontext(&oucp, (const ucontext_t *)(a1 + 32));
}
*(_DWORD *)(a1 + 24) = 1;
result = 1LL;
}
}
return result;
}

original_code:
int
ht_uctx_make(
    ht_uctx_t uctx,
    char *sk_addr, size_t sk_size,
    const sigset_t *sigmask,
    void (*start_func)(void *), void *start_arg,
    ht_uctx_t uctx_after)
{
    ht_mctx_t mctx_parent;
    sigset_t ss;
    if (uctx == ((void *)0) || start_func == ((void *)0) || sk_size < 16*1024)
        return ((*__errno_location ()) = (22), ((0)));
    if (sk_addr == ((void *)0)) {
        if ((sk_addr = (char *)malloc(sk_size)) == ((void *)0))
            return ((*__errno_location ()) = ((*__errno_location ())), ((0)));
        uctx->uc_stack_own = (!(0));
    }
    else
        uctx->uc_stack_own = (0);
    uctx->uc_stack_ptr = sk_addr;
    uctx->uc_stack_len = sk_size;
    if (!ht_mctx_set(&uctx->uc_mctx, ht_uctx_trampoline,
                      uctx->uc_stack_ptr, uctx->uc_stack_ptr+uctx->uc_stack_len))
        return ((*__errno_location ()) = ((*__errno_location ())), ((0)));
    ht_uctx_trampoline_ctx.mctx_parent = &mctx_parent;
    ht_uctx_trampoline_ctx.uctx_this = uctx;
    ht_uctx_trampoline_ctx.uctx_after = uctx_after;
    ht_uctx_trampoline_ctx.start_func = start_func;
    ht_uctx_trampoline_ctx.start_arg = start_arg;
    if (sigmask != ((void *)0))
        sigprocmask(2, sigmask, &ss);
    swapcontext(&((&mctx_parent)->uc), &((&(uctx->uc_mctx))->uc));;
    if (sigmask != ((void *)0))
        sigprocmask(2, &ss, ((void *)0));
    uctx->uc_mctx_set = (!(0));
    return (!(0));
}

canonical_original_code:
int ht_uctx_make(struct ht_uctx_st *uctx, char *sk_addr, unsigned long sk_size, struct __sigset_t *sigmask, void (*start_func)(void *), void *start_arg, struct ht_uctx_st *uctx_after)
{
    struct ht_mctx_st mctx_parent;
    struct __sigset_t ss;
    if (uctx == ((void *)0) || start_func == ((void *)0) || sk_size < 16*1024)
        return ((*__errno_location ()) = (22), ((0)));
    if (sk_addr == ((void *)0)) {
        if ((sk_addr = (char *)malloc(sk_size)) == ((void *)0))
            return ((*__errno_location ()) = ((*__errno_location ())), ((0)));
        uctx->uc_stack_own = (!(0));
    }
    else
        uctx->uc_stack_own = (0);
    uctx->uc_stack_ptr = sk_addr;
    uctx->uc_stack_len = sk_size;
    if (!ht_mctx_set(&uctx->uc_mctx, ht_uctx_trampoline,
                      uctx->uc_stack_ptr, uctx->uc_stack_ptr+uctx->uc_stack_len))
        return ((*__errno_location ()) = ((*__errno_location ())), ((0)));
    ht_uctx_trampoline_ctx.mctx_parent = &mctx_parent;
    ht_uctx_trampoline_ctx.uctx_this = uctx;
    ht_uctx_trampoline_ctx.uctx_after = uctx_after;
    ht_uctx_trampoline_ctx.start_func = start_func;
    ht_uctx_trampoline_ctx.start_arg = start_arg;
    if (sigmask != ((void *)0))
        sigprocmask(2, sigmask, &ss);
    swapcontext(&((&mctx_parent)->uc), &((&(uctx->uc_mctx))->uc));;
    if (sigmask != ((void *)0))
        sigprocmask(2, &ss, ((void *)0));
    uctx->uc_mctx_set = (!(0));
    return (!(0));
}

variable_types: struct ht_uctx_st { int uc_stack_own; char *uc_stack_ptr; unsigned long uc_stack_len; int uc_mctx_set; struct ht_mctx_st { struct ucontext_t { unsigned long uc_flags; struct ucontext_t *uc_link; struct stack_t { void *ss_sp; int ss_flags; unsigned long ss_size; } uc_stack; struct mcontext_t { long long gregs[23]; struct _libc_fpstate { unsigned short cwd; unsigned short swd; unsigned short ftw; unsigned short fop; unsigned long rip; unsigned long rdp; unsigned int mxcsr; unsigned int mxcr_mask; struct _libc_fpxreg { unsigned short significand[4]; unsigned short exponent; unsigned short __glibc_reserved1[3]; } _st[8]; struct _libc_xmmreg { unsigned int element[4]; } _xmm[16]; unsigned int __glibc_reserved1[24]; } *fpregs; unsigned long long __reserved1[8]; } uc_mcontext; struct __sigset_t { unsigned long __val[-1]; } uc_sigmask; struct _libc_fpstate __fpregs_mem; unsigned long long __ssp[4]; } uc; int restored; int error; } uc_mctx; } *

variable_types:
sigmask
struct __sigset_t *

user_defined_types: struct ucontext_t { unsigned long uc_flags; struct ucontext_t *uc_link; struct stack_t uc_stack; struct mcontext_t uc_mcontext; struct __sigset_t uc_sigmask; struct _libc_fpstate __fpregs_mem; unsigned long long __ssp[4]; }


decompiled_code:
__int64 __fastcall ht_uctx_switch(__int64 a1, __int64 a2)
{
unsigned int v2; // ebx

if ( a1 && a2 )
{
v2 = *(_DWORD *)(a2 + 24);
if ( v2 )
{
*(_DWORD *)(a1 + 24) = 1;
swapcontext((ucontext_t *)(a1 + 32), (const ucontext_t *)(a2 + 32));
v2 = 1;
}
else
{
*_errno_location() = 1;
}
}
else
{
*_errno_location() = 22;
v2 = 0;
}
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, __int64 a2)
{
unsigned int v2; // ebx

if ( a1 && a2 )
{
v2 = *(_DWORD *)(a2 + 24);
if ( v2 )
{
*(_DWORD *)(a1 + 24) = 1;
swapcontext((ucontext_t *)(a1 + 32), (const ucontext_t *)(a2 + 32));
v2 = 1;
}
else
{
*_errno_location() = 1;
}
}
else
{
*_errno_location() = 22;
v2 = 0;
}
return v2;
}

original_code:
int
ht_uctx_switch(
    ht_uctx_t uctx_from,
    ht_uctx_t uctx_to)
{
    if (uctx_from == ((void *)0) || uctx_to == ((void *)0))
        return ((*__errno_location ()) = (22), ((0)));
    if (!(uctx_to->uc_mctx_set))
        return ((*__errno_location ()) = (1), ((0)));
    uctx_from->uc_mctx_set = (!(0));
    swapcontext(&((&(uctx_from->uc_mctx))->uc), &((&(uctx_to->uc_mctx))->uc));;
    return (!(0));
}

canonical_original_code:
int ht_uctx_switch(struct ht_uctx_st *uctx_from, struct ht_uctx_st *uctx_to)
{
    if (uctx_from == ((void *)0) || uctx_to == ((void *)0))
        return ((*__errno_location ()) = (22), ((0)));
    if (!(uctx_to->uc_mctx_set))
        return ((*__errno_location ()) = (1), ((0)));
    uctx_from->uc_mctx_set = (!(0));
    swapcontext(&((&(uctx_from->uc_mctx))->uc), &((&(uctx_to->uc_mctx))->uc));;
    return (!(0));
}

user_defined_types: struct mcontext_t { long long gregs[23]; struct _libc_fpstate *fpregs; unsigned long long __reserved1[8]; }