int _C_DATA_SIZE = 8192;
#include "forth.h"
#include "forth2c.h"
Cells2 mybounds(Cell p0, Cell p1)
{
Cells2 _c_result;
Cell x0;
{
Cell n1, n2;
n2 = p0;
n1 = p1;
p1 = n1;
p0 = n2;
x0 = n1;
}
{
Cell n1, n2, n;
n1 = x0;
n2 = p0;
n = n2 + n1;
p0 = n;
}
{
Cell n1, n2;
n1 = p0;
n2 = p1;
p1 = n1;
p0 = n2;
}
{
_c_result.cell0 = p0;
_c_result.cell1 = p1;
return (_c_result);
}
}
Char seed[4];
void initiate_seed(void)
{
Cell x0;
Cell x1;
{
x0 = 74755;
}
{
x1 = (Cell) (&seed[0]);
}
{
Cell *a, n;
a = (Cell *) x1;
n = x0;
*a = n;
}
{
return;
}
}
Cell random(void)
{
Cell _c_result;
Cell x0;
Cell x1;
Cell x2;
{
x0 = (Cell) (&seed[0]);
}
{
Cell *a;
a = (Cell *) x0;
x0 = *a;
}
{
x1 = 1309;
}
{
Cell n1, n2, n;
n1 = x1;
n2 = x0;
n = n2 * n1;
x0 = n;
}
{
x1 = 13849;
}
{
Cell n1, n2, n;
n1 = x1;
n2 = x0;
n = n2 + n1;
x0 = n;
}
{
x1 = 65535;
}
{
Cell n1, n2, n;
n1 = x1;
n2 = x0;
n = n2 & n1;
x0 = n;
}
{
Cell n;
n = x0;
x0 = n;
x1 = n;
}
{
x2 = (Cell) (&seed[0]);
}
{
Cell *a, n;
a = (Cell *) x2;
n = x1;
*a = n;
}
{
_c_result = x0;
return (_c_result);
}
}
#define elements 6000
Char list[24000];
void initiate_list(void)
{
Cell x0;
Cell x1;
Cell r0;
Cell r1;
{
x0 = (Cell) (&list[0]);
}
{
x1 = (Cell) elements;
}
{
Cell n;
n = x1;
x1 = n * sizeof(Cell);
}
{
Cell n1, n2, n;
n1 = x1;
n2 = x0;
n = n2 + n1;
x0 = n;
}
{
x1 = (Cell) (&list[0]);
}
{
Cell bound, index;
index = x1;
bound = x0;
r0 = bound;
r1 = index;
}
label0:
{
Cell _C_locret;
_C_locret = random();
x0 = _C_locret;
}
{
Cell n = r1;
x1 = n;
}
{
Cell *a, n;
a = (Cell *) x1;
n = x0;
*a = n;
}
{
x0 = sizeof(Cell);
}
{
Cell step, index, bound;
index = r1;
bound = r0;
step = x0;
index += step;
if ((step > 0 && index < bound) ||
(step <= 0 && index >= bound))
{
r0 = bound;
r1 = index;
goto label0;
}
}
{
}
{
return;
}
}
void dump_list(void)
{
Cell x0;
Cell x1;
Cell r0;
Cell r1;
{
x0 = (Cell) (&list[0]);
}
{
x1 = (Cell) elements;
}
{
Cell n;
n = x1;
x1 = n * sizeof(Cell);
}
{
Cell n1, n2, n;
n1 = x1;
n2 = x0;
n = n2 + n1;
x0 = n;
}
{
x1 = (Cell) (&list[0]);
}
{
Cell bound, index;
index = x1;
bound = x0;
r0 = bound;
r1 = index;
}
label0:
{
Cell n = r1;
x0 = n;
}
{
Cell *a;
a = (Cell *) x0;
x0 = *a;
}
{
printf("%d ", x0);
fflush(stdout);
}
{
x0 = sizeof(Cell);
}
{
Cell step, index, bound;
index = r1;
bound = r0;
step = x0;
index += step;
if ((step > 0 && index < bound) ||
(step <= 0 && index >= bound))
{
r0 = bound;
r1 = index;
goto label0;
}
}
{
}
{
printf("\n");
}
{
return;
}
}
void verify_list(void)
{
Cell x0;
Cell x1;
Cell r0;
Cell r1;
{
x0 = (Cell) (&list[0]);
}
{
x1 = (Cell) elements;
}
{
Cell n;
n = x1;
x1 = n - 1;
}
{
Cell n;
n = x1;
x1 = n * sizeof(Cell);
}
{
Cells2 _C_locret;
_C_locret = mybounds(x1, x0);
x0 = _C_locret.cell1;
x1 = _C_locret.cell0;
}
{
Cell bound, index;
index = x1;
bound = x0;
r0 = bound;
r1 = index;
}
label0:
{
Cell n = r1;
x0 = n;
}
{
Cell *a;
a = (Cell *) x0;
x0 = a[1];
x1 = a[0];
}
{
Cell n1, n2, n;
n1 = x1;
n2 = x0;
n = FLAG(n2 > n1);
x0 = n;
}
{
Cell n;
n = x0;
if (n != 0)
{
fputs("\nbubble-sort: not sorted\n", stdout);
exit(n);
}
}
{
x0 = sizeof(Cell);
}
{
Cell step, index, bound;
index = r1;
bound = r0;
step = x0;
index += step;
if ((step > 0 && index < bound) ||
(step <= 0 && index >= bound))
{
r0 = bound;
r1 = index;
goto label0;
}
}
{
}
{
return;
}
}
Cell bubble(void)
{
Cell _c_result;
Cell x0;
Cell x1;
Cell x2;
Cell x3;
Cell r0;
Cell r1;
Cell r2;
Cell r3;
{
fputs("bubbling...", stdout);
fflush(stdout);
}
{
printf("\n");
}
{
x0 = 1;
}
{
x1 = (Cell) elements;
}
{
x2 = 1;
}
{
Cell bound, index;
index = x2;
bound = x1;
r0 = bound;
r1 = index;
}
label0:
{
x1 = (Cell) (&list[0]);
}
{
x2 = (Cell) elements;
}
{
Cell n = r1;
x3 = n;
}
{
Cell n1, n2, n;
n1 = x3;
n2 = x2;
n = n2 - n1;
x2 = n;
}
{
Cell n;
n = x2;
x2 = n * sizeof(Cell);
}
{
Cells2 _C_locret;
_C_locret = mybounds(x2, x1);
x1 = _C_locret.cell1;
x2 = _C_locret.cell0;
}
{
Cell bound, index;
index = x2;
bound = x1;
r2 = bound;
r3 = index;
}
label1:
{
Cell n = r3;
x1 = n;
}
{
Cell *a;
a = (Cell *) x1;
x1 = a[1];
x2 = a[0];
}
{
Cell n1, n2, n;
n1 = x2;
n2 = x1;
n = FLAG(n2 > n1);
x1 = n;
}
if (!x1) goto label2;
{
Cell n = r3;
x1 = n;
}
{
Cell *a;
a = (Cell *) x1;
x1 = a[1];
x2 = a[0];
}
{
Cell n1, n2;
n1 = x2;
n2 = x1;
x1 = n1;
x2 = n2;
}
{
Cell n = r3;
x3 = n;
}
{
Cell *a, n1, n2;
a = (Cell *) x3;
n1 = x2;
n2 = x1;
a[0] = n1;
a[1] = n2;
}
label2:
{
x1 = sizeof(Cell);
}
{
Cell step, index, bound;
index = r3;
bound = r2;
step = x1;
index += step;
if ((step > 0 && index < bound) ||
(step <= 0 && index >= bound))
{
r2 = bound;
r3 = index;
goto label1;
}
}
{
}
{
Cell index, bound;
index = r1;
bound = r0;
index++;
if (index != bound)
{
r0 = bound;
r1 = index;
goto label0;
}
}
{
}
{
_c_result = x0;
return (_c_result);
}
}
Cell bubble_sort(void)
{
Cell _c_result;
Cell x0;
{
initiate_seed();
}
{
initiate_list();
}
{
Cell _C_locret;
_C_locret = bubble();
x0 = _C_locret;
}
{
verify_list();
}
{
_c_result = x0;
return (_c_result);
}
}
Cell bubble_with_flag(void)
{
Cell _c_result;
Cell x0;
Cell x1;
Cell x2;
Cell x3;
Cell x4;
Cell r0;
Cell r1;
Cell r2;
Cell r3;
{
x0 = 1;
}
{
x1 = (Cell) elements;
}
{
x2 = 1;
}
{
Cell bound, index;
index = x2;
bound = x1;
r0 = bound;
r1 = index;
}
label0:
{
x1 = -1;
}
{
x2 = (Cell) (&list[0]);
}
{
x3 = (Cell) elements;
}
{
Cell n = r1;
x4 = n;
}
{
Cell n1, n2, n;
n1 = x4;
n2 = x3;
n = n2 - n1;
x3 = n;
}
{
Cell n;
n = x3;
x3 = n * sizeof(Cell);
}
{
Cells2 _C_locret;
_C_locret = mybounds(x3, x2);
x2 = _C_locret.cell1;
x3 = _C_locret.cell0;
}
{
Cell bound, index;
index = x3;
bound = x2;
r2 = bound;
r3 = index;
}
label1:
{
Cell n = r3;
x2 = n;
}
{
Cell *a;
a = (Cell *) x2;
x2 = a[1];
x3 = a[0];
}
{
Cell n1, n2, n;
n1 = x3;
n2 = x2;
n = FLAG(n2 > n1);
x2 = n;
}
if (!x2) goto label2;
{
Cell n = r3;
x2 = n;
}
{
Cell *a;
a = (Cell *) x2;
x2 = a[1];
x3 = a[0];
}
{
Cell n1, n2;
n1 = x3;
n2 = x2;
x2 = n1;
x3 = n2;
}
{
Cell n = r3;
x4 = n;
}
{
Cell *a, n1, n2;
a = (Cell *) x4;
n1 = x3;
n2 = x2;
a[0] = n1;
a[1] = n2;
}
{
}
{
x1 = 0;
}
label2:
{
x2 = sizeof(Cell);
}
{
Cell step, index, bound;
index = r3;
bound = r2;
step = x2;
index += step;
if ((step > 0 && index < bound) ||
(step <= 0 && index >= bound))
{
r2 = bound;
r3 = index;
goto label1;
}
}
{
}
if (!x1) goto label3;
goto label4;
label3:
{
Cell index, bound;
index = r1;
bound = r0;
index++;
if (index != bound)
{
r0 = bound;
r1 = index;
goto label0;
}
}
label4:
{
}
{
_c_result = x0;
return (_c_result);
}
}
Cell bubble_sort_with_flag(void)
{
Cell _c_result;
Cell x0;
{
initiate_seed();
}
{
initiate_list();
}
{
Cell _C_locret;
_C_locret = bubble_with_flag();
x0 = _C_locret;
}
{
verify_list();
}
{
_c_result = x0;
return (_c_result);
}
}
Cell main(void)
{
Cell _c_result;
Cell x0;
{
Cell _C_locret;
_C_locret = bubble_sort();
x0 = _C_locret;
}
{
_c_result = x0;
return (_c_result);
}
}