Skip to content

Instantly share code, notes, and snippets.

@utgwkk
Created February 12, 2018 02:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save utgwkk/9930eddce00a5536581d9c8f5fd35255 to your computer and use it in GitHub Desktop.
Save utgwkk/9930eddce00a5536581d9c8f5fd35255 to your computer and use it in GitHub Desktop.
fib(38) を求めるCプログラム
#include <stdio.h>
#include <stdlib.h>
extern void start_timer();
extern void stop_timer();
typedef union MLType {
int value;
union MLType (*func)(union MLType, union MLType);
union MLType *tuple;
} _t;
_t _b1(_t, _t);
_t _b0(_t, _t);
_t _b2(_t, _t);
_t _b3(_t, _t);
_t _toplevel(_t, _t);
_t _b1(_t p0, _t p1) {
_t t3;
_t t2;
_t t1;
_t t0;
t0 = p0.tuple[1];
t1 = (_t){t0.value < p1.value};
if (t1.value) goto _iftrue1;
t2 = (_t){p1.value < t0.value};
if (t2.value) goto _iftrue0;
t0 = (_t){1};
goto _endif0;
_iftrue0:;
t0 = (_t){0};
_endif0:;
goto _endif1;
_iftrue1:;
t0 = (_t){0};
_endif1:;
return t0;
}
_t _b0(_t p0, _t p1) {
_t t1;
_t t0;
t0.tuple = malloc(2 * sizeof(_t));
if (t0.tuple == NULL) exit(EXIT_FAILURE);
t0.tuple[0] = (_t){.func = _b1};
t0.tuple[1] = p1;
t0 = t0;
return t0;
}
_t _b2(_t p0, _t p1) {
_t t7;
_t t6;
_t t5;
_t t4;
_t t3;
_t t2;
_t t1;
_t t0;
t0 = (_t){p1.value < 2};
if (t0.value) goto _iftrue2;
t1 = (_t){p1.value + -1};
t2 = p0.tuple[0];
t3 = t2.func(p0, t1);
t4 = (_t){p1.value + -2};
t5 = p0.tuple[0];
t6 = t5.func(p0, t4);
t0 = (_t){t3.value + t6.value};
goto _endif2;
_iftrue2:;
t0 = p1;
_endif2:;
return t0;
}
_t _b3(_t p0, _t p1) {
_t t17;
_t t16;
_t t15;
_t t14;
_t t13;
_t t12;
_t t11;
_t t10;
_t t9;
_t t8;
_t t7;
_t t6;
_t t5;
_t t4;
_t t3;
_t t2;
_t t1;
_t t0;
t0.tuple = malloc(2 * sizeof(_t));
if (t0.tuple == NULL) exit(EXIT_FAILURE);
t0.tuple[0] = (_t){0};
t0.tuple[1] = (_t){1};
t1 = t0;
t2.tuple = malloc(2 * sizeof(_t));
if (t2.tuple == NULL) exit(EXIT_FAILURE);
t2.tuple[0] = t1;
t2.tuple[1] = p1;
t3 = t2;
_loop0:;
t4 = t3.tuple[0];
t5 = t4.tuple[0];
t6 = t3.tuple[0];
t7 = t6.tuple[1];
t8 = t3.tuple[1];
t9 = (_t){t8.value < 1};
if (t9.value) goto _iftrue4;
t10 = (_t){t8.value < 2};
if (t10.value) goto _iftrue3;
t11 = (_t){t5.value + t7.value};
t12.tuple = malloc(2 * sizeof(_t));
if (t12.tuple == NULL) exit(EXIT_FAILURE);
t12.tuple[0] = t7;
t12.tuple[1] = t11;
t13 = t12;
t14 = (_t){t8.value + -1};
t15.tuple = malloc(2 * sizeof(_t));
if (t15.tuple == NULL) exit(EXIT_FAILURE);
t15.tuple[0] = t13;
t15.tuple[1] = t14;
t16 = t15;
t3 = t16;
goto _loop0;
goto _endif3;
_iftrue3:;
t0 = t7;
_endif3:;
goto _endif4;
_iftrue4:;
t0 = t5;
_endif4:;
return t0;
}
_t _toplevel(_t p0, _t p1) {
_t t12;
_t t11;
_t t10;
_t t9;
_t t8;
_t t7;
_t t6;
_t t5;
_t t4;
_t t3;
_t t2;
_t t1;
_t t0;
t0.tuple = malloc(1 * sizeof(_t));
if (t0.tuple == NULL) exit(EXIT_FAILURE);
t0.tuple[0] = (_t){.func = _b0};
t1 = t0;
t2.tuple = malloc(1 * sizeof(_t));
if (t2.tuple == NULL) exit(EXIT_FAILURE);
t2.tuple[0] = (_t){.func = _b2};
t3.tuple = malloc(1 * sizeof(_t));
if (t3.tuple == NULL) exit(EXIT_FAILURE);
t3.tuple[0] = (_t){.func = _b3};
t4 = t3;
t5 = t2.tuple[0];
t6 = t5.func(t2, (_t){38});
t7 = t1.tuple[0];
t8 = t7.func(t1, t6);
t9 = t4.tuple[0];
t10 = t9.func(t4, (_t){38});
t11 = t8.tuple[0];
t0 = t11.func(t8, t10);
return t0;
}
int main (void) {
start_timer();
printf("%d\n", _toplevel((_t){0}, (_t){0}).value);
stop_timer();
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment