decompiled_code:
__int64 __fastcall cam_mv(float a1, float a2, float a3)
{
float v3; // xmm3_4
float v4; // xmm0_4
__int64 result; // rax
double v6; // [rsp+8h] [rbp-40h]
double v7; // [rsp+18h] [rbp-30h]
double v8; // [rsp+20h] [rbp-28h]
double cosx; // [rsp+30h] [rbp-18h] BYREF
double sinx[2]; // [rsp+38h] [rbp-10h] BYREF

v8 = *(float *)&cam_ti;
sincos(*(float *)&cam_ti, sinx, &cosx);
v7 = cosx;
v6 = sinx[0];
sincos(v8 - 1.570796326795, sinx, &cosx);
v3 = v7 * a1 + cosx * a2;
v4 = v6 * a1 + a2 * sinx[0];
result = map_get(
(unsigned int)(int)(float)(v3 + *(float *)&cam_x),
(unsigned int)(int)(float)(v4 + *(float *)&cam_y),
(unsigned int)(int)(float)(a3 + *(float *)&cam_z));
if ( (_DWORD)result )
return 0xFFFFFFFFLL;
*(float *)&cam_x = v3 + *(float *)&cam_x;
*(float *)&cam_y = v4 + *(float *)&cam_y;
*(float *)&cam_z = a3 + *(float *)&cam_z;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(float a1, float a2, float a3)
{
float v3; // xmm3_4
float v4; // xmm0_4
__int64 result; // rax
double v6; // [rsp+8h] [rbp-40h]
double v7; // [rsp+18h] [rbp-30h]
double v8; // [rsp+20h] [rbp-28h]
double cosx; // [rsp+30h] [rbp-18h] BYREF
double sinx[2]; // [rsp+38h] [rbp-10h] BYREF

v8 = *(float *)&cam_ti;
sincos(*(float *)&cam_ti, sinx, &cosx);
v7 = cosx;
v6 = sinx[0];
sincos(v8 - 1.570796326795, sinx, &cosx);
v3 = v7 * a1 + cosx * a2;
v4 = v6 * a1 + a2 * sinx[0];
result = map_get(
(unsigned int)(int)(float)(v3 + *(float *)&cam_x),
(unsigned int)(int)(float)(v4 + *(float *)&cam_y),
(unsigned int)(int)(float)(a3 + *(float *)&cam_z));
if ( (_DWORD)result )
return 0xFFFFFFFFLL;
*(float *)&cam_x = v3 + *(float *)&cam_x;
*(float *)&cam_y = v4 + *(float *)&cam_y;
*(float *)&cam_z = a3 + *(float *)&cam_z;
return result;
}

original_code:
int cam_mv (float x, float y, float z) {
  int ret = -1;
  float
    dx = x * cos (cam_ti) + y * cos (cam_ti - 3.14159265359/2),
    dy = x * sin (cam_ti) + y * sin (cam_ti - 3.14159265359/2),
    dz = z;
  int i = cam_x + dx, j = cam_y + dy, k = cam_z + dz;
  if (!map_get (i, j, k)) {
    cam_x += dx; cam_y += dy; cam_z += dz;
    ret = 0;
  }
  return ret;
}

canonical_original_code:
int cam_mv(float x, float y, float z) {
  int ret = -1;
  float dx = x * cos (cam_ti) + y * cos (cam_ti - 3.14159265359/2); float dy = x * sin (cam_ti) + y * sin (cam_ti - 3.14159265359/2); float dz = z;
  int i = cam_x + dx; int j = cam_y + dy; int k = cam_z + dz;
  if (!map_get (i, j, k)) {
    cam_x += dx; cam_y += dy; cam_z += dz;
    ret = 0;
  }
  return ret;
}

variable_types: x float

variable_types: y float

variable_types: z float

variable_types: ret int

variable_types: dx float

variable_types: dy float

variable_types: dz float

variable_types: i int

variable_types: j int

variable_types: k int


repo: baezilisK/micecraft

decompiled_code:
__int64 cam_sync()
{
int v1[5]; // [rsp+4h] [rbp-14h] BYREF

getdx((__int64)v1);
glMatrixMode(5888LL);
glLoadIdentity();
return gluLookAt(
*(float *)&cam_x,
*(float *)&cam_y,
*(float *)&cam_z,
(float)(*(float *)v1 + *(float *)&cam_x),
(float)(*(float *)&v1[1] + *(float *)&cam_y),
(float)(*(float *)&v1[2] + *(float *)&cam_z),
0.0);
}

canonical_decompiled_code:
__int64 func3()
{
int v1[5]; // [rsp+4h] [rbp-14h] BYREF

func0((__int64)v1);
glMatrixMode(5888LL);
glLoadIdentity();
return gluLookAt(
*(float *)&cam_x,
*(float *)&cam_y,
*(float *)&cam_z,
(float)(*(float *)v1 + *(float *)&cam_x),
(float)(*(float *)&v1[1] + *(float *)&cam_y),
(float)(*(float *)&v1[2] + *(float *)&cam_z),
0.0);
}

original_code:
void cam_sync (void) {
  float dx[3];
  getdx (dx);
  glMatrixMode (0x1700);
  glLoadIdentity ();
  gluLookAt (
    cam_x, cam_y, cam_z,
    cam_x + dx[0], cam_y + dx[1], cam_z + dx[2],
    0, 0, 1
  );
}

canonical_original_code:
void cam_sync() {
  float dx[3];
  getdx (dx);
  glMatrixMode (0x1700);
  glLoadIdentity ();
  gluLookAt (
    cam_x, cam_y, cam_z,
    cam_x + dx[0], cam_y + dx[1], cam_z + dx[2],
    0, 0, 1
  );
}

variable_types:
dx
float [3]

return_type: void


decompiled_code:
void terrain_init()
{
;
}

canonical_decompiled_code:
void func0()
{
;
}

original_code:
void terrain_init (void) {
}

canonical_original_code:
void terrain_init() {
}


decompiled_code:
float __fastcall terrain_h(float a1)
{
return sin((float)(a1 / 3.0)) * 4.0;
}

canonical_decompiled_code:
float __fastcall func1(float a1)
{
return sin((float)(a1 / 3.0)) * 4.0;
}

original_code:
float terrain_h (float x, float y) {
  (void) y;
  return 4 * sin (x / 3);
}

canonical_original_code:
float terrain_h(float x, float y) {
  (void) y;
  return 4 * sin (x / 3);
}

return_type: float


decompiled_code:
void terrain_del()
{
;
}

canonical_decompiled_code:
void func2()
{
;
}

original_code:
void terrain_del (void) {
}

canonical_original_code:
void terrain_del() {
}


original_code:
void map_gen (void) {
  int i, j, k, l;
  terrain_init ();
  for (l = 0; l < (sizeof(chunks) / sizeof *(chunks)); ++l)
    for (i = 0; i < 8; ++i)
      for (j = 0; j < 8; ++j)
        for (k = 0; k < 128; ++k)
          chunks[l][i][j][k] = rng_f () < 0.05;
  terrain_del ();
}

canonical_original_code:
void map_gen() {
  int i; int j; int k; int l;
  terrain_init ();
  for (l = 0; l < (sizeof(chunks) / sizeof *(chunks)); ++l)
    for (i = 0; i < 8; ++i)
      for (j = 0; j < 8; ++j)
        for (k = 0; k < 128; ++k)
          chunks[l][i][j][k] = rng_f () < 0.05;
  terrain_del ();
}

variable_types: l int


decompiled_code:
__int64 __fastcall map_set(int a1, int a2, int a3, int a4)
{
__int64 result; // rax

result = a3;
chunks[128 * (a2 + 8LL * a1) + a3] = a4;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(int a1, int a2, int a3, int a4)
{
__int64 result; // rax

result = a3;
chunks[128 * (a2 + 8LL * a1) + a3] = a4;
return result;
}

original_code:
void map_set (int i, int j, int k, int val) {
  chunks[0][i][j][k] = val;
}

canonical_original_code:
void map_set(int i, int j, int k, int val) {
  chunks[0][i][j][k] = val;
}

variable_types: val int


decompiled_code:
__int64 __fastcall map_get(unsigned int a1, unsigned int a2, unsigned int a3)
{
__int64 result; // rax

if ( a3 > 8 || a2 > 8 || a1 > 0x20 )
result = 0LL;
else
result = (unsigned int)chunks[128 * ((int)a2 + 8LL * (int)a1) + (int)a3];
return result;
}

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

if ( a3 > 8 || a2 > 8 || a1 > 0x20 )
result = 0LL;
else
result = (unsigned int)chunks[128 * ((int)a2 + 8LL * (int)a1) + (int)a3];
return result;
}

original_code:
int map_get (int i, int j, int k) {
  if (i < 0 || j < 0 || k < 0) return 0;
  if (i > 32 || j > 8 || k > 8) return 0;
  return chunks[0][i][j][k];
}

canonical_original_code:
int map_get(int i, int j, int k) {
  if (i < 0 || j < 0 || k < 0) return 0;
  if (i > 32 || j > 8 || k > 8) return 0;
  return chunks[0][i][j][k];
}

return_type: int


original_code:
float map_height (float x, float y, float z) {
  float a = 1000;
  int i = x, j = y, k = z;
  ((x < a && y < a && z < a) ? (void) (0) : __assert_fail ("x < a && y < a && z < a", "src/map.c", 37, __extension__ __PRETTY_FUNCTION__));
  for (; k >= 0 && !map_get (i, j, k); --k);
  return z - (k + 1);
}

canonical_original_code:
float map_height(float x, float y, float z) {
  float a = 1000;
  int i = x; int j = y; int k = z;
  ((x < a && y < a && z < a) ? (void) (0) : __assert_fail ("x < a && y < a && z < a", "src/map.c", 37, __extension__ __PRETTY_FUNCTION__));
  for (; k >= 0 && !map_get (i, j, k); --k);
  return z - (k + 1);
}

variable_types: a float


decompiled_code:
__int64 map_display()
{
int v0; // ebp
const char *v1; // rbx
float v2; // xmm0_4
const char *v3; // rdi
__int64 result; // rax

v0 = 0;
v1 = (const char *)chunks;
do
{
glColor3f(0.0, 0.0, 1.0);
v2 = (float)v0;
v0 += 8;
ugl_rprism(v2, 0.0, 0.0, 8.0, 8.0, 128.0);
v3 = v1;
v1 += 0x8000;
result = chunk_display(v3, v2);
}
while ( v1 != "src/map.c" );
return result;
}

canonical_decompiled_code:
__int64 func4()
{
int v0; // ebp
const char *v1; // rbx
float v2; // xmm0_4
const char *v3; // rdi
__int64 result; // rax

v0 = 0;
v1 = (const char *)chunks;
do
{
glColor3f(0.0, 0.0, 1.0);
v2 = (float)v0;
v0 += 8;
ugl_rprism(v2, 0.0, 0.0, 8.0, 8.0, 128.0);
v3 = v1;
v1 += 0x8000;
result = chunk_display(v3, v2);
}
while ( v1 != "src/map.c" );
return result;
}

original_code:
void map_display (void) {
  int i;
  for (i = 0; i < (sizeof(chunks) / sizeof *(chunks)); ++i) {
    glColor3f (0, 0, 1);
    ugl_rprism (8*i, 0, 0, 8, 8, 128);
    chunk_display (chunks[i], i * 8);
  }
}

canonical_original_code:
void map_display() {
  int i;
  for (i = 0; i < (sizeof(chunks) / sizeof *(chunks)); ++i) {
    glColor3f (0, 0, 1);
    ugl_rprism (8*i, 0, 0, 8, 8, 128);
    chunk_display (chunks[i], i * 8);
  }
}


decompiled_code:
void map_del()
{
;
}

canonical_decompiled_code:
void func5()
{
;
}

original_code:
void map_del (void) {
}

canonical_original_code:
void map_del() {
}


xmalloc

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

result = malloc(a1);
if ( !result )
{
if ( a1 )
{
fwrite("out of memory\n", 1uLL, 0xEuLL, stderr);
exit(1);
}
}
return result;
}

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

result = malloc(a1);
if ( !result )
{
if ( a1 )
{
fwrite("out of memory\n", 1uLL, 0xEuLL, stderr);
exit(1);
}
}
return result;
}

original_code:
void *xmalloc (size_t n) {
  void *ret = malloc (n);
  if (!ret && n) {
    fprintf (stderr, "out of memory\n");
    exit (1);
  }
  return ret;
}

canonical_original_code:
void *xmalloc(unsigned long n) {
  void *ret = malloc (n);
  if (!ret && n) {
    fprintf (stderr, "out of memory\n");
    exit (1);
  }
  return ret;
}

variable_types:
n
unsigned long

variable_types:
ret
void *

return_type: void *


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

result = (unsigned __int8)kbd_map[a1];
kbd_toggle[result] ^= 1u;
kbd_state[result] = 1;
return result;
}

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

result = (unsigned __int8)kbd_map[a1];
kbd_toggle[result] ^= 1u;
kbd_state[result] = 1;
return result;
}

original_code:
void kbd_glutkeydown (unsigned char key, int x, int y) {
  (void) x; (void) y;
  kbd_state[kbd_map[key]] = 1;
  kbd_toggle[kbd_map[key]] ^= 1;
}

canonical_original_code:
void kbd_glutkeydown(unsigned char key, int x, int y) {
  (void) x; (void) y;
  kbd_state[kbd_map[key]] = 1;
  kbd_toggle[kbd_map[key]] ^= 1;
}

variable_types:
key
unsigned char

variable_types: x int

variable_types: y int


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

result = (unsigned __int8)kbd_map[a1];
kbd_state[result] = 0;
return result;
}

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

result = (unsigned __int8)kbd_map[a1];
kbd_state[result] = 0;
return result;
}

original_code:
void kbd_glutkeyup (unsigned char key, int x, int y) {
  (void) x; (void) y;
  kbd_state[kbd_map[key]] = 0;
}

canonical_original_code:
void kbd_glutkeyup(unsigned char key, int x, int y) {
  (void) x; (void) y;
  kbd_state[kbd_map[key]] = 0;
}


main

canonical_name: main

repo: baezilisK/paint

decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
const char *v3; // rdi

glutInit();
glutInitDisplayMode();
glutInitWindowSize();
v3 = *argv;
glutCreateWindow();
init(v3, 300LL);
glutDisplayFunc();
glutReshapeFunc();
glutMouseFunc();
glutKeyboardFunc();
glutMotionFunc();
glutMainLoop();
exit(1);
}

canonical_decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
const char *v3; // rdi

glutInit();
glutInitDisplayMode();
glutInitWindowSize();
v3 = *argv;
glutCreateWindow();
func12(v3, 300LL);
glutDisplayFunc();
glutReshapeFunc();
glutMouseFunc();
glutKeyboardFunc();
glutMotionFunc();
glutMainLoop();
exit(1);
}

original_code:
int main (int argc, char **argv) {
  glutInit (&argc, argv);
  glutInitDisplayMode (0x0000 | 0x0000);
  glutInitWindowSize (300, 300);
  glutCreateWindow (argv[0]);
  init ();
  glutDisplayFunc (display);
  glutReshapeFunc (reshape);
  glutMouseFunc (mouse);
  glutKeyboardFunc (keyboard);
  glutMotionFunc (trackmouse);
  glutMainLoop ();
  exit (1);
}

canonical_original_code:
int main(int argc, char **argv) {
  glutInit (&argc, argv);
  glutInitDisplayMode (0x0000 | 0x0000);
  glutInitWindowSize (300, 300);
  glutCreateWindow (argv[0]);
  init ();
  glutDisplayFunc (display);
  glutReshapeFunc (reshape);
  glutMouseFunc (mouse);
  glutKeyboardFunc (keyboard);
  glutMotionFunc (trackmouse);
  glutMainLoop ();
  exit (1);
}

variable_types: argc int

variable_types:
argv
char **


display

decompiled_code:
__int64 display()
{
if ( draw )
glBegin();
glColor3f();
glVertex2f();
glVertex2f();
glEnd();
printf("displayed %d %d\n", (unsigned int)mousex, (unsigned int)mousey);
return glFlush();
}

canonical_decompiled_code:
__int64 func7()
{
if ( draw )
glBegin();
glColor3f();
glVertex2f();
glVertex2f();
glEnd();
printf("displayed %d %d\n", (unsigned int)mousex, (unsigned int)mousey);
return glFlush();
}

original_code:
void display (void) {
  if (draw) glBegin (0x0003);
    glColor3f (r, g, b);
    glVertex2f (mousexx, mouseyy); glVertex2f (mousex, mousey);
  glEnd ();
  printf ("displayed %d %d\n", mousex, mousey);
  glFlush ();
}

canonical_original_code:
void display() {
  if (draw) glBegin (0x0003);
    glColor3f (r, g, b);
    glVertex2f (mousexx, mouseyy); glVertex2f (mousex, mousey);
  glEnd ();
  printf ("displayed %d %d\n", mousex, mousey);
  glFlush ();
}


reshape

decompiled_code:
__int64 reshape()
{
glViewport();
glLoadIdentity();
return glOrtho();
}

canonical_decompiled_code:
__int64 func8()
{
glViewport();
glLoadIdentity();
return glOrtho();
}

original_code:
void reshape (int w, int h) {
  glViewport (0, 0, w, h);
  glLoadIdentity ();
  glOrtho (0, w, 0, h, -1, 1);
}

canonical_original_code:
void reshape(int w, int h) {
  glViewport (0, 0, w, h);
  glLoadIdentity ();
  glOrtho (0, w, 0, h, -1, 1);
}

variable_types: w int

variable_types: h int


mouse

decompiled_code:
_BOOL8 __fastcall mouse(unsigned int a1, unsigned int a2, unsigned int a3, int a4)
{
_BOOL8 result; // rax
int v7; // [rsp+Ch] [rbp-2Ch]

glGetIntegerv();
printf("mouse %d %d %d %d\n", a1, a2, a3, (unsigned int)(v7 - a4));
result = a2 == 0;
draw = a2 == 0;
if ( !a2 )
{
mousex = a3;
mousexx = a3;
mousey = v7 - a4;
mouseyy = v7 - a4;
}
return result;
}

canonical_decompiled_code:
_BOOL8 __fastcall func9(unsigned int a1, unsigned int a2, unsigned int a3, int a4)
{
_BOOL8 result; // rax
int v7; // [rsp+Ch] [rbp-2Ch]

glGetIntegerv();
printf("mouse %d %d %d %d\n", a1, a2, a3, (unsigned int)(v7 - a4));
result = a2 == 0;
draw = a2 == 0;
if ( !a2 )
{
mousex = a3;
mousexx = a3;
mousey = v7 - a4;
mouseyy = v7 - a4;
}
return result;
}

original_code:
void mouse (int button, int state, int x, int y) {
  int vp[4]; glGetIntegerv (0x0BA2, vp); y = vp[3] - y;
  printf ("mouse %d %d %d %d\n", button, state, x, y);
  if (draw = state == 0x0000, draw) {
    mousexx = mousex = x;
    mouseyy = mousey = y;
  }
}

canonical_original_code:
void mouse(int button, int state, int x, int y) {
  int vp[4]; glGetIntegerv (0x0BA2, vp); y = vp[3] - y;
  printf ("mouse %d %d %d %d\n", button, state, x, y);
  if (draw = state == 0x0000, draw) {
    mousexx = mousex = x;
    mouseyy = mousey = y;
  }
}

variable_types: button int

variable_types: state int

variable_types:
vp
int [4]


trackmouse

decompiled_code:
__int64 __fastcall trackmouse(int a1, int a2)
{
int v2; // eax
int v4; // [rsp+Ch] [rbp-1Ch]

glGetIntegerv();
v2 = mousex;
mousex = a1;
mousexx = v2;
mouseyy = mousey;
mousey = v4 - a2;
return glutPostRedisplay();
}

canonical_decompiled_code:
__int64 __fastcall func10(int a1, int a2)
{
int v2; // eax
int v4; // [rsp+Ch] [rbp-1Ch]

glGetIntegerv();
v2 = mousex;
mousex = a1;
mousexx = v2;
mouseyy = mousey;
mousey = v4 - a2;
return glutPostRedisplay();
}

original_code:
void trackmouse (int x, int y) {
  int vp[4]; glGetIntegerv (0x0BA2, vp);
  mousexx = mousex, mouseyy = mousey;
  mousex = x; mousey = vp[3] -y;
  glutPostRedisplay ();
}

canonical_original_code:
void trackmouse(int x, int y) {
  int vp[4]; glGetIntegerv (0x0BA2, vp);
  mousexx = mousex, mouseyy = mousey;
  mousex = x; mousey = vp[3] -y;
  glutPostRedisplay ();
}


keyboard

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

if ( a1 == 27 )
exit(0);
if ( a1 == 36 )
{
glClear();
result = glutPostRedisplay();
LABEL_11:
if ( a1 == 40 )
{
b ^= 1u;
return result;
}
goto LABEL_8;
}
if ( a1 != 123 )
{
if ( a1 == 125 )
{
g ^= 1u;
return result;
}
goto LABEL_11;
}
r ^= 1u;
LABEL_8:
if ( a1 == 61 )
{
b = 0;
g = 0;
r = 0;
}
return result;
}

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

if ( a1 == 27 )
exit(0);
if ( a1 == 36 )
{
glClear();
result = glutPostRedisplay();
LABEL_11:
if ( a1 == 40 )
{
b ^= 1u;
return result;
}
goto LABEL_8;
}
if ( a1 != 123 )
{
if ( a1 == 125 )
{
g ^= 1u;
return result;
}
goto LABEL_11;
}
r ^= 1u;
LABEL_8:
if ( a1 == 61 )
{
b = 0;
g = 0;
r = 0;
}
return result;
}

original_code:
void keyboard (unsigned char key, int x, int y) {
  (void) x; (void) y;
  if (key == 0x1B) exit (0);
  if (key == '$') glClear (0x00004000), glutPostRedisplay ();
  if (key == '{') r ^= 1;
  if (key == '}') g ^= 1;
  if (key == '(') b ^= 1;
  if (key == '=') r = g = b = 0;
}

canonical_original_code:
void keyboard(unsigned char key, int x, int y) {
  (void) x; (void) y;
  if (key == 0x1B) exit (0);
  if (key == '$') glClear (0x00004000), glutPostRedisplay ();
  if (key == '{') r ^= 1;
  if (key == '}') g ^= 1;
  if (key == '(') b ^= 1;
  if (key == '=') r = g = b = 0;
}


init

decompiled_code:
__int64 init()
{
glClearColor();
return glClear();
}

canonical_decompiled_code:
__int64 func12()
{
glClearColor();
return glClear();
}

original_code:
void init (void) {
  glClearColor (0, 0, 0, 0);
  glClear (0x00004000);
}

canonical_original_code:
void init() {
  glClearColor (0, 0, 0, 0);
  glClear (0x00004000);
}


decompiled_code:
__int64 __fastcall find_max_func(_DWORD *a1, unsigned int *a2)
{
__int64 result; // rax

result = *a2;
if ( (int)result > *a1 )
*a1 = result;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func7(_DWORD *a1, unsigned int *a2)
{
__int64 result; // rax

result = *a2;
if ( (int)result > *a1 )
*a1 = result;
return result;
}

original_code:
static void find_max_func(void *max_val, void *data)
{
    if ( *((int*)data) > *((int*)max_val) )
    {
        *((int*)max_val) = *((int*)data);
    }
}

canonical_original_code:
static void find_max_func(void *max_val, void *data)
{
    if ( *((int *)data) > *((int *)max_val) )
    {
        *((int *)max_val) = *((int *)data);
    }
}

variable_types:
data
void *


decompiled_code:
int __fastcall print_data_func(_DWORD *a1, unsigned int *a2)
{
int result; // eax

result = printf("%d", *a2);
if ( (*a1)-- != 1 )
result = printf(", ");
return result;
}

canonical_decompiled_code:
int __fastcall func9(_DWORD *a1, unsigned int *a2)
{
int result; // eax

result = printf("%d", *a2);
if ( (*a1)-- != 1 )
result = printf(", ");
return result;
}

original_code:
static void print_data_func(void *remaining_size, void *data)
{
    printf("%d", *(int*)data);
    (*((int*)remaining_size))--;
    if (*((int*)remaining_size) != 0)
    {
        printf(", ");
    }
}

canonical_original_code:
static void print_data_func(void *remaining_size, void *data)
{
    printf("%d", *(int *)data);
    (*((int *)remaining_size))--;
    if (*((int *)remaining_size) != 0)
    {
        printf(", ");
    }
}


decompiled_code:
char *__fastcall get_cmd_args(char *dest, char *a2, char *a3)
{
char *result; // rax
__int64 v6; // rbx
int v7; // er13
__int64 v8; // rsi
int v9; // edx
int v10; // er12
int v11; // er12
const char *v12; // rsi
size_t v13; // rdx
char v14; // [rsp+1h] [rbp-69h]
char v15[104]; // [rsp+2h] [rbp-68h] BYREF

if ( !fgets(v15, 39, stdin) )
{
perror("fgets");
exit(1);
}
LOBYTE(result) = v15[0];
*(_QWORD *)dest = 0LL;
*((_DWORD *)dest + 2) = 0;
dest[12] = 0;
*(_QWORD *)a2 = 0LL;
*((_DWORD *)a2 + 2) = 0;
a2[12] = 0;
*(_QWORD *)a3 = 0LL;
*((_DWORD *)a3 + 2) = 0;
a3[12] = 0;
if ( (_BYTE)result == 10 )
{
v12 = v15;
v13 = 0LL;
return strncpy(dest, v12, v13);
}
v6 = 1LL;
v7 = 0;
v8 = 0LL;
do
{
while ( 1 )
{
v9 = v6 - 1;
v10 = v6;
if ( (_BYTE)result == 32 )
break;
++v6;
result = (char *)(unsigned __int8)*(&v14 + v6);
if ( (_BYTE)result == 10 )
goto LABEL_10;
}
if ( v7 )
{
if ( v7 == 1 )
strncpy(a2, &v15[v8], v9 - (int)v8);
}
else
{
strncpy(dest, &v15[v8], v9 - (int)v8);
}
++v6;
++v7;
v8 = v10;
result = (char *)(unsigned __int8)*(&v14 + v6);
}
while ( (_BYTE)result != 10 );
LABEL_10:
switch ( v7 )
{
case 0:
v11 = v10 - v8;
v12 = &v15[v8];
v13 = v11;
return strncpy(dest, v12, v13);
case 1:
return strncpy(a2, &v15[v8], v10 - (int)v8);
case 2:
result = strncpy(a3, &v15[v8], v10 - (int)v8);
break;
}
return result;
}

canonical_decompiled_code:
char *__fastcall func10(char *dest, char *a2, char *a3)
{
char *result; // rax
__int64 v6; // rbx
int v7; // er13
__int64 v8; // rsi
int v9; // edx
int v10; // er12
int v11; // er12
const char *v12; // rsi
size_t v13; // rdx
char v14; // [rsp+1h] [rbp-69h]
char v15[104]; // [rsp+2h] [rbp-68h] BYREF

if ( !fgets(v15, 39, stdin) )
{
perror("fgets");
exit(1);
}
LOBYTE(result) = v15[0];
*(_QWORD *)dest = 0LL;
*((_DWORD *)dest + 2) = 0;
dest[12] = 0;
*(_QWORD *)a2 = 0LL;
*((_DWORD *)a2 + 2) = 0;
a2[12] = 0;
*(_QWORD *)a3 = 0LL;
*((_DWORD *)a3 + 2) = 0;
a3[12] = 0;
if ( (_BYTE)result == 10 )
{
v12 = v15;
v13 = 0LL;
return strncpy(dest, v12, v13);
}
v6 = 1LL;
v7 = 0;
v8 = 0LL;
do
{
while ( 1 )
{
v9 = v6 - 1;
v10 = v6;
if ( (_BYTE)result == 32 )
break;
++v6;
result = (char *)(unsigned __int8)*(&v14 + v6);
if ( (_BYTE)result == 10 )
goto LABEL_10;
}
if ( v7 )
{
if ( v7 == 1 )
strncpy(a2, &v15[v8], v9 - (int)v8);
}
else
{
strncpy(dest, &v15[v8], v9 - (int)v8);
}
++v6;
++v7;
v8 = v10;
result = (char *)(unsigned __int8)*(&v14 + v6);
}
while ( (_BYTE)result != 10 );
LABEL_10:
switch ( v7 )
{
case 0:
v11 = v10 - v8;
v12 = &v15[v8];
v13 = v11;
return strncpy(dest, v12, v13);
case 1:
return strncpy(a2, &v15[v8], v10 - (int)v8);
case 2:
result = strncpy(a3, &v15[v8], v10 - (int)v8);
break;
}
return result;
}

original_code:
static void get_cmd_args(char cmd[], char arg1[], char arg2[])
{
    char buf[(13 + 13 + 13)];
    int start_idx, end_idx, word_cnt;
    if (((void *)0) == fgets(buf, (13 + 13 + 13), stdin))
    {
        perror("fgets");
        exit(1);
    }
    memset(cmd, '\0', 13);
    memset(arg1, '\0', 13);
    memset(arg2, '\0', 13);
    start_idx = 0;
    end_idx = 0;
    word_cnt = 0;
    while (buf[end_idx] != '\n')
    {
        if (buf[end_idx] == ' ')
        {
            if (word_cnt == 0)
            {
                strncpy(cmd, &buf[start_idx], end_idx - start_idx);
            }
            else if (word_cnt == 1)
            {
                strncpy(arg1, &buf[start_idx], end_idx - start_idx);
            }
            word_cnt++;
            start_idx = end_idx + 1;
        }
        end_idx++;
    }
    if (word_cnt == 0)
    {
        strncpy(cmd, &buf[start_idx], end_idx - start_idx);
    }
    else if (word_cnt == 1)
    {
        strncpy(arg1, &buf[start_idx], end_idx - start_idx);
    }
    else if (word_cnt == 2)
    {
        strncpy(arg2, &buf[start_idx], end_idx - start_idx);
    }
}

canonical_original_code:
static void get_cmd_args(char cmd[], char arg1[], char arg2[])
{
    char buf[-1];
    int start_idx; int end_idx; int word_cnt;
    if (((void *)0) == fgets(buf, (13 + 13 + 13), stdin))
    {
        perror("fgets");
        exit(1);
    }
    memset(cmd, '\0', 13);
    memset(arg1, '\0', 13);
    memset(arg2, '\0', 13);
    start_idx = 0;
    end_idx = 0;
    word_cnt = 0;
    while (buf[end_idx] != '\n')
    {
        if (buf[end_idx] == ' ')
        {
            if (word_cnt == 0)
            {
                strncpy(cmd, &buf[start_idx], end_idx - start_idx);
            }
            else if (word_cnt == 1)
            {
                strncpy(arg1, &buf[start_idx], end_idx - start_idx);
            }
            word_cnt++;
            start_idx = end_idx + 1;
        }
        end_idx++;
    }
    if (word_cnt == 0)
    {
        strncpy(cmd, &buf[start_idx], end_idx - start_idx);
    }
    else if (word_cnt == 1)
    {
        strncpy(arg1, &buf[start_idx], end_idx - start_idx);
    }
    else if (word_cnt == 2)
    {
        strncpy(arg2, &buf[start_idx], end_idx - start_idx);
    }
}

variable_types:
cmd
char []

variable_types:
buf
char [-1]


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

result = malloc(0x10uLL);
if ( !result )
{
perror("dlist_create malloc() failed");
exit(1);
}
*result = 0LL;
result[1] = 0LL;
return result;
}

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

result = malloc(0x10uLL);
if ( !result )
{
perror("dlist_create malloc() failed");
exit(1);
}
*result = 0LL;
result[1] = 0LL;
return result;
}

original_code:
DList *dlist_create(void)
{
    DList *thiz = (DList *)malloc(sizeof(DList));
    if (thiz == ((void *)0))
    {
        perror("dlist_create malloc() failed");
        exit(1);
    }
    thiz->head = ((void *)0);
    thiz->size = 0;
    return thiz;
}

canonical_original_code:
struct _DList *dlist_create()
{
    struct _DList *thiz = (DList *)malloc(sizeof(DList));
    if (thiz == ((void *)0))
    {
        perror("dlist_create malloc() failed");
        exit(1);
    }
    thiz->head = ((void *)0);
    thiz->size = 0;
    return thiz;
}

variable_types: struct _DList { struct _DListNode { void *pdata; struct _DListNode *prev; struct _DListNode *next; } *head; unsigned long size; } *

user_defined_types: struct _DList { struct _DListNode *head; unsigned long size; }


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

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

original_code:
size_t dlist_size(DList *thiz)
{
    return thiz->size;
}

canonical_original_code:
unsigned long dlist_size(struct _DList *thiz)
{
    return thiz->size;
}

return_type: unsigned long

user_defined_types: struct _DListNode { void *pdata; struct _DListNode *prev; struct _DListNode *next; }


decompiled_code:
__int64 __fastcall dlist_foreach(_QWORD *a1, void (__fastcall *a2)(__int64, _QWORD), __int64 a3)
{
_QWORD *v3; // rbx
unsigned int v5; // ebp
__int64 result; // rax

v3 = (_QWORD *)*a1;
if ( a1[1] )
{
v5 = 0;
do
{
a2(a3, *v3);
v3 = (_QWORD *)v3[2];
result = ++v5;
}
while ( (unsigned __int64)v5 < a1[1] );
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func21(_QWORD *a1, void (__fastcall *a2)(__int64, _QWORD), __int64 a3)
{
_QWORD *v3; // rbx
unsigned int v5; // ebp
__int64 result; // rax

v3 = (_QWORD *)*a1;
if ( a1[1] )
{
v5 = 0;
do
{
a2(a3, *v3);
v3 = (_QWORD *)v3[2];
result = ++v5;
}
while ( (unsigned __int64)v5 < a1[1] );
}
return result;
}

original_code:
void dlist_foreach(DList *thiz, DListVisitFunc data_func, void *ctx)
{
    struct _DListNode *iter;
    unsigned int idx;
    iter = thiz->head;
    idx = 0;
    while (idx < thiz->size)
    {
        data_func(ctx, iter->pdata);
        iter = iter->next;
        idx++;
    }
}

canonical_original_code:
void dlist_foreach(struct _DList *thiz, void (*data_func)(void *ctx, void *data), void *ctx)
{
    struct _DListNode *iter;
    unsigned int idx;
    iter = thiz->head;
    idx = 0;
    while (idx < thiz->size)
    {
        data_func(ctx, iter->pdata);
        iter = iter->next;
        idx++;
    }
}

variable_types:
ctx
void *

variable_types: struct _DListNode { void *pdata; struct _DListNode *prev; struct _DListNode *next; } *

variable_types:
idx
unsigned int


original_code:
void dlist_insert(DList *thiz, size_t idx, void *pdata)
{
    size_t i;
    struct _DListNode *new_node_p = ((void *)0);
    struct _DListNode *node_of_idx_p = ((void *)0);
    struct _DListNode *prev_node_of_idx_p = ((void *)0);
    if (idx > thiz->size)
    {
        printf("idx %zu is out of range[0..%zu]\n", idx, thiz->size);
        return;
    }
    new_node_p = (struct _DListNode *)malloc(sizeof(struct _DListNode));
    if (new_node_p == ((void *)0))
    {
        perror("new_node_p malloc");
        exit(1);
    }
    new_node_p->pdata = pdata;
    new_node_p->next = ((void *)0);
    new_node_p->prev = ((void *)0);
    if (thiz->size == 0)
    {
        node_of_idx_p = prev_node_of_idx_p = new_node_p;
    }
    else
    {
        node_of_idx_p = thiz->head;
        for (i = 0; i < idx; i++)
            node_of_idx_p = node_of_idx_p->next;
        prev_node_of_idx_p = node_of_idx_p->prev;
    }
    new_node_p->next = node_of_idx_p;
    new_node_p->prev = prev_node_of_idx_p;
    node_of_idx_p->prev = new_node_p;
    prev_node_of_idx_p->next = new_node_p;
    if (idx == 0)
    {
        thiz->head = new_node_p;
    }
    thiz->size++;
}

canonical_original_code:
void dlist_insert(struct _DList *thiz, unsigned long idx, void *pdata)
{
    unsigned long i;
    struct _DListNode *new_node_p = ((void *)0);
    struct _DListNode *node_of_idx_p = ((void *)0);
    struct _DListNode *prev_node_of_idx_p = ((void *)0);
    if (idx > thiz->size)
    {
        printf("idx %zu is out of range[0..%zu]\n", idx, thiz->size);
        return;
    }
    new_node_p = (struct _DListNode *)malloc(sizeof(struct _DListNode));
    if (new_node_p == ((void *)0))
    {
        perror("new_node_p malloc");
        exit(1);
    }
    new_node_p->pdata = pdata;
    new_node_p->next = ((void *)0);
    new_node_p->prev = ((void *)0);
    if (thiz->size == 0)
    {
        node_of_idx_p = prev_node_of_idx_p = new_node_p;
    }
    else
    {
        node_of_idx_p = thiz->head;
        for (i = 0; i < idx; i++)
            node_of_idx_p = node_of_idx_p->next;
        prev_node_of_idx_p = node_of_idx_p->prev;
    }
    new_node_p->next = node_of_idx_p;
    new_node_p->prev = prev_node_of_idx_p;
    node_of_idx_p->prev = new_node_p;
    prev_node_of_idx_p->next = new_node_p;
    if (idx == 0)
    {
        thiz->head = new_node_p;
    }
    thiz->size++;
}

variable_types:
idx
unsigned long

variable_types:
pdata
void *

variable_types:
i
unsigned long


original_code:
void dlist_delete(DList *thiz, size_t idx)
{
    size_t i;
    struct _DListNode *node_of_idx_p = ((void *)0);
    struct _DListNode *next_node_of_idx_p = ((void *)0);
    struct _DListNode *prev_node_of_idx_p = ((void *)0);
    if (thiz->size == 0)
    {
        printf("dlist is empty.\n");
        return;
    }
    if (idx >= thiz->size)
    {
        printf("idx %zu is out of range[0..%zu]\n", idx, (thiz->size - 1));
        return;
    }
    node_of_idx_p = thiz->head;
    for (i = 0; i < idx; i++)
    {
        node_of_idx_p = node_of_idx_p->next;
    }
    next_node_of_idx_p = node_of_idx_p->next;
    prev_node_of_idx_p = node_of_idx_p->prev;
    if (idx == 0)
    {
        thiz->head = next_node_of_idx_p;
    }
    next_node_of_idx_p->prev = prev_node_of_idx_p;
    prev_node_of_idx_p->next = next_node_of_idx_p;
    thiz->size--;
    if (thiz->size == 0)
    {
        thiz->head = ((void *)0);
    }
    free(node_of_idx_p->pdata);
    free(node_of_idx_p);
}

canonical_original_code:
void dlist_delete(struct _DList *thiz, unsigned long idx)
{
    unsigned long i;
    struct _DListNode *node_of_idx_p = ((void *)0);
    struct _DListNode *next_node_of_idx_p = ((void *)0);
    struct _DListNode *prev_node_of_idx_p = ((void *)0);
    if (thiz->size == 0)
    {
        printf("dlist is empty.\n");
        return;
    }
    if (idx >= thiz->size)
    {
        printf("idx %zu is out of range[0..%zu]\n", idx, (thiz->size - 1));
        return;
    }
    node_of_idx_p = thiz->head;
    for (i = 0; i < idx; i++)
    {
        node_of_idx_p = node_of_idx_p->next;
    }
    next_node_of_idx_p = node_of_idx_p->next;
    prev_node_of_idx_p = node_of_idx_p->prev;
    if (idx == 0)
    {
        thiz->head = next_node_of_idx_p;
    }
    next_node_of_idx_p->prev = prev_node_of_idx_p;
    prev_node_of_idx_p->next = next_node_of_idx_p;
    thiz->size--;
    if (thiz->size == 0)
    {
        thiz->head = ((void *)0);
    }
    free(node_of_idx_p->pdata);
    free(node_of_idx_p);
}


decompiled_code:
void __fastcall dlist_destroy(void *ptr)
{
while ( *((_QWORD *)ptr + 1) )
dlist_delete((__int64 *)ptr, 0LL);
free(ptr);
}

canonical_decompiled_code:
void __fastcall func24(void *ptr)
{
while ( *((_QWORD *)ptr + 1) )
func23((__int64 *)ptr, 0LL);
free(ptr);
}

original_code:
void dlist_destroy(DList *thiz)
{
    while (thiz->size != 0)
    {
        dlist_delete(thiz, 0);
    }
    free(thiz);
}

canonical_original_code:
void dlist_destroy(struct _DList *thiz)
{
    while (thiz->size != 0)
    {
        dlist_delete(thiz, 0);
    }
    free(thiz);
}


GamaSort

repo: baifanmvp/sort

original_code:
static void GamaSort(KEY_T array[], int lo, int up, int bit)
{
    register KEY_T temp;
    register long b, u, l;
    if (up - lo > 15) {
 b = (1 << bit);
 u = up; l = lo;
 while (((b & array[u]) == b) && (u > lo))
     u--;
 if (!((u == lo) && ((b & array[u]) == b))) {
     while (((b & array[l]) == 0) && (l < up))
  l++;
 }
 if ((u == lo && (b & array[u]) == b) ||
     (l == up && (b & array[l]) == 0)) {
     u = up + 1;
 } else {
     while (l < u) {
  if (((b & array[l]) == b) && ((b & array[u]) == 0)) {
      temp = (array[u]); (array[u]) = (array[l]); (array[l]) = temp;
      while (((b & array[u]) == b) && (u > lo))
   u--;
  }
  l++;
     }
 }
 if (l >= u)
     u++;
 if (bit > 0) {
     if (u - 1 > lo)
  GamaSort(array, lo, u-1, bit-1);
     if (up > u)
  GamaSort(array, u, up, bit-1);
 }
    }
}

canonical_original_code:
static void GamaSort(long array[], int lo, int up, int bit)
{
    register long temp;
    register long b; register long u; register long l;
    if (up - lo > 15) {
 b = (1 << bit);
 u = up; l = lo;
 while (((b & array[u]) == b) && (u > lo))
     u--;
 if (!((u == lo) && ((b & array[u]) == b))) {
     while (((b & array[l]) == 0) && (l < up))
  l++;
 }
 if ((u == lo && (b & array[u]) == b) ||
     (l == up && (b & array[l]) == 0)) {
     u = up + 1;
 } else {
     while (l < u) {
  if (((b & array[l]) == b) && ((b & array[u]) == 0)) {
      temp = (array[u]); (array[u]) = (array[l]); (array[l]) = temp;
      while (((b & array[u]) == b) && (u > lo))
   u--;
  }
  l++;
     }
 }
 if (l >= u)
     u++;
 if (bit > 0) {
     if (u - 1 > lo)
  GamaSort(array, lo, u-1, bit-1);
     if (up > u)
  GamaSort(array, u, up, bit-1);
 }
    }
}

variable_types:
array
long []

variable_types: lo int

variable_types: up int

variable_types: bit int

variable_types: temp long

variable_types: b long

variable_types: u long

variable_types: l long


lg

decompiled_code:
__int64 __fastcall lg(int a1)
{
return (unsigned int)(int)(log10((double)a1) / 0.3010299956639812);
}

canonical_decompiled_code:
__int64 __fastcall func1(int a1)
{
return (unsigned int)(int)(log10((double)a1) / 0.3010299956639812);
}

original_code:
static int lg (int x)
{
    return (int) (log10(x) / log10(2));
}

canonical_original_code:
static int lg(int x)
{
    return (int) (log10(x) / log10(2));
}

variable_types: x int


gamasort

original_code:
void gamasort(KEY_T array[], int lo, int up)
{
    KEY_T ubits, i, temp, max = (-0x7fffffff - 1), maxidx;
    for (i = 0; i <= up; i++) {
 if (array[i] >= max) {
     max = array[i];
     maxidx = i;
 }
    }
    temp = (array[up]); (array[up]) = (array[maxidx]); (array[maxidx]) = temp;
    ubits = lg(array[maxidx]);
    GamaSort(array, lo, up, ubits);
    insort(array, up);
}

canonical_original_code:
void gamasort(long array[], int lo, int up)
{
    long ubits; long i; long temp; long max = (-0x7fffffff - 1); long maxidx;
    for (i = 0; i <= up; i++) {
 if (array[i] >= max) {
     max = array[i];
     maxidx = i;
 }
    }
    temp = (array[up]); (array[up]) = (array[maxidx]); (array[maxidx]) = temp;
    ubits = lg(array[maxidx]);
    GamaSort(array, lo, up, ubits);
    insort(array, up);
}

variable_types: ubits long

variable_types: i long

variable_types: max long

variable_types: maxidx long


heapsort

original_code:
void heapsort (KEY_T array[], int len)
{
    register int i;
    register KEY_T temp, *sa = array - 1;
    for (i = len / 2; i >= 1; i--)
 siftdown (sa, i, len);
    for (i = len; i >= 2; i--) {
 temp = (sa[1]); (sa[1]) = (sa[i]); (sa[i]) = temp;
 siftdown (sa, 1, i - 1);
    }
}

canonical_original_code:
void heapsort(long array[], int len)
{
    register int i;
    register long temp; register long *sa = array - 1;
    for (i = len / 2; i >= 1; i--)
 siftdown (sa, i, len);
    for (i = len; i >= 2; i--) {
 temp = (sa[1]); (sa[1]) = (sa[i]); (sa[i]) = temp;
 siftdown (sa, 1, i - 1);
    }
}

variable_types: len int

variable_types: i int

variable_types:
sa
long *


increment

decompiled_code:
void __fastcall increment(__int64 a1)
{
++*(_DWORD *)(a1 + 64);
}

canonical_decompiled_code:
void __fastcall func0(__int64 a1)
{
++*(_DWORD *)(a1 + 64);
}

original_code:
static void
increment(test_t *test) {
    test->counter++;
}

canonical_original_code:
static void increment(struct test *test) {
    test->counter++;
}

variable_types: struct test { struct e3_timer { struct e3_timer *next; unsigned long ticks; void (*function)(void *cookie); void *cookie; } timer_1; struct e3_timer timer_2; unsigned int counter; } *

user_defined_types: struct test { struct e3_timer timer_1; struct e3_timer timer_2; unsigned int counter; }


triple

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

result = (unsigned int)(3 * *(_DWORD *)(a1 + 64));
*(_DWORD *)(a1 + 64) = result;
return result;
}

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

result = (unsigned int)(3 * *(_DWORD *)(a1 + 64));
*(_DWORD *)(a1 + 64) = result;
return result;
}

original_code:
static void
triple(test_t *test) {
    test->counter *= 3;
}

canonical_original_code:
static void triple(struct test *test) {
    test->counter *= 3;
}

user_defined_types: struct e3_timer { struct e3_timer *next; unsigned long ticks; void (*function)(void *cookie); void *cookie; }


reschedule

decompiled_code:
__int64 __fastcall reschedule(__int64 a1)
{
++*(_DWORD *)(a1 + 64);
return e3_timer_create(a1, 0LL, reschedule, a1);
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1)
{
++*(_DWORD *)(a1 + 64);
return e3_timer_create(a1, 0LL, reschedule, a1);
}

original_code:
static void
reschedule(test_t *test) {
    test->counter++;
    e3_timer_create(&test->timer_1, 0,
        (e3_timer_function_t) reschedule, test);
}

canonical_original_code:
static void reschedule(struct test *test) {
    test->counter++;
    e3_timer_create(&test->timer_1, 0,
        (void (*)(void *cookie)) reschedule, test);
}


original_code:
void
e3_timer_test(jasmine_t *jasmine) {
    test_t test;
    for ((jasmine)->state = 0, (jasmine)->current = 0, (jasmine)->last = 0, puts("the system timer"); (3 == (jasmine)->state) ? (puts(""), 0) : 1; ) {
        for (; 0 == (jasmine)->state; (jasmine)->state = 1) {
            test.counter = 0;
        }
        for (; 2 == (jasmine)->state; (jasmine)->state = ((jasmine)->current == (jasmine)->last) ? 3 : 0) {
        }
        for ((jasmine)->group = 2, (jasmine)->last = (unsigned short) ((jasmine)->last < 64 ? 64 : (jasmine)->last); 1 == (jasmine)->state && (jasmine)->current < 64 && (64 == ((jasmine)->current = 64)); (jasmine)->state = 2, ((jasmine)->group == 2 ? ((jasmine)->ignored++, puts(" ! " "can tick without any timers created"), 2) : ((jasmine)->group == 1 ? ((jasmine)->passed++, puts(" ✓ " "can tick without any timers created"), 1) : ((jasmine)->failed++, printf(" ✗ " "can tick without any timers created" ": expected %s\r\n", (jasmine)->reason), 0)))) {
            if (!(!e3_timer_tick())) { (jasmine)->expects++; (jasmine)->group = 0; (jasmine)->reason = "!e3_timer_tick()"; continue; } else { (jasmine)->group = 1; (jasmine)->expects++; };
            if (!(test.counter == 0)) { (jasmine)->expects++; (jasmine)->group = 0; (jasmine)->reason = "test.counter == 0"; continue; } else { (jasmine)->group = 1; (jasmine)->expects++; };
        }
        for ((jasmine)->group = 2, (jasmine)->last = (unsigned short) ((jasmine)->last < 69 ? 69 : (jasmine)->last); 1 == (jasmine)->state && (jasmine)->current < 69 && (69 == ((jasmine)->current = 69)); (jasmine)->state = 2, ((jasmine)->group == 2 ? ((jasmine)->ignored++, puts(" ! " "does not require an interrupt for a zero tick"), 2) : ((jasmine)->group == 1 ? ((jasmine)->passed++, puts(" ✓ " "does not require an interrupt for a zero tick"), 1) : ((jasmine)->failed++, printf(" ✗ " "does not require an interrupt for a zero tick" ": expected %s\r\n", (jasmine)->reason), 0)))) {
            e3_timer_create(&test.timer_1, 0,
                (e3_timer_function_t) increment, &test);
            if (!(test.counter == 0)) { (jasmine)->expects++; (jasmine)->group = 0; (jasmine)->reason = "test.counter == 0"; continue; } else { (jasmine)->group = 1; (jasmine)->expects++; };
            if (!(!e3_timer_tick())) { (jasmine)->expects++; (jasmine)->group = 0; (jasmine)->reason = "!e3_timer_tick()"; continue; } else { (jasmine)->group = 1; (jasmine)->expects++; };
            if (!(test.counter == 1)) { (jasmine)->expects++; (jasmine)->group = 0; (jasmine)->reason = "test.counter == 1"; continue; } else { (jasmine)->group = 1; (jasmine)->expects++; };
        }
        for ((jasmine)->group = 2, (jasmine)->last = (unsigned short) ((jasmine)->last < 78 ? 78 : (jasmine)->last); 1 == (jasmine)->state && (jasmine)->current < 78 && (78 == ((jasmine)->current = 78)); (jasmine)->state = 2, ((jasmine)->group == 2 ? ((jasmine)->ignored++, puts(" ! " "can have multiple timers with the same ticks"), 2) : ((jasmine)->group == 1 ? ((jasmine)->passed++, puts(" ✓ " "can have multiple timers with the same ticks"), 1) : ((jasmine)->failed++, printf(" ✗ " "can have multiple timers with the same ticks" ": expected %s\r\n", (jasmine)->reason), 0)))) {
            e3_timer_create(&test.timer_1, 0,
                (e3_timer_function_t) increment, &test);
            e3_timer_create(&test.timer_2, 0,
                (e3_timer_function_t) increment, &test);
            if (!(test.counter == 0)) { (jasmine)->expects++; (jasmine)->group = 0; (jasmine)->reason = "test.counter == 0"; continue; } else { (jasmine)->group = 1; (jasmine)->expects++; };
            if (!(!e3_timer_tick())) { (jasmine)->expects++; (jasmine)->group = 0; (jasmine)->reason = "!e3_timer_tick()"; continue; } else { (jasmine)->group = 1; (jasmine)->expects++; };
            if (!(test.counter == 2)) { (jasmine)->expects++; (jasmine)->group = 0; (jasmine)->reason = "test.counter == 2"; continue; } else { (jasmine)->group = 1; (jasmine)->expects++; };
        }
        for ((jasmine)->group = 2, (jasmine)->last = (unsigned short) ((jasmine)->last < 90 ? 90 : (jasmine)->last); 1 == (jasmine)->state && (jasmine)->current < 90 && (90 == ((jasmine)->current = 90)); (jasmine)->state = 2, ((jasmine)->group == 2 ? ((jasmine)->ignored++, puts(" ! " "will ignore invalid timer functions"), 2) : ((jasmine)->group == 1 ? ((jasmine)->passed++, puts(" ✓ " "will ignore invalid timer functions"), 1) : ((jasmine)->failed++, printf(" ✗ " "will ignore invalid timer functions" ": expected %s\r\n", (jasmine)->reason), 0)))) {
            e3_timer_create(&test.timer_1, 0, 0, 0);
            if (!(test.counter == 0)) { (jasmine)->expects++; (jasmine)->group = 0; (jasmine)->reason = "test.counter == 0"; continue; } else { (jasmine)->group = 1; (jasmine)->expects++; };
            if (!(!e3_timer_tick())) { (jasmine)->expects++; (jasmine)->group = 0; (jasmine)->reason = "!e3_timer_tick()"; continue; } else { (jasmine)->group = 1; (jasmine)->expects++; };
            if (!(test.counter == 0)) { (jasmine)->expects++; (jasmine)->group = 0; (jasmine)->reason = "test.counter == 0"; continue; } else { (jasmine)->group = 1; (jasmine)->expects++; };
        }
        for ((jasmine)->group = 2, (jasmine)->last = (unsigned short) ((jasmine)->last < 97 ? 97 : (jasmine)->last); 1 == (jasmine)->state && (jasmine)->current < 97 && (97 == ((jasmine)->current = 97)); (jasmine)->state = 2, ((jasmine)->group == 2 ? ((jasmine)->ignored++, puts(" ! " "can delete a timer that has been created"), 2) : ((jasmine)->group == 1 ? ((jasmine)->passed++, puts(" ✓ " "can delete a timer that has been created"), 1) : ((jasmine)->failed++, printf(" ✗ " "can delete a timer that has been created" ": expected %s\r\n", (jasmine)->reason), 0)))) {
            e3_timer_create(&test.timer_1, 0,
                (e3_timer_function_t) triple, &test);
            e3_timer_create(&test.timer_2, 0,
                (e3_timer_function_t) increment, &test);
            if (!(test.counter == 0)) { (jasmine)->expects++; (jasmine)->group = 0; (jasmine)->reason = "test.counter == 0"; continue; } else { (jasmine)->group = 1; (jasmine)->expects++; };
            e3_timer_delete(&test.timer_1);
            if (!(!e3_timer_tick())) { (jasmine)->expects++; (jasmine)->group = 0; (jasmine)->reason = "!e3_timer_tick()"; continue; } else { (jasmine)->group = 1; (jasmine)->expects++; };
            if (!(test.counter == 1)) { (jasmine)->expects++; (jasmine)->group = 0; (jasmine)->reason = "test.counter == 1"; continue; } else { (jasmine)->group = 1; (jasmine)->expects++; };
        }
        for ((jasmine)->group = 2, (jasmine)->last = (unsigned short) ((jasmine)->last < 110 ? 110 : (jasmine)->last); 1 == (jasmine)->state && (jasmine)->current < 110 && (110 == ((jasmine)->current = 110)); (jasmine)->state = 2, ((jasmine)->group == 2 ? ((jasmine)->ignored++, puts(" ! " "can delete a timer that has not been created"), 2) : ((jasmine)->group == 1 ? ((jasmine)->passed++, puts(" ✓ " "can delete a timer that has not been created"), 1) : ((jasmine)->failed++, printf(" ✗ " "can delete a timer that has not been created" ": expected %s\r\n", (jasmine)->reason), 0)))) {
            e3_timer_delete(&test.timer_1);
            if (!(!e3_timer_tick())) { (jasmine)->expects++; (jasmine)->group = 0; (jasmine)->reason = "!e3_timer_tick()"; continue; } else { (jasmine)->group = 1; (jasmine)->expects++; };
            if (!(test.counter == 0)) { (jasmine)->expects++; (jasmine)->group = 0; (jasmine)->reason = "test.counter == 0"; continue; } else { (jasmine)->group = 1; (jasmine)->expects++; };
        }
        for ((jasmine)->group = 2, (jasmine)->last = (unsigned short) ((jasmine)->last < 116 ? 116 : (jasmine)->last); 1 == (jasmine)->state && (jasmine)->current < 116 && (116 == ((jasmine)->current = 116)); (jasmine)->state = 2, ((jasmine)->group == 2 ? ((jasmine)->ignored++, puts(" ! " "can tick faster than the interrupt"), 2) : ((jasmine)->group == 1 ? ((jasmine)->passed++, puts(" ✓ " "can tick faster than the interrupt"), 1) : ((jasmine)->failed++, printf(" ✗ " "can tick faster than the interrupt" ": expected %s\r\n", (jasmine)->reason), 0)))) {
            e3_timer_create(&test.timer_1, 1,
                (e3_timer_function_t) increment, &test);
            if (!(test.counter == 0)) { (jasmine)->expects++; (jasmine)->group = 0; (jasmine)->reason = "test.counter == 0"; continue; } else { (jasmine)->group = 1; (jasmine)->expects++; };
            if (!(e3_timer_tick())) { (jasmine)->expects++; (jasmine)->group = 0; (jasmine)->reason = "e3_timer_tick()"; continue; } else { (jasmine)->group = 1; (jasmine)->expects++; };
            if (!(test.counter == 0)) { (jasmine)->expects++; (jasmine)->group = 0; (jasmine)->reason = "test.counter == 0"; continue; } else { (jasmine)->group = 1; (jasmine)->expects++; };
            if (!(e3_timer_tick())) { (jasmine)->expects++; (jasmine)->group = 0; (jasmine)->reason = "e3_timer_tick()"; continue; } else { (jasmine)->group = 1; (jasmine)->expects++; };
            if (!(test.counter == 0)) { (jasmine)->expects++; (jasmine)->group = 0; (jasmine)->reason = "test.counter == 0"; continue; } else { (jasmine)->group = 1; (jasmine)->expects++; };
            e3_timer_interrupt();
            if (!(test.counter == 0)) { (jasmine)->expects++; (jasmine)->group = 0; (jasmine)->reason = "test.counter == 0"; continue; } else { (jasmine)->group = 1; (jasmine)->expects++; };
            if (!(!e3_timer_tick())) { (jasmine)->expects++; (jasmine)->group = 0; (jasmine)->reason = "!e3_timer_tick()"; continue; } else { (jasmine)->group = 1; (jasmine)->expects++; };
            if (!(test.counter == 1)) { (jasmine)->expects++; (jasmine)->group = 0; (jasmine)->reason = "test.counter == 1"; continue; } else { (jasmine)->group = 1; (jasmine)->expects++; };
        }
        for ((jasmine)->group = 2, (jasmine)->last = (unsigned short) ((jasmine)->last < 131 ? 131 : (jasmine)->last); 1 == (jasmine)->state && (jasmine)->current < 131 && (131 == ((jasmine)->current = 131)); (jasmine)->state = 2, ((jasmine)->group == 2 ? ((jasmine)->ignored++, puts(" ! " "can tick slower than the interrupt"), 2) : ((jasmine)->group == 1 ? ((jasmine)->passed++, puts(" ✓ " "can tick slower than the interrupt"), 1) : ((jasmine)->failed++, printf(" ✗ " "can tick slower than the interrupt" ": expected %s\r\n", (jasmine)->reason), 0)))) {
            e3_timer_create(&test.timer_1, 2,
                (e3_timer_function_t) triple, &test);
            e3_timer_create(&test.timer_2, 1,
                (e3_timer_function_t) increment, &test);
            if (!(test.counter == 0)) { (jasmine)->expects++; (jasmine)->group = 0; (jasmine)->reason = "test.counter == 0"; continue; } else { (jasmine)->group = 1; (jasmine)->expects++; };
            e3_timer_interrupt();
            e3_timer_interrupt();
            e3_timer_interrupt();
            e3_timer_interrupt();
            if (!(test.counter == 0)) { (jasmine)->expects++; (jasmine)->group = 0; (jasmine)->reason = "test.counter == 0"; continue; } else { (jasmine)->group = 1; (jasmine)->expects++; };
            if (!(!e3_timer_tick())) { (jasmine)->expects++; (jasmine)->group = 0; (jasmine)->reason = "!e3_timer_tick()"; continue; } else { (jasmine)->group = 1; (jasmine)->expects++; };
            if (!(test.counter == 3)) { (jasmine)->expects++; (jasmine)->group = 0; (jasmine)->reason = "test.counter == 3"; continue; } else { (jasmine)->group = 1; (jasmine)->expects++; };
        }
        for ((jasmine)->group = 2, (jasmine)->last = (unsigned short) ((jasmine)->last < 148 ? 148 : (jasmine)->last); 1 == (jasmine)->state && (jasmine)->current < 148 && (148 == ((jasmine)->current = 148)); (jasmine)->state = 2, ((jasmine)->group == 2 ? ((jasmine)->ignored++, puts(" ! " "can create a timer within a timer function"), 2) : ((jasmine)->group == 1 ? ((jasmine)->passed++, puts(" ✓ " "can create a timer within a timer function"), 1) : ((jasmine)->failed++, printf(" ✗ " "can create a timer within a timer function" ": expected %s\r\n", (jasmine)->reason), 0)))) {
            e3_timer_create(&test.timer_1, 0,
                (e3_timer_function_t) reschedule, &test);
            if (!(test.counter == 0)) { (jasmine)->expects++; (jasmine)->group = 0; (jasmine)->reason = "test.counter == 0"; continue; } else { (jasmine)->group = 1; (jasmine)->expects++; };
            if (!(e3_timer_tick())) { (jasmine)->expects++; (jasmine)->group = 0; (jasmine)->reason = "e3_timer_tick()"; continue; } else { (jasmine)->group = 1; (jasmine)->expects++; };
            if (!(test.counter == 1)) { (jasmine)->expects++; (jasmine)->group = 0; (jasmine)->reason = "test.counter == 1"; continue; } else { (jasmine)->group = 1; (jasmine)->expects++; };
            if (!(e3_timer_tick())) { (jasmine)->expects++; (jasmine)->group = 0; (jasmine)->reason = "e3_timer_tick()"; continue; } else { (jasmine)->group = 1; (jasmine)->expects++; };
            if (!(test.counter == 2)) { (jasmine)->expects++; (jasmine)->group = 0; (jasmine)->reason = "test.counter == 2"; continue; } else { (jasmine)->group = 1; (jasmine)->expects++; };
            e3_timer_delete(&test.timer_1);
            if (!(!e3_timer_tick())) { (jasmine)->expects++; (jasmine)->group = 0; (jasmine)->reason = "!e3_timer_tick()"; continue; } else { (jasmine)->group = 1; (jasmine)->expects++; };
            if (!(test.counter == 2)) { (jasmine)->expects++; (jasmine)->group = 0; (jasmine)->reason = "test.counter == 2"; continue; } else { (jasmine)->group = 1; (jasmine)->expects++; };
        }
    }
}

canonical_original_code:
void e3_timer_test(struct jasmine *jasmine) {
    struct test test;
    for ((jasmine)->state = 0, (jasmine)->current = 0, (jasmine)->last = 0, puts("the system timer"); (3 == (jasmine)->state) ? (puts(""), 0) : 1; ) {
        for (; 0 == (jasmine)->state; (jasmine)->state = 1) {
            test.counter = 0;
        }
        for (; 2 == (jasmine)->state; (jasmine)->state = ((jasmine)->current == (jasmine)->last) ? 3 : 0) {
        }
        for ((jasmine)->group = 2, (jasmine)->last = (unsigned short) ((jasmine)->last < 64 ? 64 : (jasmine)->last); 1 == (jasmine)->state && (jasmine)->current < 64 && (64 == ((jasmine)->current = 64)); (jasmine)->state = 2, ((jasmine)->group == 2 ? ((jasmine)->ignored++, puts(" ! " "can tick without any timers created"), 2) : ((jasmine)->group == 1 ? ((jasmine)->passed++, puts(" ✓ " "can tick without any timers created"), 1) : ((jasmine)->failed++, printf(" ✗ " "can tick without any timers created" ": expected %s\r\n", (jasmine)->reason), 0)))) {
            if (!(!e3_timer_tick())) { (jasmine)->expects++; (jasmine)->group = 0; (jasmine)->reason = "!e3_timer_tick()"; continue; } else { (jasmine)->group = 1; (jasmine)->expects++; };
            if (!(test.counter == 0)) { (jasmine)->expects++; (jasmine)->group = 0; (jasmine)->reason = "test.counter == 0"; continue; } else { (jasmine)->group = 1; (jasmine)->expects++; };
        }
        for ((jasmine)->group = 2, (jasmine)->last = (unsigned short) ((jasmine)->last < 69 ? 69 : (jasmine)->last); 1 == (jasmine)->state && (jasmine)->current < 69 && (69 == ((jasmine)->current = 69)); (jasmine)->state = 2, ((jasmine)->group == 2 ? ((jasmine)->ignored++, puts(" ! " "does not require an interrupt for a zero tick"), 2) : ((jasmine)->group == 1 ? ((jasmine)->passed++, puts(" ✓ " "does not require an interrupt for a zero tick"), 1) : ((jasmine)->failed++, printf(" ✗ " "does not require an interrupt for a zero tick" ": expected %s\r\n", (jasmine)->reason), 0)))) {
            e3_timer_create(&test.timer_1, 0,
                (void (*)(void *cookie)) increment, &test);
            if (!(test.counter == 0)) { (jasmine)->expects++; (jasmine)->group = 0; (jasmine)->reason = "test.counter == 0"; continue; } else { (jasmine)->group = 1; (jasmine)->expects++; };
            if (!(!e3_timer_tick())) { (jasmine)->expects++; (jasmine)->group = 0; (jasmine)->reason = "!e3_timer_tick()"; continue; } else { (jasmine)->group = 1; (jasmine)->expects++; };
            if (!(test.counter == 1)) { (jasmine)->expects++; (jasmine)->group = 0; (jasmine)->reason = "test.counter == 1"; continue; } else { (jasmine)->group = 1; (jasmine)->expects++; };
        }
        for ((jasmine)->group = 2, (jasmine)->last = (unsigned short) ((jasmine)->last < 78 ? 78 : (jasmine)->last); 1 == (jasmine)->state && (jasmine)->current < 78 && (78 == ((jasmine)->current = 78)); (jasmine)->state = 2, ((jasmine)->group == 2 ? ((jasmine)->ignored++, puts(" ! " "can have multiple timers with the same ticks"), 2) : ((jasmine)->group == 1 ? ((jasmine)->passed++, puts(" ✓ " "can have multiple timers with the same ticks"), 1) : ((jasmine)->failed++, printf(" ✗ " "can have multiple timers with the same ticks" ": expected %s\r\n", (jasmine)->reason), 0)))) {
            e3_timer_create(&test.timer_1, 0,
                (void (*)(void *cookie)) increment, &test);
            e3_timer_create(&test.timer_2, 0,
                (void (*)(void *cookie)) increment, &test);
            if (!(test.counter == 0)) { (jasmine)->expects++; (jasmine)->group = 0; (jasmine)->reason = "test.counter == 0"; continue; } else { (jasmine)->group = 1; (jasmine)->expects++; };
            if (!(!e3_timer_tick())) { (jasmine)->expects++; (jasmine)->group = 0; (jasmine)->reason = "!e3_timer_tick()"; continue; } else { (jasmine)->group = 1; (jasmine)->expects++; };
            if (!(test.counter == 2)) { (jasmine)->expects++; (jasmine)->group = 0; (jasmine)->reason = "test.counter == 2"; continue; } else { (jasmine)->group = 1; (jasmine)->expects++; };
        }
        for ((jasmine)->group = 2, (jasmine)->last = (unsigned short) ((jasmine)->last < 90 ? 90 : (jasmine)->last); 1 == (jasmine)->state && (jasmine)->current < 90 && (90 == ((jasmine)->current = 90)); (jasmine)->state = 2, ((jasmine)->group == 2 ? ((jasmine)->ignored++, puts(" ! " "will ignore invalid timer functions"), 2) : ((jasmine)->group == 1 ? ((jasmine)->passed++, puts(" ✓ " "will ignore invalid timer functions"), 1) : ((jasmine)->failed++, printf(" ✗ " "will ignore invalid timer functions" ": expected %s\r\n", (jasmine)->reason), 0)))) {
            e3_timer_create(&test.timer_1, 0, 0, 0);
            if (!(test.counter == 0)) { (jasmine)->expects++; (jasmine)->group = 0; (jasmine)->reason = "test.counter == 0"; continue; } else { (jasmine)->group = 1; (jasmine)->expects++; };
            if (!(!e3_timer_tick())) { (jasmine)->expects++; (jasmine)->group = 0; (jasmine)->reason = "!e3_timer_tick()"; continue; } else { (jasmine)->group = 1; (jasmine)->expects++; };
            if (!(test.counter == 0)) { (jasmine)->expects++; (jasmine)->group = 0; (jasmine)->reason = "test.counter == 0"; continue; } else { (jasmine)->group = 1; (jasmine)->expects++; };
        }
        for ((jasmine)->group = 2, (jasmine)->last = (unsigned short) ((jasmine)->last < 97 ? 97 : (jasmine)->last); 1 == (jasmine)->state && (jasmine)->current < 97 && (97 == ((jasmine)->current = 97)); (jasmine)->state = 2, ((jasmine)->group == 2 ? ((jasmine)->ignored++, puts(" ! " "can delete a timer that has been created"), 2) : ((jasmine)->group == 1 ? ((jasmine)->passed++, puts(" ✓ " "can delete a timer that has been created"), 1) : ((jasmine)->failed++, printf(" ✗ " "can delete a timer that has been created" ": expected %s\r\n", (jasmine)->reason), 0)))) {
            e3_timer_create(&test.timer_1, 0,
                (void (*)(void *cookie)) triple, &test);
            e3_timer_create(&test.timer_2, 0,
                (void (*)(void *cookie)) increment, &test);
            if (!(test.counter == 0)) { (jasmine)->expects++; (jasmine)->group = 0; (jasmine)->reason = "test.counter == 0"; continue; } else { (jasmine)->group = 1; (jasmine)->expects++; };
            e3_timer_delete(&test.timer_1);
            if (!(!e3_timer_tick())) { (jasmine)->expects++; (jasmine)->group = 0; (jasmine)->reason = "!e3_timer_tick()"; continue; } else { (jasmine)->group = 1; (jasmine)->expects++; };
            if (!(test.counter == 1)) { (jasmine)->expects++; (jasmine)->group = 0; (jasmine)->reason = "test.counter == 1"; continue; } else { (jasmine)->group = 1; (jasmine)->expects++; };
        }
        for ((jasmine)->group = 2, (jasmine)->last = (unsigned short) ((jasmine)->last < 110 ? 110 : (jasmine)->last); 1 == (jasmine)->state && (jasmine)->current < 110 && (110 == ((jasmine)->current = 110)); (jasmine)->state = 2, ((jasmine)->group == 2 ? ((jasmine)->ignored++, puts(" ! " "can delete a timer that has not been created"), 2) : ((jasmine)->group == 1 ? ((jasmine)->passed++, puts(" ✓ " "can delete a timer that has not been created"), 1) : ((jasmine)->failed++, printf(" ✗ " "can delete a timer that has not been created" ": expected %s\r\n", (jasmine)->reason), 0)))) {
            e3_timer_delete(&test.timer_1);
            if (!(!e3_timer_tick())) { (jasmine)->expects++; (jasmine)->group = 0; (jasmine)->reason = "!e3_timer_tick()"; continue; } else { (jasmine)->group = 1; (jasmine)->expects++; };
            if (!(test.counter == 0)) { (jasmine)->expects++; (jasmine)->group = 0; (jasmine)->reason = "test.counter == 0"; continue; } else { (jasmine)->group = 1; (jasmine)->expects++; };
        }
        for ((jasmine)->group = 2, (jasmine)->last = (unsigned short) ((jasmine)->last < 116 ? 116 : (jasmine)->last); 1 == (jasmine)->state && (jasmine)->current < 116 && (116 == ((jasmine)->current = 116)); (jasmine)->state = 2, ((jasmine)->group == 2 ? ((jasmine)->ignored++, puts(" ! " "can tick faster than the interrupt"), 2) : ((jasmine)->group == 1 ? ((jasmine)->passed++, puts(" ✓ " "can tick faster than the interrupt"), 1) : ((jasmine)->failed++, printf(" ✗ " "can tick faster than the interrupt" ": expected %s\r\n", (jasmine)->reason), 0)))) {
            e3_timer_create(&test.timer_1, 1,
                (void (*)(void *cookie)) increment, &test);
            if (!(test.counter == 0)) { (jasmine)->expects++; (jasmine)->group = 0; (jasmine)->reason = "test.counter == 0"; continue; } else { (jasmine)->group = 1; (jasmine)->expects++; };
            if (!(e3_timer_tick())) { (jasmine)->expects++; (jasmine)->group = 0; (jasmine)->reason = "e3_timer_tick()"; continue; } else { (jasmine)->group = 1; (jasmine)->expects++; };
            if (!(test.counter == 0)) { (jasmine)->expects++; (jasmine)->group = 0; (jasmine)->reason = "test.counter == 0"; continue; } else { (jasmine)->group = 1; (jasmine)->expects++; };
            if (!(e3_timer_tick())) { (jasmine)->expects++; (jasmine)->group = 0; (jasmine)->reason = "e3_timer_tick()"; continue; } else { (jasmine)->group = 1; (jasmine)->expects++; };
            if (!(test.counter == 0)) { (jasmine)->expects++; (jasmine)->group = 0; (jasmine)->reason = "test.counter == 0"; continue; } else { (jasmine)->group = 1; (jasmine)->expects++; };
            e3_timer_interrupt();
            if (!(test.counter == 0)) { (jasmine)->expects++; (jasmine)->group = 0; (jasmine)->reason = "test.counter == 0"; continue; } else { (jasmine)->group = 1; (jasmine)->expects++; };
            if (!(!e3_timer_tick())) { (jasmine)->expects++; (jasmine)->group = 0; (jasmine)->reason = "!e3_timer_tick()"; continue; } else { (jasmine)->group = 1; (jasmine)->expects++; };
            if (!(test.counter == 1)) { (jasmine)->expects++; (jasmine)->group = 0; (jasmine)->reason = "test.counter == 1"; continue; } else { (jasmine)->group = 1; (jasmine)->expects++; };
        }
        for ((jasmine)->group = 2, (jasmine)->last = (unsigned short) ((jasmine)->last < 131 ? 131 : (jasmine)->last); 1 == (jasmine)->state && (jasmine)->current < 131 && (131 == ((jasmine)->current = 131)); (jasmine)->state = 2, ((jasmine)->group == 2 ? ((jasmine)->ignored++, puts(" ! " "can tick slower than the interrupt"), 2) : ((jasmine)->group == 1 ? ((jasmine)->passed++, puts(" ✓ " "can tick slower than the interrupt"), 1) : ((jasmine)->failed++, printf(" ✗ " "can tick slower than the interrupt" ": expected %s\r\n", (jasmine)->reason), 0)))) {
            e3_timer_create(&test.timer_1, 2,
                (void (*)(void *cookie)) triple, &test);
            e3_timer_create(&test.timer_2, 1,
                (void (*)(void *cookie)) increment, &test);
            if (!(test.counter == 0)) { (jasmine)->expects++; (jasmine)->group = 0; (jasmine)->reason = "test.counter == 0"; continue; } else { (jasmine)->group = 1; (jasmine)->expects++; };
            e3_timer_interrupt();
            e3_timer_interrupt();
            e3_timer_interrupt();
            e3_timer_interrupt();
            if (!(test.counter == 0)) { (jasmine)->expects++; (jasmine)->group = 0; (jasmine)->reason = "test.counter == 0"; continue; } else { (jasmine)->group = 1; (jasmine)->expects++; };
            if (!(!e3_timer_tick())) { (jasmine)->expects++; (jasmine)->group = 0; (jasmine)->reason = "!e3_timer_tick()"; continue; } else { (jasmine)->group = 1; (jasmine)->expects++; };
            if (!(test.counter == 3)) { (jasmine)->expects++; (jasmine)->group = 0; (jasmine)->reason = "test.counter == 3"; continue; } else { (jasmine)->group = 1; (jasmine)->expects++; };
        }
        for ((jasmine)->group = 2, (jasmine)->last = (unsigned short) ((jasmine)->last < 148 ? 148 : (jasmine)->last); 1 == (jasmine)->state && (jasmine)->current < 148 && (148 == ((jasmine)->current = 148)); (jasmine)->state = 2, ((jasmine)->group == 2 ? ((jasmine)->ignored++, puts(" ! " "can create a timer within a timer function"), 2) : ((jasmine)->group == 1 ? ((jasmine)->passed++, puts(" ✓ " "can create a timer within a timer function"), 1) : ((jasmine)->failed++, printf(" ✗ " "can create a timer within a timer function" ": expected %s\r\n", (jasmine)->reason), 0)))) {
            e3_timer_create(&test.timer_1, 0,
                (void (*)(void *cookie)) reschedule, &test);
            if (!(test.counter == 0)) { (jasmine)->expects++; (jasmine)->group = 0; (jasmine)->reason = "test.counter == 0"; continue; } else { (jasmine)->group = 1; (jasmine)->expects++; };
            if (!(e3_timer_tick())) { (jasmine)->expects++; (jasmine)->group = 0; (jasmine)->reason = "e3_timer_tick()"; continue; } else { (jasmine)->group = 1; (jasmine)->expects++; };
            if (!(test.counter == 1)) { (jasmine)->expects++; (jasmine)->group = 0; (jasmine)->reason = "test.counter == 1"; continue; } else { (jasmine)->group = 1; (jasmine)->expects++; };
            if (!(e3_timer_tick())) { (jasmine)->expects++; (jasmine)->group = 0; (jasmine)->reason = "e3_timer_tick()"; continue; } else { (jasmine)->group = 1; (jasmine)->expects++; };
            if (!(test.counter == 2)) { (jasmine)->expects++; (jasmine)->group = 0; (jasmine)->reason = "test.counter == 2"; continue; } else { (jasmine)->group = 1; (jasmine)->expects++; };
            e3_timer_delete(&test.timer_1);
            if (!(!e3_timer_tick())) { (jasmine)->expects++; (jasmine)->group = 0; (jasmine)->reason = "!e3_timer_tick()"; continue; } else { (jasmine)->group = 1; (jasmine)->expects++; };
            if (!(test.counter == 2)) { (jasmine)->expects++; (jasmine)->group = 0; (jasmine)->reason = "test.counter == 2"; continue; } else { (jasmine)->group = 1; (jasmine)->expects++; };
        }
    }
}

variable_types: struct jasmine { char *reason; unsigned short state; unsigned short group; unsigned short current; unsigned short last; unsigned short passed; unsigned short failed; unsigned short ignored; unsigned short expects; } *

variable_types: struct test { struct e3_timer { struct e3_timer *next; unsigned long ticks; void (*function)(void *cookie); void *cookie; } timer_1; struct e3_timer timer_2; unsigned int counter; }


main

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

v4[0] = 0LL;
v4[1] = 0x20000LL;
v5 = 0LL;
e3_timer_test(v4, argv, envp);
e3_hsm_test(v4);
e3_event_test(v4);
e3_tcp_client_test(v4);
printf(
"jasmine: %u passed, %u failed, %u ignored, %u expects\r\n",
(unsigned __int16)v5,
WORD1(v5),
WORD2(v5),
HIWORD(v5));
return WORD1(v5);
}

original_code:
int main(void) {
    jasmine_t jasmine;
    do { (&jasmine)->state = 0; (&jasmine)->group = 2; (&jasmine)->current = 0; (&jasmine)->last = 0; (&jasmine)->passed = 0; (&jasmine)->failed = 0; (&jasmine)->ignored = 0; (&jasmine)->expects = 0; (&jasmine)->reason = 0; } while (0);
    e3_timer_test(&jasmine);
    e3_hsm_test(&jasmine);
    e3_event_test(&jasmine);
    e3_tcp_client_test(&jasmine);
    printf("jasmine: %u passed, %u failed, %u ignored, %u expects\r\n",
        jasmine.passed, jasmine.failed, jasmine.ignored, jasmine.expects);
    return jasmine.failed;
}

canonical_original_code:
int main() {
    struct jasmine jasmine;
    do { (&jasmine)->state = 0; (&jasmine)->group = 2; (&jasmine)->current = 0; (&jasmine)->last = 0; (&jasmine)->passed = 0; (&jasmine)->failed = 0; (&jasmine)->ignored = 0; (&jasmine)->expects = 0; (&jasmine)->reason = 0; } while (0);
    e3_timer_test(&jasmine);
    e3_hsm_test(&jasmine);
    e3_event_test(&jasmine);
    e3_tcp_client_test(&jasmine);
    printf("jasmine: %u passed, %u failed, %u ignored, %u expects\r\n",
        jasmine.passed, jasmine.failed, jasmine.ignored, jasmine.expects);
    return jasmine.failed;
}

variable_types: struct jasmine { char *reason; unsigned short state; unsigned short group; unsigned short current; unsigned short last; unsigned short passed; unsigned short failed; unsigned short ignored; unsigned short expects; }


connected

decompiled_code:
void __fastcall connected(__int64 a1)
{
++*(_DWORD *)(a1 + 232);
}

original_code:
static void
connected(test_t *test, void *arg) {
    test->connected++;
    (void) arg;
}

canonical_original_code:
static void connected(struct test *test, void *arg) {
    test->connected++;
    (void) arg;
}

variable_types: struct test { struct e3_socket_double { struct e3_socket { struct e3_socket_interface { void (*connect)(struct e3_socket *socket, char *host, int port); int (*is_connected)(struct e3_socket *socket); int (*is_data_available)(struct e3_socket *socket); int (*is_error)(struct e3_socket *socket); } *interface; } socket; char *host; int port; int is_connected; int is_data_available; int is_error; } socket; struct e3_tcp_client { struct e3_socket *socket; unsigned long poll_interval; struct e3_event { struct e3_event_listener { struct e3_event_listener *next; struct e3_event *event; void (*function)(void *hint, void *args); void *cookie; } *listeners; } connected; struct e3_event timeout; struct e3_event disconnected; struct e3_timer { struct e3_timer *next; unsigned long ticks; void (*function)(void *cookie); void *cookie; } poll_timer; struct e3_timer timeout_timer; } client; struct e3_event_listener connect_listener; struct e3_event_listener timeout_listener; struct e3_event_listener disconnect_listener; unsigned int connected; unsigned int timeout; unsigned int disconnected; } *

variable_types:
arg
void *

user_defined_types: struct test { struct e3_socket_double socket; struct e3_tcp_client client; struct e3_event_listener connect_listener; struct e3_event_listener timeout_listener; struct e3_event_listener disconnect_listener; unsigned int connected; unsigned int timeout; unsigned int disconnected; }

user_defined_types: struct e3_socket_double { struct e3_socket socket; char *host; int port; int is_connected; int is_data_available; int is_error; }

user_defined_types: struct e3_tcp_client { struct e3_socket *socket; unsigned long poll_interval; struct e3_event connected; struct e3_event timeout; struct e3_event disconnected; struct e3_timer poll_timer; struct e3_timer timeout_timer; }

user_defined_types: struct e3_socket { struct e3_socket_interface *interface; }

user_defined_types: struct e3_event { struct e3_event_listener *listeners; }


timeout

decompiled_code:
void __fastcall timeout(__int64 a1)
{
++*(_DWORD *)(a1 + 236);
}

original_code:
static void
timeout(test_t *test, void *arg) {
    test->timeout++;
    (void) arg;
}

canonical_original_code:
static void timeout(struct test *test, void *arg) {
    test->timeout++;
    (void) arg;
}

user_defined_types: struct e3_socket_interface { void (*connect)(struct e3_socket *socket, char *host, int port); int (*is_connected)(struct e3_socket *socket); int (*is_data_available)(struct e3_socket *socket); int (*is_error)(struct e3_socket *socket); }

user_defined_types: struct e3_event_listener { struct e3_event_listener *next; struct e3_event *event; void (*function)(void *hint, void *args); void *cookie; }


disconnected

decompiled_code:
void __fastcall disconnected(__int64 a1)
{
++*(_DWORD *)(a1 + 240);
}

original_code:
static void
disconnected(test_t *test, void *arg) {
    test->disconnected++;
    (void) arg;
}

canonical_original_code:
static void disconnected(struct test *test, void *arg) {
    test->disconnected++;
    (void) arg;
}


tick

decompiled_code:
__int64 tick()
{
e3_timer_interrupt();
return e3_timer_tick();
}

canonical_decompiled_code:
__int64 func3()
{
e3_timer_interrupt();
return e3_timer_tick();
}

original_code:
static e3_timer_ticks_t
tick(void) {
    e3_timer_interrupt();
    return e3_timer_tick();
}

canonical_original_code:
static unsigned long tick() {
    e3_timer_interrupt();
    return e3_timer_tick();
}


original_code:
void
e3_tcp_client_test(jasmine_t *jasmine) {
    test_t test;
    for ((jasmine)->state = 0, (jasmine)->current = 0, (jasmine)->last = 0, puts("a tcp client"); (3 == (jasmine)->state) ? (puts(""), 0) : 1; ) {
        for (; 0 == (jasmine)->state; (jasmine)->state = 1) {
            (&(&test.socket)->socket)->interface = (E3_SOCKET_DOUBLE);
            (&test.socket)->is_connected = (0);
            (&test.socket)->is_data_available = (0);
            (&test.socket)->is_error = (0);
            e3_tcp_client_create(&test.client, &test.socket.socket, 0);
            e3_event_listener_create(&test.connect_listener,
                &test.client.connected,
                (e3_event_handler_t) connected, &test);
            e3_event_listener_create(&test.timeout_listener,
                &test.client.timeout,
                (e3_event_handler_t) timeout, &test);
            e3_event_listener_create(&test.disconnect_listener,
                &test.client.disconnected,
                (e3_event_handler_t) disconnected, &test);
            test.connected = 0;
            test.timeout = 0;
            test.disconnected = 0;
        }
        for (; 2 == (jasmine)->state; (jasmine)->state = ((jasmine)->current == (jasmine)->last) ? 3 : 0) {
            e3_event_listener_delete(&test.connect_listener);
            e3_event_listener_delete(&test.timeout_listener);
            e3_event_listener_delete(&test.disconnect_listener);
            e3_tcp_client_delete(&test.client);
            ;
        }
        for ((jasmine)->group = 2, (jasmine)->last = (unsigned short) ((jasmine)->last < 101 ? 101 : (jasmine)->last); 1 == (jasmine)->state && (jasmine)->current < 101 && (101 == ((jasmine)->current = 101)); (jasmine)->state = 2, ((jasmine)->group == 2 ? ((jasmine)->ignored++, puts(" ! " "can connect before the timeout is reached"), 2) : ((jasmine)->group == 1 ? ((jasmine)->passed++, puts(" ✓ " "can connect before the timeout is reached"), 1) : ((jasmine)->failed++, printf(" ✗ " "can connect before the timeout is reached" ": expected %s\r\n", (jasmine)->reason), 0)))) {
            e3_tcp_client_connect(&test.client, "localhost", 80, 11);
            while (tick()) {
                (&test.socket)->is_connected = (1);
            }
            if (!(test.connected == 1)) { (jasmine)->expects++; (jasmine)->group = 0; (jasmine)->reason = "test.connected == 1"; continue; } else { (jasmine)->group = 1; (jasmine)->expects++; };
            if (!(test.timeout == 0)) { (jasmine)->expects++; (jasmine)->group = 0; (jasmine)->reason = "test.timeout == 0"; continue; } else { (jasmine)->group = 1; (jasmine)->expects++; };
            if (!(test.disconnected == 0)) { (jasmine)->expects++; (jasmine)->group = 0; (jasmine)->reason = "test.disconnected == 0"; continue; } else { (jasmine)->group = 1; (jasmine)->expects++; };
        }
        for ((jasmine)->group = 2, (jasmine)->last = (unsigned short) ((jasmine)->last < 113 ? 113 : (jasmine)->last); 1 == (jasmine)->state && (jasmine)->current < 113 && (113 == ((jasmine)->current = 113)); (jasmine)->state = 2, ((jasmine)->group == 2 ? ((jasmine)->ignored++, puts(" ! " "can timeout while connecting"), 2) : ((jasmine)->group == 1 ? ((jasmine)->passed++, puts(" ✓ " "can timeout while connecting"), 1) : ((jasmine)->failed++, printf(" ✗ " "can timeout while connecting" ": expected %s\r\n", (jasmine)->reason), 0)))) {
            e3_tcp_client_connect(&test.client, "localhost", 80, 11);
            while (tick());
            if (!(test.connected == 0)) { (jasmine)->expects++; (jasmine)->group = 0; (jasmine)->reason = "test.connected == 0"; continue; } else { (jasmine)->group = 1; (jasmine)->expects++; };
            if (!(test.timeout == 1)) { (jasmine)->expects++; (jasmine)->group = 0; (jasmine)->reason = "test.timeout == 1"; continue; } else { (jasmine)->group = 1; (jasmine)->expects++; };
            if (!(test.disconnected == 0)) { (jasmine)->expects++; (jasmine)->group = 0; (jasmine)->reason = "test.disconnected == 0"; continue; } else { (jasmine)->group = 1; (jasmine)->expects++; };
        }
        for ((jasmine)->group = 2, (jasmine)->last = (unsigned short) ((jasmine)->last < 123 ? 123 : (jasmine)->last); 1 == (jasmine)->state && (jasmine)->current < 123 && (123 == ((jasmine)->current = 123)); (jasmine)->state = 2, ((jasmine)->group == 2 ? ((jasmine)->ignored++, puts(" ! " "can disconnect while connecting"), 2) : ((jasmine)->group == 1 ? ((jasmine)->passed++, puts(" ✓ " "can disconnect while connecting"), 1) : ((jasmine)->failed++, printf(" ✗ " "can disconnect while connecting" ": expected %s\r\n", (jasmine)->reason), 0)))) {
            e3_tcp_client_connect(&test.client, "localhost", 80, 11);
            while (tick()) {
                (&test.socket)->is_error = (1);
            }
            if (!(test.connected == 0)) { (jasmine)->expects++; (jasmine)->group = 0; (jasmine)->reason = "test.connected == 0"; continue; } else { (jasmine)->group = 1; (jasmine)->expects++; };
            if (!(test.timeout == 0)) { (jasmine)->expects++; (jasmine)->group = 0; (jasmine)->reason = "test.timeout == 0"; continue; } else { (jasmine)->group = 1; (jasmine)->expects++; };
            if (!(test.disconnected == 1)) { (jasmine)->expects++; (jasmine)->group = 0; (jasmine)->reason = "test.disconnected == 1"; continue; } else { (jasmine)->group = 1; (jasmine)->expects++; };
        }
    }
}

canonical_original_code:
void e3_tcp_client_test(struct jasmine *jasmine) {
    struct test test;
    for ((jasmine)->state = 0, (jasmine)->current = 0, (jasmine)->last = 0, puts("a tcp client"); (3 == (jasmine)->state) ? (puts(""), 0) : 1; ) {
        for (; 0 == (jasmine)->state; (jasmine)->state = 1) {
            (&(&test.socket)->socket)->interface = (E3_SOCKET_DOUBLE);
            (&test.socket)->is_connected = (0);
            (&test.socket)->is_data_available = (0);
            (&test.socket)->is_error = (0);
            e3_tcp_client_create(&test.client, &test.socket.socket, 0);
            e3_event_listener_create(&test.connect_listener,
                &test.client.connected,
                (void (*)(void *hint, void *args)) connected, &test);
            e3_event_listener_create(&test.timeout_listener,
                &test.client.timeout,
                (void (*)(void *hint, void *args)) timeout, &test);
            e3_event_listener_create(&test.disconnect_listener,
                &test.client.disconnected,
                (void (*)(void *hint, void *args)) disconnected, &test);
            test.connected = 0;
            test.timeout = 0;
            test.disconnected = 0;
        }
        for (; 2 == (jasmine)->state; (jasmine)->state = ((jasmine)->current == (jasmine)->last) ? 3 : 0) {
            e3_event_listener_delete(&test.connect_listener);
            e3_event_listener_delete(&test.timeout_listener);
            e3_event_listener_delete(&test.disconnect_listener);
            e3_tcp_client_delete(&test.client);
            ;
        }
        for ((jasmine)->group = 2, (jasmine)->last = (unsigned short) ((jasmine)->last < 101 ? 101 : (jasmine)->last); 1 == (jasmine)->state && (jasmine)->current < 101 && (101 == ((jasmine)->current = 101)); (jasmine)->state = 2, ((jasmine)->group == 2 ? ((jasmine)->ignored++, puts(" ! " "can connect before the timeout is reached"), 2) : ((jasmine)->group == 1 ? ((jasmine)->passed++, puts(" ✓ " "can connect before the timeout is reached"), 1) : ((jasmine)->failed++, printf(" ✗ " "can connect before the timeout is reached" ": expected %s\r\n", (jasmine)->reason), 0)))) {
            e3_tcp_client_connect(&test.client, "localhost", 80, 11);
            while (tick()) {
                (&test.socket)->is_connected = (1);
            }
            if (!(test.connected == 1)) { (jasmine)->expects++; (jasmine)->group = 0; (jasmine)->reason = "test.connected == 1"; continue; } else { (jasmine)->group = 1; (jasmine)->expects++; };
            if (!(test.timeout == 0)) { (jasmine)->expects++; (jasmine)->group = 0; (jasmine)->reason = "test.timeout == 0"; continue; } else { (jasmine)->group = 1; (jasmine)->expects++; };
            if (!(test.disconnected == 0)) { (jasmine)->expects++; (jasmine)->group = 0; (jasmine)->reason = "test.disconnected == 0"; continue; } else { (jasmine)->group = 1; (jasmine)->expects++; };
        }
        for ((jasmine)->group = 2, (jasmine)->last = (unsigned short) ((jasmine)->last < 113 ? 113 : (jasmine)->last); 1 == (jasmine)->state && (jasmine)->current < 113 && (113 == ((jasmine)->current = 113)); (jasmine)->state = 2, ((jasmine)->group == 2 ? ((jasmine)->ignored++, puts(" ! " "can timeout while connecting"), 2) : ((jasmine)->group == 1 ? ((jasmine)->passed++, puts(" ✓ " "can timeout while connecting"), 1) : ((jasmine)->failed++, printf(" ✗ " "can timeout while connecting" ": expected %s\r\n", (jasmine)->reason), 0)))) {
            e3_tcp_client_connect(&test.client, "localhost", 80, 11);
            while (tick());
            if (!(test.connected == 0)) { (jasmine)->expects++; (jasmine)->group = 0; (jasmine)->reason = "test.connected == 0"; continue; } else { (jasmine)->group = 1; (jasmine)->expects++; };
            if (!(test.timeout == 1)) { (jasmine)->expects++; (jasmine)->group = 0; (jasmine)->reason = "test.timeout == 1"; continue; } else { (jasmine)->group = 1; (jasmine)->expects++; };
            if (!(test.disconnected == 0)) { (jasmine)->expects++; (jasmine)->group = 0; (jasmine)->reason = "test.disconnected == 0"; continue; } else { (jasmine)->group = 1; (jasmine)->expects++; };
        }
        for ((jasmine)->group = 2, (jasmine)->last = (unsigned short) ((jasmine)->last < 123 ? 123 : (jasmine)->last); 1 == (jasmine)->state && (jasmine)->current < 123 && (123 == ((jasmine)->current = 123)); (jasmine)->state = 2, ((jasmine)->group == 2 ? ((jasmine)->ignored++, puts(" ! " "can disconnect while connecting"), 2) : ((jasmine)->group == 1 ? ((jasmine)->passed++, puts(" ✓ " "can disconnect while connecting"), 1) : ((jasmine)->failed++, printf(" ✗ " "can disconnect while connecting" ": expected %s\r\n", (jasmine)->reason), 0)))) {
            e3_tcp_client_connect(&test.client, "localhost", 80, 11);
            while (tick()) {
                (&test.socket)->is_error = (1);
            }
            if (!(test.connected == 0)) { (jasmine)->expects++; (jasmine)->group = 0; (jasmine)->reason = "test.connected == 0"; continue; } else { (jasmine)->group = 1; (jasmine)->expects++; };
            if (!(test.timeout == 0)) { (jasmine)->expects++; (jasmine)->group = 0; (jasmine)->reason = "test.timeout == 0"; continue; } else { (jasmine)->group = 1; (jasmine)->expects++; };
            if (!(test.disconnected == 1)) { (jasmine)->expects++; (jasmine)->group = 0; (jasmine)->reason = "test.disconnected == 1"; continue; } else { (jasmine)->group = 1; (jasmine)->expects++; };
        }
    }
}

variable_types: struct test { struct e3_socket_double { struct e3_socket { struct e3_socket_interface { void (*connect)(struct e3_socket *socket, char *host, int port); int (*is_connected)(struct e3_socket *socket); int (*is_data_available)(struct e3_socket *socket); int (*is_error)(struct e3_socket *socket); } *interface; } socket; char *host; int port; int is_connected; int is_data_available; int is_error; } socket; struct e3_tcp_client { struct e3_socket *socket; unsigned long poll_interval; struct e3_event { struct e3_event_listener { struct e3_event_listener *next; struct e3_event *event; void (*function)(void *hint, void *args); void *cookie; } *listeners; } connected; struct e3_event timeout; struct e3_event disconnected; struct e3_timer { struct e3_timer *next; unsigned long ticks; void (*function)(void *cookie); void *cookie; } poll_timer; struct e3_timer timeout_timer; } client; struct e3_event_listener connect_listener; struct e3_event_listener timeout_listener; struct e3_event_listener disconnect_listener; unsigned int connected; unsigned int timeout; unsigned int disconnected; }

user_defined_types: struct jasmine { char *reason; unsigned short state; unsigned short group; unsigned short current; unsigned short last; unsigned short passed; unsigned short failed; unsigned short ignored; unsigned short expects; }


connect

original_code:
static void
connect(e3_socket_t *socket, const char *host, int port) {
    ((e3_socket_double_t *) socket)->host = host;
    ((e3_socket_double_t *) socket)->port = port;
}

canonical_original_code:
static void connect(struct e3_socket *socket, char *host, int port) {
    ((struct e3_socket_double *) socket)->host = host;
    ((struct e3_socket_double *) socket)->port = port;
}

variable_types: struct e3_socket { struct e3_socket_interface { void (*connect)(struct e3_socket *socket, char *host, int port); int (*is_connected)(struct e3_socket *socket); int (*is_data_available)(struct e3_socket *socket); int (*is_error)(struct e3_socket *socket); } *interface; } *

variable_types:
host
char *

variable_types: port int


decompiled_code:
__int64 __fastcall is_connected(__int64 a1)
{
return *(unsigned int *)(a1 + 20);
}

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

original_code:
static int
is_connected(e3_socket_t *socket) {
    return ((e3_socket_double_t *) socket)->is_connected;
}

canonical_original_code:
static int is_connected(struct e3_socket *socket) {
    return ((struct e3_socket_double *) socket)->is_connected;
}


decompiled_code:
__int64 __fastcall is_data_available(__int64 a1)
{
return *(unsigned int *)(a1 + 24);
}

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

original_code:
static int
is_data_available(e3_socket_t *socket) {
    return ((e3_socket_double_t *) socket)->is_data_available;
}

canonical_original_code:
static int is_data_available(struct e3_socket *socket) {
    return ((struct e3_socket_double *) socket)->is_data_available;
}


decompiled_code:
__int64 __fastcall is_error(__int64 a1)
{
return *(unsigned int *)(a1 + 28);
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1)
{
return *(unsigned int *)(a1 + 28);
}

original_code:
static int
is_error(e3_socket_t *socket) {
    return ((e3_socket_double_t *) socket)->is_error;
}

canonical_original_code:
static int is_error(struct e3_socket *socket) {
    return ((struct e3_socket_double *) socket)->is_error;
}


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

++_gcov0_connect_timeout;
e3_timer_delete(a1 + 40);
++qword_498;
result = e3_event_fire(a1 + 24, 0LL);
++qword_4A0;
return result;
}

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

++_gcov0_connect_timeout;
e3_timer_delete(a1 + 40);
++qword_498;
result = e3_event_fire(a1 + 24, 0LL);
++qword_4A0;
return result;
}

original_code:
static void
connect_timeout(e3_tcp_client_t *client) {
    e3_timer_delete(&client->poll_timer);
    e3_event_fire(&client->timeout, 0);
}

canonical_original_code:
static void connect_timeout(struct e3_tcp_client *client) {
    e3_timer_delete(&client->poll_timer);
    e3_event_fire(&client->timeout, 0);
}

variable_types: struct e3_tcp_client { struct e3_socket { struct e3_socket_interface { void (*connect)(struct e3_socket *socket, char *host, int port); int (*is_connected)(struct e3_socket *socket); int (*is_data_available)(struct e3_socket *socket); int (*is_error)(struct e3_socket *socket); } *interface; } *socket; unsigned long poll_interval; struct e3_event { struct e3_event_listener { struct e3_event_listener *next; struct e3_event *event; void (*function)(void *hint, void *args); void *cookie; } *listeners; } connected; struct e3_event timeout; struct e3_event disconnected; struct e3_timer { struct e3_timer *next; unsigned long ticks; void (*function)(void *cookie); void *cookie; } poll_timer; struct e3_timer timeout_timer; } *


connecting

decompiled_code:
__int64 __fastcall connecting(__int64 *a1)
{
__int64 v2; // rdi
__int64 v3; // rdi
__int64 v4; // rsi
__int64 result; // rax

v2 = *a1;
++_gcov0_connecting;
if ( (*(unsigned int (__fastcall **)(__int64))(*(_QWORD *)v2 + 8LL))(v2) )
{
++qword_448;
e3_timer_delete(a1 + 9);
++qword_458;
result = e3_event_fire(a1 + 2, 0LL);
++qword_460;
}
else
{
v3 = *a1;
++qword_450;
if ( (*(unsigned int (__fastcall **)(__int64))(*(_QWORD *)v3 + 24LL))(v3) )
{
++qword_468;
e3_timer_delete(a1 + 9);
++qword_478;
result = e3_event_fire(a1 + 4, 0LL);
++qword_480;
}
else
{
v4 = a1[1];
++qword_470;
result = e3_timer_create(a1 + 5, v4, connecting, a1);
++qword_488;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 *a1)
{
__int64 v2; // rdi
__int64 v3; // rdi
__int64 v4; // rsi
__int64 result; // rax

v2 = *a1;
++_gcov0_connecting;
if ( (*(unsigned int (__fastcall **)(__int64))(*(_QWORD *)v2 + 8LL))(v2) )
{
++qword_448;
e3_timer_delete(a1 + 9);
++qword_458;
result = e3_event_fire(a1 + 2, 0LL);
++qword_460;
}
else
{
v3 = *a1;
++qword_450;
if ( (*(unsigned int (__fastcall **)(__int64))(*(_QWORD *)v3 + 24LL))(v3) )
{
++qword_468;
e3_timer_delete(a1 + 9);
++qword_478;
result = e3_event_fire(a1 + 4, 0LL);
++qword_480;
}
else
{
v4 = a1[1];
++qword_470;
result = e3_timer_create(a1 + 5, v4, connecting, a1);
++qword_488;
}
}
return result;
}

original_code:
static void
connecting(e3_tcp_client_t *client) {
    if ((client->socket)->interface->is_connected(client->socket)) {
        e3_timer_delete(&client->timeout_timer);
        e3_event_fire(&client->connected, 0);
    }
    else if ((client->socket)->interface->is_error(client->socket)) {
        e3_timer_delete(&client->timeout_timer);
        e3_event_fire(&client->disconnected, 0);
    }
    else {
        e3_timer_create(&client->poll_timer, client->poll_interval,
            (e3_timer_function_t) connecting, client);
    }
}

canonical_original_code:
static void connecting(struct e3_tcp_client *client) {
    if ((client->socket)->interface->is_connected(client->socket)) {
        e3_timer_delete(&client->timeout_timer);
        e3_event_fire(&client->connected, 0);
    }
    else if ((client->socket)->interface->is_error(client->socket)) {
        e3_timer_delete(&client->timeout_timer);
        e3_event_fire(&client->disconnected, 0);
    }
    else {
        e3_timer_create(&client->poll_timer, client->poll_interval,
            (void (*)(void *cookie)) connecting, client);
    }
}


decompiled_code:
__int64 __fastcall e3_tcp_client_create(__int64 a1, __int64 a2, __int64 a3)
{
__int64 v4; // rdi
__int64 result; // rax

v4 = a1 + 16;
*(_QWORD *)(v4 - 16) = a2;
*(_QWORD *)(v4 - 8) = a3;
++_gcov0_e3_tcp_client_create;
((void (*)(void))e3_event_create)();
++qword_4C8;
e3_event_create(a1 + 24);
++qword_4D0;
result = e3_event_create(a1 + 32);
++qword_4D8;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, __int64 a2, __int64 a3)
{
__int64 v4; // rdi
__int64 result; // rax

v4 = a1 + 16;
*(_QWORD *)(v4 - 16) = a2;
*(_QWORD *)(v4 - 8) = a3;
++_gcov0_e3_tcp_client_create;
((void (*)(void))e3_event_create)();
++qword_4C8;
e3_event_create(a1 + 24);
++qword_4D0;
result = e3_event_create(a1 + 32);
++qword_4D8;
return result;
}

original_code:
void
e3_tcp_client_create(e3_tcp_client_t *client, e3_socket_t *socket,
    e3_timer_ticks_t poll_interval) {
    client->socket = socket;
    client->poll_interval = poll_interval;
    e3_event_create(&client->connected);
    e3_event_create(&client->timeout);
    e3_event_create(&client->disconnected);
}

canonical_original_code:
void e3_tcp_client_create(struct e3_tcp_client *client, struct e3_socket *socket, unsigned long poll_interval) {
    client->socket = socket;
    client->poll_interval = poll_interval;
    e3_event_create(&client->connected);
    e3_event_create(&client->timeout);
    e3_event_create(&client->disconnected);
}

variable_types:
socket
struct e3_socket *


decompiled_code:
__int64 __fastcall e3_tcp_client_connect(__int64 a1, __int64 a2, __int64 a3, __int64 a4)
{
void (__fastcall ***v6)(_QWORD); // rdi
__int64 v7; // rsi
__int64 result; // rax

v6 = *(void (__fastcall ****)(_QWORD))a1;
++_gcov0_e3_tcp_client_connect;
(**v6)(v6);
v7 = *(_QWORD *)(a1 + 8);
++qword_4E8;
e3_timer_create(a1 + 40, v7, connecting, a1);
++qword_4F0;
result = e3_timer_create(a1 + 72, a4, connect_timeout, a1);
++qword_4F8;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, __int64 a2, __int64 a3, __int64 a4)
{
void (__fastcall ***v6)(_QWORD); // rdi
__int64 v7; // rsi
__int64 result; // rax

v6 = *(void (__fastcall ****)(_QWORD))a1;
++_gcov0_e3_tcp_client_connect;
(**v6)(v6);
v7 = *(_QWORD *)(a1 + 8);
++qword_4E8;
e3_timer_create(a1 + 40, v7, connecting, a1);
++qword_4F0;
result = e3_timer_create(a1 + 72, a4, connect_timeout, a1);
++qword_4F8;
return result;
}

original_code:
void
e3_tcp_client_connect(e3_tcp_client_t *client, const char *host, int port,
    e3_timer_ticks_t timeout) {
    (client->socket)->interface->connect(client->socket, host, port);
    e3_timer_create(&client->poll_timer, client->poll_interval,
        (e3_timer_function_t) connecting, client);
    e3_timer_create(&client->timeout_timer, timeout,
        (e3_timer_function_t) connect_timeout, client);
}

canonical_original_code:
void e3_tcp_client_connect(struct e3_tcp_client *client, char *host, int port, unsigned long timeout) {
    (client->socket)->interface->connect(client->socket, host, port);
    e3_timer_create(&client->poll_timer, client->poll_interval,
        (void (*)(void *cookie)) connecting, client);
    e3_timer_create(&client->timeout_timer, timeout,
        (void (*)(void *cookie)) connect_timeout, client);
}

variable_types:
timeout
unsigned long


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

++_gcov0_e3_tcp_client_delete;
e3_event_delete(a1 + 16);
++qword_508;
e3_event_delete(a1 + 24);
++qword_510;
e3_event_delete(a1 + 32);
++qword_518;
e3_timer_delete(a1 + 40);
++qword_520;
result = e3_timer_delete(a1 + 72);
++qword_528;
return result;
}

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

++_gcov0_e3_tcp_client_delete;
e3_event_delete(a1 + 16);
++qword_508;
e3_event_delete(a1 + 24);
++qword_510;
e3_event_delete(a1 + 32);
++qword_518;
e3_timer_delete(a1 + 40);
++qword_520;
result = e3_timer_delete(a1 + 72);
++qword_528;
return result;
}

original_code:
void
e3_tcp_client_delete(e3_tcp_client_t *client) {
    e3_event_delete(&client->connected);
    e3_event_delete(&client->timeout);
    e3_event_delete(&client->disconnected);
    e3_timer_delete(&client->poll_timer);
    e3_timer_delete(&client->timeout_timer);
}

canonical_original_code:
void e3_tcp_client_delete(struct e3_tcp_client *client) {
    e3_event_delete(&client->connected);
    e3_event_delete(&client->timeout);
    e3_event_delete(&client->disconnected);
    e3_timer_delete(&client->poll_timer);
    e3_timer_delete(&client->timeout_timer);
}


decompiled_code:
void e3_timer_interrupt()
{
++_gcov0_e3_timer_interrupt;
++pending_ticks;
}

canonical_decompiled_code:
void func0()
{
++_gcov0_e3_timer_interrupt;
++pending_ticks;
}

original_code:
void
e3_timer_interrupt(void) {
    pending_ticks++;
}

canonical_original_code:
void e3_timer_interrupt() {
    pending_ticks++;
}


decompiled_code:
_BOOL8 e3_timer_tick()
{
__int64 *v0; // rbx
unsigned __int64 v1; // rbp
__int64 v2; // rcx
__int64 *v3; // rax
unsigned __int64 v4; // rdx
void (__fastcall *v5)(__int64); // rdx
_BOOL8 result; // rax

v0 = (__int64 *)timers;
v1 = pending_ticks;
timers = 0LL;
++_gcov0_e3_timer_tick;
pending_ticks = 0LL;
if ( !v0 )
{
++qword_3A0;
return 0LL;
}
do
{
while ( 1 )
{
v3 = v0;
v0 = (__int64 *)*v0;
v4 = v3[1];
if ( v4 <= v1 )
break;
v2 = timers;
++qword_388;
timers = (__int64)v3;
*v3 = v2;
v3[1] = v4 - v1;
LABEL_4:
if ( !v0 )
goto LABEL_8;
}
v5 = (void (__fastcall *)(__int64))v3[2];
if ( !v5 )
{
++qword_398;
goto LABEL_4;
}
++qword_390;
v5(v3[3]);
}
while ( v0 );
LABEL_8:
result = timers != 0;
++qword_3A0;
return result;
}

canonical_decompiled_code:
_BOOL8 func1()
{
__int64 *v0; // rbx
unsigned __int64 v1; // rbp
__int64 v2; // rcx
__int64 *v3; // rax
unsigned __int64 v4; // rdx
void (__fastcall *v5)(__int64); // rdx
_BOOL8 result; // rax

v0 = (__int64 *)timers;
v1 = pending_ticks;
timers = 0LL;
++_gcov0_e3_timer_tick;
pending_ticks = 0LL;
if ( !v0 )
{
++qword_3A0;
return 0LL;
}
do
{
while ( 1 )
{
v3 = v0;
v0 = (__int64 *)*v0;
v4 = v3[1];
if ( v4 <= v1 )
break;
v2 = timers;
++qword_388;
timers = (__int64)v3;
*v3 = v2;
v3[1] = v4 - v1;
LABEL_4:
if ( !v0 )
goto LABEL_8;
}
v5 = (void (__fastcall *)(__int64))v3[2];
if ( !v5 )
{
++qword_398;
goto LABEL_4;
}
++qword_390;
v5(v3[3]);
}
while ( v0 );
LABEL_8:
result = timers != 0;
++qword_3A0;
return result;
}

original_code:
e3_timer_ticks_t
e3_timer_tick(void) {
    e3_timer_ticks_t ticks;
    e3_timer_t *current;
    e3_timer_t *next;
    ticks = pending_ticks;
    pending_ticks = 0;
    current = timers;
    timers = 0;
    while (current) {
        next = current->next;
        if (current->ticks > ticks) {
            current->next = timers;
            timers = current;
            current->ticks -= ticks;
        }
        else if (current->function) {
            current->function(current->cookie);
        }
        current = next;
    }
    return (timers != 0);
}

canonical_original_code:
unsigned long e3_timer_tick() {
    unsigned long ticks;
    struct e3_timer *current;
    struct e3_timer *next;
    ticks = pending_ticks;
    pending_ticks = 0;
    current = timers;
    timers = 0;
    while (current) {
        next = current->next;
        if (current->ticks > ticks) {
            current->next = timers;
            timers = current;
            current->ticks -= ticks;
        }
        else if (current->function) {
            current->function(current->cookie);
        }
        current = next;
    }
    return (timers != 0);
}

variable_types:
ticks
unsigned long

variable_types: struct e3_timer { struct e3_timer *next; unsigned long ticks; void (*function)(void *cookie); void *cookie; } *


enter

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

if ( *a1 == a2 )
{
++qword_3C8;
}
else
{
v3 = *a2;
++_gcov0_enter;
enter(a1, v3);
*a1 = a2;
++qword_3D0;
result = ((__int64 (__fastcall *)(__int64 **))a2[3])(a1);
++qword_3D8;
}
return result;
}

original_code:
static void
enter(e3_hsm_t *hsm, const e3_hsm_state_t * const state) {
    if (hsm->state != state) {
        enter(hsm, state->parent);
        hsm->state = state;
        hsm->state->enter(hsm);
    }
}

canonical_original_code:
static void enter(struct e3_hsm *hsm, struct e3_hsm_state *state) {
    if (hsm->state != state) {
        enter(hsm, state->parent);
        hsm->state = state;
        hsm->state->enter(hsm);
    }
}

variable_types: struct e3_hsm { struct e3_hsm_state { struct e3_hsm_state *parent; unsigned long ancestry; struct e3_hsm_state *(*transition)(unsigned long signal); void (*enter)(void *cookie); void (*exit)(void *cookie); } *state; } *

variable_types:
state
struct e3_hsm_state *

user_defined_types: struct e3_hsm { struct e3_hsm_state *state; }