// File: /workspace/github_c_makefile_star2_O1/dalnefre[P]kernel_abe/reduce.c
// Function: test_reduce
void
test_reduce()
{
	DBUG_ENTER("test_reduce");
	init_reduce();
	TRACE(printf("--test_reduce--\n"));

	assert_reduce("0", "0");
	assert_reduce("1", "1");
	assert_reduce("TRUE", "TRUE");
	assert_reduce("FALSE", "FALSE");
	assert_reduce("()", "()");
	assert_reduce("()", "NIL");
	
	assert_reduce("(literal 0)", "0");
	assert_reduce("(literal TRUE)", "TRUE");
	assert_reduce("(literal ())", "()");
	assert_reduce("(literal (x))", "(x)");

	assert_reduce("(list? TRUE)", "FALSE");
	assert_reduce("(list? ())", "TRUE");
	assert_reduce("(list? (literal (x)))", "TRUE");

	assert_reduce("(empty? TRUE)", "FALSE");
	assert_reduce("(empty? ())", "TRUE");
	assert_reduce("(empty? (literal (x)))", "FALSE");

	assert_reduce("(first (literal (x)))", "x");
	assert_reduce("(rest (literal (x)))", "()");
	assert_reduce("(first (literal (x y)))", "x");
	assert_reduce("(rest (literal (x y)))", "(y)");
	assert_reduce("(prepend 0 ())", "(0)");
	assert_reduce("(prepend 0 (prepend 1 ()))", "(0 1)");
	assert_reduce("(prepend 0 (literal (1)))", "(0 1)");
	assert_reduce("(prepend (literal x) (literal (y)))", "(x y)");
	assert_reduce("(first (prepend 0 (literal (1))))", "0");
	assert_reduce("(rest (prepend 0 (literal (1))))", "(1)");
	assert_reduce("(first ())", "()");
	assert_reduce("(rest ())", "()");
	assert_reduce("(list)", "()");
	assert_reduce("(list 0)", "(0)");
	assert_reduce("(list 0 1)", "(0 1)");
	assert_reduce("(list (literal x) (literal (y)))", "(x (y))");

	assert_reduce("(seq)", "NIL");
	assert_reduce("(seq 1)", "(1)");
	assert_reduce("(seq 1 2)", "(1 2)");
	assert_reduce("(seq (literal x) (literal (y)))", "(x (y))");

	assert_reduce("(equal? 0 0)", "TRUE");
	assert_reduce("(equal? 0 1)", "FALSE");
	assert_reduce("(equal? NIL ())", "TRUE");
	assert_reduce("(equal? 0 ())", "FALSE");

	assert_reduce("(if TRUE (literal Yes) (?))", "Yes");
	assert_reduce("(if FALSE (?) (literal No))", "No");

	assert_reduce("(number? 0)", "TRUE");
	assert_reduce("(number? 1)", "TRUE");
	assert_reduce("(number? -1)", "TRUE");
	assert_reduce("(number? TRUE)", "FALSE");
	assert_reduce("(number? ())", "FALSE");

	assert_reduce("(zero? 0)", "TRUE");
	assert_reduce("(zero? 1)", "FALSE");
	assert_reduce("(zero? -1)", "FALSE");
	assert_reduce("(zero? TRUE)", "FALSE");
	assert_reduce("(zero? ())", "FALSE");

	assert_reduce("(sum 1 1)", "2");
	assert_reduce("(sum 1 2 3)", "6");
	assert_reduce("(sum 1 0 -1)", "0");
	assert_reduce("(sum 41)", "41");
	assert_reduce("(zero? (sum 0 -1))", "FALSE");
	assert_reduce("(zero? (sum 1 -1))", "TRUE");

	assert_reduce("(product 1 1)", "1");
	assert_reduce("(product -1 2 3)", "-6");
	assert_reduce("(product 1 0)", "0");
	assert_reduce("(product 41)", "41");
	assert_reduce("(zero? (product 0 -1))", "TRUE");
	assert_reduce("(zero? (product 1 -1))", "FALSE");
	
	assert_reduce("((template (x) (literal x)) 0)", "0");
	assert_reduce("((template (x y) (literal (y x))) TRUE FALSE)", "(FALSE TRUE)");
	assert_reduce("((template (x y) (literal (y x))) foo bar)", "(bar foo)");
	reduce_line(reduce_cfg, "(define 2tuple (template (x y) (prepend x (prepend y ()))))", a_sink);
	assert_reduce("(2tuple () (sum 1 2))", "(() 3)");
	
	assert_reduce("((function (x) (prepend x ())) 0)", "(0)");
	assert_reduce("((function (x) (if x FALSE TRUE)) TRUE)", "FALSE");
	assert_reduce("((function (x) (if x FALSE TRUE)) FALSE)", "TRUE");	
	assert_reduce("((function (x) (list (literal Hello) x)) (literal World))", "(Hello World)");
	assert_reduce("(((function (x) (function (y) (sum x y))) 3) 4)", "7");
	reduce_line(reduce_cfg, "(define fact (function (n) (if (zero? n) 1 (product n (fact (sum n -1))))))", a_sink);
	assert_reduce("(fact 3)", "6");

	assert_reduce("(reduce 0)", "0");
	assert_reduce("(reduce (literal (equal? 0 0)))", "TRUE");

	reduce_line(reduce_cfg, "(define not (function (x) (if x FALSE TRUE)))", a_sink);
	assert_reduce("(not TRUE)", "FALSE");
	assert_reduce("(not FALSE)", "TRUE");
#if 0
	assert_reduce("(not 0)", "_");		/* error expected */
#endif
	reduce_line(reduce_cfg, "(define symbol? (function (x) (not (list? x))))", a_sink);
	assert_reduce("(symbol? 0)", "TRUE");
	assert_reduce("(symbol? ())", "FALSE");
	assert_reduce("(symbol? (literal x))", "TRUE");
	reduce_line(reduce_cfg, "(define swap2 (function (x y) (prepend y (prepend x NIL))))", a_sink);
	assert_reduce("(swap2 0 1 2)", "(1 0)");
	
#if 0
	assert_reduce("(?)", "_");	/* this case produces error messages, but should pass */
#endif
	report_actor_usage(reduce_cfg);
	DBUG_RETURN;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
leaq 0xc4f4(%rip), %rax      # 0x1467b
movq %rsp, %rdi
movq %rax, (%rdi)
leaq 0x131f4(%rip), %rax     # 0x1b388
movq (%rax), %rax
movq 0x50(%rax), %rax
movl 0x8(%rax), %ecx
movl %ecx, 0x8(%rdi)
movl $0x68b, 0xc(%rdi)       # imm = 0x68B
leaq 0xe955(%rip), %rcx      # 0x16b04
movq %rcx, 0x10(%rdi)
leaq 0x12f76(%rip), %rcx     # 0x1b130
movq %rcx, 0x18(%rdi)
movq %rax, 0x20(%rdi)
callq 0x13322
callq 0x8cff
leaq 0xcd85(%rip), %rdi      # 0x14f58
callq 0x20a0
leaq 0xdd31(%rip), %rbx      # 0x15f10
movq %rbx, %rdi
movq %rbx, %rsi
callq 0x87dd
leaq 0xe005(%rip), %rdi      # 0x161f6
movq %rdi, %rsi
callq 0x87dd
leaq 0xe065(%rip), %r14      # 0x16265
movq %r14, %rdi
movq %r14, %rsi
callq 0x87dd
leaq 0xe089(%rip), %r15      # 0x1629b
movq %r15, %rdi
movq %r15, %rsi
callq 0x87dd
leaq 0xdec2(%rip), %rbp      # 0x160e6
movq %rbp, %rdi
movq %rbp, %rsi
callq 0x87dd
leaq 0xe5f2(%rip), %rsi      # 0x16828
movq %rbp, %rdi
callq 0x87dd
leaq 0xc442(%rip), %rdi      # 0x14687
movq %rbx, %rsi
callq 0x87dd
leaq 0xc43f(%rip), %rdi      # 0x14693
movq %r14, %rsi
callq 0x87dd
leaq 0xc43f(%rip), %rdi      # 0x146a2
movq %rbp, %rsi
callq 0x87dd
leaq 0xc43d(%rip), %rdi      # 0x146af
leaq 0xe3b6(%rip), %rsi      # 0x1662f
callq 0x87dd
leaq 0xc438(%rip), %rdi      # 0x146bd
movq %r15, %rsi
callq 0x87dd
leaq 0xc436(%rip), %rdi      # 0x146ca
movq %r14, %rsi
callq 0x87dd
leaq 0xc432(%rip), %rdi      # 0x146d5
movq %r14, %rsi
callq 0x87dd
leaq 0xc439(%rip), %rdi      # 0x146eb
movq %r15, %rsi
callq 0x87dd
leaq 0xc438(%rip), %rdi      # 0x146f9
movq %r14, %rsi
callq 0x87dd
leaq 0xc435(%rip), %rdi      # 0x14705
movq %r15, %rsi
callq 0x87dd
leaq 0xc43d(%rip), %rdi      # 0x1471c
leaq 0xddd7(%rip), %rbx      # 0x160bd
movq %rbx, %rsi
callq 0x87dd
leaq 0xc43d(%rip), %rdi      # 0x14732
movq %rbp, %rsi
callq 0x87dd
leaq 0xc443(%rip), %rdi      # 0x14747
movq %rbx, %rsi
callq 0x87dd
leaq 0xc44c(%rip), %rdi      # 0x1475f
leaq 0xe33b(%rip), %rsi      # 0x16655
callq 0x87dd
leaq 0xc450(%rip), %rdi      # 0x14776
leaq 0xe691(%rip), %r12      # 0x169be
movq %r12, %rsi
callq 0x87dd
leaq 0xc449(%rip), %rdi      # 0x14785
leaq 0xc45d(%rip), %r13      # 0x147a0
movq %r13, %rsi
callq 0x87dd
leaq 0xc454(%rip), %rdi      # 0x147a6
movq %r13, %rsi
callq 0x87dd
leaq 0xc45f(%rip), %rdi      # 0x147c0
leaq 0xc47c(%rip), %rsi      # 0x147e4
callq 0x87dd
leaq 0xc476(%rip), %rdi      # 0x147ea
leaq 0xdb95(%rip), %rsi      # 0x15f10
callq 0x87dd
leaq 0xc485(%rip), %rdi      # 0x1480c
leaq 0xe56d(%rip), %rbx      # 0x168fb
movq %rbx, %rsi
callq 0x87dd
leaq 0xc490(%rip), %rdi      # 0x1482d
movq %rbp, %rsi
callq 0x87dd
leaq 0xc48c(%rip), %rdi      # 0x14838
movq %rbp, %rsi
callq 0x87dd
leaq 0xdbaf(%rip), %rdi      # 0x15f6a
movq %rbp, %rsi
callq 0x87dd
leaq 0xc478(%rip), %rdi      # 0x14842
movq %r12, %rsi
movq %r12, %rbp
callq 0x87dd
leaq 0xc46f(%rip), %rdi      # 0x1484b
movq %r13, %rsi
callq 0x87dd
leaq 0xc46b(%rip), %rdi      # 0x14856
leaq 0xc485(%rip), %r13      # 0x14877
movq %r13, %rsi
callq 0x87dd
leaq 0xc47e(%rip), %rdi      # 0x1487f
leaq 0xe420(%rip), %rsi      # 0x16828
callq 0x87dd
leaq 0xc471(%rip), %rdi      # 0x14885
movq %rbx, %rsi
callq 0x87dd
leaq 0xc46a(%rip), %rdi      # 0x1488d
leaq 0xc46d(%rip), %rsi      # 0x14897
callq 0x87dd
leaq 0xc467(%rip), %rdi      # 0x1489d
movq %r13, %rsi
callq 0x87dd
leaq 0xc478(%rip), %rdi      # 0x148bd
movq %r14, %rsi
callq 0x87dd
leaq 0xc476(%rip), %rdi      # 0x148ca
movq %r15, %rsi
callq 0x87dd
leaq 0xc474(%rip), %rdi      # 0x148d7
movq %r14, %rsi
callq 0x87dd
leaq 0xc475(%rip), %rdi      # 0x148e7
movq %r15, %rsi
callq 0x87dd
leaq 0xc474(%rip), %rdi      # 0x148f5
leaq 0xc489(%rip), %rsi      # 0x14911
callq 0x87dd
leaq 0xc481(%rip), %rdi      # 0x14915
leaq 0xc496(%rip), %rsi      # 0x14931
callq 0x87dd
leaq 0xc48d(%rip), %rdi      # 0x14934
movq %r14, %rsi
callq 0x87dd
leaq 0xc48a(%rip), %rdi      # 0x14940
movq %r14, %rsi
callq 0x87dd
leaq 0xc487(%rip), %rdi      # 0x1494c
movq %r14, %rsi
callq 0x87dd
leaq 0xc485(%rip), %rdi      # 0x14959
movq %r15, %rsi
callq 0x87dd
leaq 0xc485(%rip), %rdi      # 0x14968
movq %r15, %rsi
callq 0x87dd
leaq 0xc483(%rip), %rdi      # 0x14975
movq %r14, %rsi
callq 0x87dd
leaq 0xc47e(%rip), %rdi      # 0x1497f
movq %r15, %rsi
callq 0x87dd
leaq 0xc479(%rip), %rdi      # 0x14989
movq %r15, %rsi
callq 0x87dd
leaq 0xc475(%rip), %rdi      # 0x14994
movq %r15, %rsi
callq 0x87dd
leaq 0xc473(%rip), %rdi      # 0x149a1
movq %r15, %rsi
callq 0x87dd
leaq 0xc46f(%rip), %rdi      # 0x149ac
leaq 0xdc72(%rip), %rsi      # 0x161b6
callq 0x87dd
leaq 0xc466(%rip), %rdi      # 0x149b6
leaq 0xc4ca(%rip), %r13      # 0x14a21
movq %r13, %rsi
callq 0x87dd
leaq 0xc45c(%rip), %rdi      # 0x149c2
leaq 0xd9a3(%rip), %r12      # 0x15f10
movq %r12, %rsi
callq 0x87dd
leaq 0xc453(%rip), %rdi      # 0x149cf
leaq 0xc455(%rip), %rbx      # 0x149d8
movq %rbx, %rsi
callq 0x87dd
leaq 0xc449(%rip), %rdi      # 0x149db
movq %r15, %rsi
callq 0x87dd
leaq 0xc44d(%rip), %rdi      # 0x149ee
movq %r14, %rsi
callq 0x87dd
leaq 0xc451(%rip), %rdi      # 0x14a01
leaq 0xdc3f(%rip), %rsi      # 0x161f6
callq 0x87dd
leaq 0xc44c(%rip), %rdi      # 0x14a0f
leaq 0xc456(%rip), %rsi      # 0x14a20
callq 0x87dd
leaq 0xc44d(%rip), %rdi      # 0x14a23
movq %r12, %rsi
callq 0x87dd
leaq 0xc44c(%rip), %rdi      # 0x14a31
movq %rbx, %rsi
callq 0x87dd
leaq 0xc44a(%rip), %rdi      # 0x14a3e
movq %r14, %rsi
callq 0x87dd
leaq 0xc452(%rip), %rdi      # 0x14a55
movq %r15, %rsi
callq 0x87dd
leaq 0xc45a(%rip), %rdi      # 0x14a6c
movq %r12, %rsi
callq 0x87dd
leaq 0xc46a(%rip), %rdi      # 0x14a8b
leaq 0xc491(%rip), %rsi      # 0x14ab9
callq 0x87dd
leaq 0xc492(%rip), %rdi      # 0x14ac6
leaq 0xc4b6(%rip), %rsi      # 0x14af1
callq 0x87dd
movq 0x12d91(%rip), %rdi     # 0x1b3d8
movq 0x12b4a(%rip), %rdx     # 0x1b198
leaq 0xc4a6(%rip), %rsi      # 0x14afb
callq 0x7f5d
leaq 0xc4d6(%rip), %rdi      # 0x14b37
leaq 0xc4e5(%rip), %rsi      # 0x14b4d
callq 0x87dd
leaq 0xc4e0(%rip), %rdi      # 0x14b54
movq %rbp, %rsi
callq 0x87dd
leaq 0xc4f3(%rip), %rdi      # 0x14b76
movq %r15, %rsi
callq 0x87dd
leaq 0xc50c(%rip), %rdi      # 0x14b9e
movq %r14, %rsi
callq 0x87dd
leaq 0xc526(%rip), %rdi      # 0x14bc7
leaq 0xc559(%rip), %rsi      # 0x14c01
callq 0x87dd
leaq 0xc55b(%rip), %rdi      # 0x14c0f
leaq 0xc584(%rip), %rsi      # 0x14c3f
callq 0x87dd
movq 0x12d11(%rip), %rdi     # 0x1b3d8
movq 0x12aca(%rip), %rdx     # 0x1b198
leaq 0xc56c(%rip), %rsi      # 0x14c41
callq 0x7f5d
leaq 0xc5ac(%rip), %rdi      # 0x14c8d
movq %r13, %rsi
callq 0x87dd
leaq 0xc5a6(%rip), %rdi      # 0x14c96
movq %r12, %rsi
callq 0x87dd
leaq 0xc5a2(%rip), %rdi      # 0x14ca1
movq %r14, %rsi
callq 0x87dd
movq 0x12cca(%rip), %rdi     # 0x1b3d8
movq 0x12a83(%rip), %rdx     # 0x1b198
leaq 0xc5a5(%rip), %rsi      # 0x14cc1
callq 0x7f5d
leaq 0xc5c7(%rip), %rdi      # 0x14cef
movq %r15, %rsi
callq 0x87dd
leaq 0xc5c3(%rip), %rdi      # 0x14cfa
movq %r14, %rsi
callq 0x87dd
movq 0x12c92(%rip), %rdi     # 0x1b3d8
movq 0x12a4b(%rip), %rdx     # 0x1b198
leaq 0xc5b2(%rip), %rsi      # 0x14d06
callq 0x7f5d
leaq 0xc5d6(%rip), %rdi      # 0x14d36
movq %r14, %rsi
callq 0x87dd
leaq 0xc5d3(%rip), %rdi      # 0x14d42
movq %r15, %rsi
callq 0x87dd
leaq 0xc5d1(%rip), %rdi      # 0x14d4f
movq %r14, %rsi
callq 0x87dd
movq 0x12c4b(%rip), %rdi     # 0x1b3d8
movq 0x12a04(%rip), %rdx     # 0x1b198
leaq 0xc5ca(%rip), %rsi      # 0x14d65
callq 0x7f5d
leaq 0xc5fa(%rip), %rdi      # 0x14da1
leaq 0xc601(%rip), %rsi      # 0x14daf
callq 0x87dd
movq 0x12c1e(%rip), %rdi     # 0x1b3d8
callq 0xb4eb
movq %rsp, %rdi
movl $0x6fd, 0xc(%rdi)       # imm = 0x6FD
callq 0x134a7
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq