// File: /workspace/github_c_makefile_star2_O2/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 0xb907(%rip), %rax      # 0x1367b
movq %rsp, %rdi
movq %rax, (%rdi)
leaq 0x12617(%rip), %rax     # 0x1a398
movq (%rax), %rax
movq 0x50(%rax), %rax
movl 0x8(%rax), %ecx
movl %ecx, 0x8(%rdi)
movl $0x68b, 0xc(%rdi)       # imm = 0x68B
leaq 0xdd48(%rip), %rcx      # 0x15ae4
movq %rcx, 0x10(%rdi)
leaq 0x12399(%rip), %rcx     # 0x1a140
movq %rcx, 0x18(%rdi)
movq %rax, 0x20(%rdi)
callq 0x12bb9
callq 0x887c
leaq 0xc198(%rip), %rdi      # 0x13f58
callq 0x20a0
leaq 0xd124(%rip), %rbx      # 0x14ef0
movq %rbx, %rdi
movq %rbx, %rsi
callq 0x83ca
leaq 0xd3f8(%rip), %rdi      # 0x151d6
movq %rdi, %rsi
callq 0x83ca
leaq 0xd458(%rip), %r14      # 0x15245
movq %r14, %rdi
movq %r14, %rsi
callq 0x83ca
leaq 0xd47c(%rip), %r15      # 0x1527b
movq %r15, %rdi
movq %r15, %rsi
callq 0x83ca
leaq 0xd2b5(%rip), %rbp      # 0x150c6
movq %rbp, %rdi
movq %rbp, %rsi
callq 0x83ca
leaq 0xd9e5(%rip), %rsi      # 0x15808
movq %rbp, %rdi
callq 0x83ca
leaq 0xb855(%rip), %rdi      # 0x13687
movq %rbx, %rsi
callq 0x83ca
leaq 0xb852(%rip), %rdi      # 0x13693
movq %r14, %rsi
callq 0x83ca
leaq 0xb852(%rip), %rdi      # 0x136a2
movq %rbp, %rsi
callq 0x83ca
leaq 0xb850(%rip), %rdi      # 0x136af
leaq 0xd7a9(%rip), %rsi      # 0x1560f
callq 0x83ca
leaq 0xb84b(%rip), %rdi      # 0x136bd
movq %r15, %rsi
callq 0x83ca
leaq 0xb849(%rip), %rdi      # 0x136ca
movq %r14, %rsi
callq 0x83ca
leaq 0xb845(%rip), %rdi      # 0x136d5
movq %r14, %rsi
callq 0x83ca
leaq 0xb84c(%rip), %rdi      # 0x136eb
movq %r15, %rsi
callq 0x83ca
leaq 0xb84b(%rip), %rdi      # 0x136f9
movq %r14, %rsi
callq 0x83ca
leaq 0xb848(%rip), %rdi      # 0x13705
movq %r15, %rsi
callq 0x83ca
leaq 0xb850(%rip), %rdi      # 0x1371c
leaq 0xd1ca(%rip), %rbx      # 0x1509d
movq %rbx, %rsi
callq 0x83ca
leaq 0xb850(%rip), %rdi      # 0x13732
movq %rbp, %rsi
callq 0x83ca
leaq 0xb856(%rip), %rdi      # 0x13747
movq %rbx, %rsi
callq 0x83ca
leaq 0xb85f(%rip), %rdi      # 0x1375f
leaq 0xd72e(%rip), %rsi      # 0x15635
callq 0x83ca
leaq 0xb863(%rip), %rdi      # 0x13776
leaq 0xda84(%rip), %r12      # 0x1599e
movq %r12, %rsi
callq 0x83ca
leaq 0xb85c(%rip), %rdi      # 0x13785
leaq 0xb870(%rip), %r13      # 0x137a0
movq %r13, %rsi
callq 0x83ca
leaq 0xb867(%rip), %rdi      # 0x137a6
movq %r13, %rsi
callq 0x83ca
leaq 0xb872(%rip), %rdi      # 0x137c0
leaq 0xb88f(%rip), %rsi      # 0x137e4
callq 0x83ca
leaq 0xb889(%rip), %rdi      # 0x137ea
leaq 0xcf88(%rip), %rsi      # 0x14ef0
callq 0x83ca
leaq 0xb898(%rip), %rdi      # 0x1380c
leaq 0xd960(%rip), %rbx      # 0x158db
movq %rbx, %rsi
callq 0x83ca
leaq 0xb8a3(%rip), %rdi      # 0x1382d
movq %rbp, %rsi
callq 0x83ca
leaq 0xb89f(%rip), %rdi      # 0x13838
movq %rbp, %rsi
callq 0x83ca
leaq 0xcfa2(%rip), %rdi      # 0x14f4a
movq %rbp, %rsi
callq 0x83ca
leaq 0xb88b(%rip), %rdi      # 0x13842
movq %r12, %rsi
movq %r12, %rbp
callq 0x83ca
leaq 0xb882(%rip), %rdi      # 0x1384b
movq %r13, %rsi
callq 0x83ca
leaq 0xb87e(%rip), %rdi      # 0x13856
leaq 0xb898(%rip), %r13      # 0x13877
movq %r13, %rsi
callq 0x83ca
leaq 0xb891(%rip), %rdi      # 0x1387f
leaq 0xd813(%rip), %rsi      # 0x15808
callq 0x83ca
leaq 0xb884(%rip), %rdi      # 0x13885
movq %rbx, %rsi
callq 0x83ca
leaq 0xb87d(%rip), %rdi      # 0x1388d
leaq 0xb880(%rip), %rsi      # 0x13897
callq 0x83ca
leaq 0xb87a(%rip), %rdi      # 0x1389d
movq %r13, %rsi
callq 0x83ca
leaq 0xb88b(%rip), %rdi      # 0x138bd
movq %r14, %rsi
callq 0x83ca
leaq 0xb889(%rip), %rdi      # 0x138ca
movq %r15, %rsi
callq 0x83ca
leaq 0xb887(%rip), %rdi      # 0x138d7
movq %r14, %rsi
callq 0x83ca
leaq 0xb888(%rip), %rdi      # 0x138e7
movq %r15, %rsi
callq 0x83ca
leaq 0xb887(%rip), %rdi      # 0x138f5
leaq 0xb89c(%rip), %rsi      # 0x13911
callq 0x83ca
leaq 0xb894(%rip), %rdi      # 0x13915
leaq 0xb8a9(%rip), %rsi      # 0x13931
callq 0x83ca
leaq 0xb8a0(%rip), %rdi      # 0x13934
movq %r14, %rsi
callq 0x83ca
leaq 0xb89d(%rip), %rdi      # 0x13940
movq %r14, %rsi
callq 0x83ca
leaq 0xb89a(%rip), %rdi      # 0x1394c
movq %r14, %rsi
callq 0x83ca
leaq 0xb898(%rip), %rdi      # 0x13959
movq %r15, %rsi
callq 0x83ca
leaq 0xb898(%rip), %rdi      # 0x13968
movq %r15, %rsi
callq 0x83ca
leaq 0xb896(%rip), %rdi      # 0x13975
movq %r14, %rsi
callq 0x83ca
leaq 0xb891(%rip), %rdi      # 0x1397f
movq %r15, %rsi
callq 0x83ca
leaq 0xb88c(%rip), %rdi      # 0x13989
movq %r15, %rsi
callq 0x83ca
leaq 0xb888(%rip), %rdi      # 0x13994
movq %r15, %rsi
callq 0x83ca
leaq 0xb886(%rip), %rdi      # 0x139a1
movq %r15, %rsi
callq 0x83ca
leaq 0xb882(%rip), %rdi      # 0x139ac
leaq 0xd065(%rip), %rsi      # 0x15196
callq 0x83ca
leaq 0xb879(%rip), %rdi      # 0x139b6
leaq 0xb8dd(%rip), %r13      # 0x13a21
movq %r13, %rsi
callq 0x83ca
leaq 0xb86f(%rip), %rdi      # 0x139c2
leaq 0xcd96(%rip), %r12      # 0x14ef0
movq %r12, %rsi
callq 0x83ca
leaq 0xb866(%rip), %rdi      # 0x139cf
leaq 0xb868(%rip), %rbx      # 0x139d8
movq %rbx, %rsi
callq 0x83ca
leaq 0xb85c(%rip), %rdi      # 0x139db
movq %r15, %rsi
callq 0x83ca
leaq 0xb860(%rip), %rdi      # 0x139ee
movq %r14, %rsi
callq 0x83ca
leaq 0xb864(%rip), %rdi      # 0x13a01
leaq 0xd032(%rip), %rsi      # 0x151d6
callq 0x83ca
leaq 0xb85f(%rip), %rdi      # 0x13a0f
leaq 0xb869(%rip), %rsi      # 0x13a20
callq 0x83ca
leaq 0xb860(%rip), %rdi      # 0x13a23
movq %r12, %rsi
callq 0x83ca
leaq 0xb85f(%rip), %rdi      # 0x13a31
movq %rbx, %rsi
callq 0x83ca
leaq 0xb85d(%rip), %rdi      # 0x13a3e
movq %r14, %rsi
callq 0x83ca
leaq 0xb865(%rip), %rdi      # 0x13a55
movq %r15, %rsi
callq 0x83ca
leaq 0xb86d(%rip), %rdi      # 0x13a6c
movq %r12, %rsi
callq 0x83ca
leaq 0xb87d(%rip), %rdi      # 0x13a8b
leaq 0xb8a4(%rip), %rsi      # 0x13ab9
callq 0x83ca
leaq 0xb8a5(%rip), %rdi      # 0x13ac6
leaq 0xb8c9(%rip), %rsi      # 0x13af1
callq 0x83ca
movq 0x121b4(%rip), %rdi     # 0x1a3e8
movq 0x11f6d(%rip), %rdx     # 0x1a1a8
leaq 0xb8b9(%rip), %rsi      # 0x13afb
callq 0x7b4c
leaq 0xb8e9(%rip), %rdi      # 0x13b37
leaq 0xb8f8(%rip), %rsi      # 0x13b4d
callq 0x83ca
leaq 0xb8f3(%rip), %rdi      # 0x13b54
movq %rbp, %rsi
callq 0x83ca
leaq 0xb906(%rip), %rdi      # 0x13b76
movq %r15, %rsi
callq 0x83ca
leaq 0xb91f(%rip), %rdi      # 0x13b9e
movq %r14, %rsi
callq 0x83ca
leaq 0xb939(%rip), %rdi      # 0x13bc7
leaq 0xb96c(%rip), %rsi      # 0x13c01
callq 0x83ca
leaq 0xb96e(%rip), %rdi      # 0x13c0f
leaq 0xb997(%rip), %rsi      # 0x13c3f
callq 0x83ca
movq 0x12134(%rip), %rdi     # 0x1a3e8
movq 0x11eed(%rip), %rdx     # 0x1a1a8
leaq 0xb97f(%rip), %rsi      # 0x13c41
callq 0x7b4c
leaq 0xb9bf(%rip), %rdi      # 0x13c8d
movq %r13, %rsi
callq 0x83ca
leaq 0xb9b9(%rip), %rdi      # 0x13c96
movq %r12, %rsi
callq 0x83ca
leaq 0xb9b5(%rip), %rdi      # 0x13ca1
movq %r14, %rsi
callq 0x83ca
movq 0x120ed(%rip), %rdi     # 0x1a3e8
movq 0x11ea6(%rip), %rdx     # 0x1a1a8
leaq 0xb9b8(%rip), %rsi      # 0x13cc1
callq 0x7b4c
leaq 0xb9da(%rip), %rdi      # 0x13cef
movq %r15, %rsi
callq 0x83ca
leaq 0xb9d6(%rip), %rdi      # 0x13cfa
movq %r14, %rsi
callq 0x83ca
movq 0x120b5(%rip), %rdi     # 0x1a3e8
movq 0x11e6e(%rip), %rdx     # 0x1a1a8
leaq 0xb9c5(%rip), %rsi      # 0x13d06
callq 0x7b4c
leaq 0xb9e9(%rip), %rdi      # 0x13d36
movq %r14, %rsi
callq 0x83ca
leaq 0xb9e6(%rip), %rdi      # 0x13d42
movq %r15, %rsi
callq 0x83ca
leaq 0xb9e4(%rip), %rdi      # 0x13d4f
movq %r14, %rsi
callq 0x83ca
movq 0x1206e(%rip), %rdi     # 0x1a3e8
movq 0x11e27(%rip), %rdx     # 0x1a1a8
leaq 0xb9dd(%rip), %rsi      # 0x13d65
callq 0x7b4c
leaq 0xba0d(%rip), %rdi      # 0x13da1
leaq 0xba14(%rip), %rsi      # 0x13daf
callq 0x83ca
movq 0x12041(%rip), %rdi     # 0x1a3e8
callq 0xb186
movq %rsp, %rdi
movl $0x6fd, 0xc(%rdi)       # imm = 0x6FD
callq 0x12d32
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq