// File: /workspace/github_c_makefile_star2_O3/hughbarney[P]zepl/lisp.c
// Function: evalExpr
Object *evalExpr(Object ** object, Object ** env, GC_PARAM)
{
	GC_TRACE(gcObject, *object);
	GC_TRACE(gcEnv, *env);

	GC_TRACE(gcFunc, nil);
	GC_TRACE(gcArgs, nil);
	GC_TRACE(gcBody, nil);

	for (;;) {
		if ((*gcObject)->type == TYPE_SYMBOL)
			return envLookup(*gcObject, *gcEnv);
		if ((*gcObject)->type != TYPE_CONS)
			return *gcObject;

		*gcFunc = (*gcObject)->car;
		*gcArgs = (*gcObject)->cdr;

		*gcFunc = evalExpr(gcFunc, gcEnv, GC_ROOTS);
		*gcBody = nil;

		if ((*gcFunc)->type == TYPE_LAMBDA) {
			*gcBody = (*gcFunc)->body;
			*gcArgs = evalList(gcArgs, gcEnv, GC_ROOTS);
			*gcEnv = newEnv(gcFunc, gcArgs, GC_ROOTS);
			*gcObject = evalProgn(gcBody, gcEnv, GC_ROOTS);
		} else if ((*gcFunc)->type == TYPE_MACRO) {
			*gcObject = expandMacroTo(gcFunc, gcArgs, gcObject, GC_ROOTS);
		} else if ((*gcFunc)->type == TYPE_PRIMITIVE) {
			Primitive *primitive = &primitives[(*gcFunc)->primitive];
			int nArgs = 0;

			for (Object * args = *gcArgs; args != nil; args = args->cdr, nArgs++)
				if (args->type != TYPE_CONS)
					exceptionWithObject(args, "is not a list");

			if (nArgs < primitive->nMinArgs)
				exceptionWithObject(*gcFunc, "expects at least %d arguments", primitive->nMinArgs);
			if (nArgs > primitive->nMaxArgs && primitive->nMaxArgs >= 0)
				exceptionWithObject(*gcFunc, "expects at most %d arguments", primitive->nMaxArgs);
			if (primitive->nMaxArgs < 0 && nArgs % -primitive->nMaxArgs)
				exceptionWithObject(*gcFunc, "expects a multiple of %d arguments", -primitive->nMaxArgs);

			switch ((*gcFunc)->primitive) {
			case PRIMITIVE_QUOTE:
				return (*gcArgs)->car;
			case PRIMITIVE_SETQ:
				return evalSetq(gcArgs, gcEnv, GC_ROOTS);
			case PRIMITIVE_PROGN:
				*gcObject = evalProgn(gcArgs, gcEnv, GC_ROOTS);
				break;
			case PRIMITIVE_IF:
				*gcObject = evalIf(gcArgs, gcEnv, GC_ROOTS);
				break;
			case PRIMITIVE_COND:
				*gcObject = evalCond(gcArgs, gcEnv, GC_ROOTS);
				break;
			case PRIMITIVE_LAMBDA:
				return evalLambda(gcArgs, gcEnv, GC_ROOTS);
			case PRIMITIVE_MACRO:
				return evalMacro(gcArgs, gcEnv, GC_ROOTS);
			default:
				*gcArgs = evalList(gcArgs, gcEnv, GC_ROOTS);
				return primitive->eval(gcArgs, GC_ROOTS);
			}
		} else
			exceptionWithObject(*gcFunc, "is not a function");
	}
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x118, %rsp            # imm = 0x118
movl $0x3, %ecx
leaq 0xb0(%rsp), %r9
movl %ecx, -0x10(%r9)
xorl %r8d, %r8d
movq %r8, -0x8(%r9)
movq (%rdi), %rax
movq %rax, (%r9)
movq %rdx, 0x8(%r9)
leaq 0x88(%rsp), %rbx
movl %ecx, -0x10(%rbx)
movq %r8, -0x8(%rbx)
movq (%rsi), %rdx
movq %rdx, (%rbx)
leaq 0xa0(%rsp), %rdx
movq %rdx, 0x8(%rbx)
leaq 0x60(%rsp), %r12
movl %ecx, -0x10(%r12)
movq %r8, -0x8(%r12)
movq 0x6679(%rip), %rdx      # 0xd208
movq %rdx, (%r12)
leaq 0x78(%rsp), %rsi
movq %rsi, 0x8(%r12)
leaq 0x38(%rsp), %r15
movl %ecx, -0x10(%r15)
movq %r8, -0x8(%r15)
movq %rdx, (%r15)
leaq 0x50(%rsp), %rsi
movq %rsi, 0x8(%r15)
leaq 0x10(%rsp), %rsi
movl %ecx, -0x10(%rsi)
movq %r8, -0x8(%rsi)
movq %rdx, (%rsi)
leaq 0x28(%rsp), %rcx
movq %rcx, 0x8(%rsi)
movq %rsp, %r13
leaq 0x1864(%rip), %r14      # 0x843c
movl (%rax), %ecx
cmpl $0x3, %ecx
jne 0x6d30
movq 0x10(%rax), %rcx
movq %rcx, 0x60(%rsp)
movq 0x18(%rax), %rax
movq %rax, 0x38(%rsp)
movq %r12, %rdi
movq %rbx, %rsi
movq %r13, %rdx
callq 0x6b25
movq %rax, %r8
movq %rax, 0x60(%rsp)
movq 0x65f6(%rip), %rcx      # 0xd208
movq %rcx, 0x10(%rsp)
movl (%rax), %eax
cmpl $0x6, %eax
je 0x6c83
cmpl $0x5, %eax
je 0x6c68
cmpl $0x4, %eax
jne 0x6e51
movq 0x18(%r8), %rax
movq %rax, 0x10(%rsp)
movq %r15, %rdi
movq %rbx, %rsi
movq %r13, %rdx
callq 0x7239
movq %rax, 0x38(%rsp)
movq %r12, %rdi
movq %r15, %rsi
movq %r13, %rdx
callq 0x4cca
movq %rax, 0x88(%rsp)
leaq 0x10(%rsp), %rdi
jmp 0x6cf8
movq %r12, %rdi
movq %r15, %rsi
leaq 0xb0(%rsp), %rdx
movq %r13, %rcx
callq 0x719f
jmp 0x6d03
movslq 0x10(%r8), %rsi
movq 0x38(%rsp), %r9
xorl %eax, %eax
cmpq %rcx, %r9
je 0x6caa
movq %r9, %rdi
cmpl $0x3, (%rdi)
jne 0x6e43
movq 0x18(%rdi), %rdi
incl %eax
cmpq %rcx, %rdi
jne 0x6c96
leaq (%rsi,%rsi,2), %rcx
leaq 0x656b(%rip), %rdx      # 0xd220
leaq (%rdx,%rcx,8), %rbp
movl 0x8(%rbp), %edx
cmpl %edx, %eax
jl 0x6e5d
movl 0xc(%rbp), %ecx
cmpl %eax, %ecx
jb 0x6e69
testl %ecx, %ecx
jns 0x6ce1
negl %ecx
xorl %edx, %edx
divl %ecx
testl %edx, %edx
jne 0x6e72
cmpl $0x6, %esi
ja 0x6e1f
movl %esi, %eax
movslq (%r14,%rax,4), %rax
addq %r14, %rax
jmpq *%rax
movq %r15, %rdi
movq %rbx, %rsi
movq %r13, %rdx
callq 0x6e85
movq %rax, 0xb0(%rsp)
jmp 0x6bd8
movq %r15, %rdi
movq %rbx, %rsi
movq %r13, %rdx
callq 0x6f0d
jmp 0x6d03
movq %r15, %rdi
movq %rbx, %rsi
movq %r13, %rdx
callq 0x6f6a
jmp 0x6d03
cmpl $0x2, %ecx
jne 0x6d45
movq 0x88(%rsp), %rsi
movq %rax, %rdi
callq 0x5793
addq $0x118, %rsp            # imm = 0x118
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl $0x3, %eax
leaq 0x100(%rsp), %rsi
movl %eax, -0x10(%rsi)
xorl %ecx, %ecx
movq %rcx, -0x8(%rsi)
movq 0x10(%r9), %rdx
movq %rdx, (%rsi)
movq %r13, 0x8(%rsi)
leaq 0xd8(%rsp), %rdx
movl %eax, -0x10(%rdx)
movq %rcx, -0x8(%rdx)
movq 0x18(%r9), %rax
movq %rax, (%rdx)
leaq 0xf0(%rsp), %rax
movq %rax, 0x8(%rdx)
leaq 0xc8(%rsp), %r8
movl $0x4, %edi
jmp 0x6e09
movq %rsp, %rdx
movq %r15, %rdi
movq %rbx, %rsi
callq 0x6a05
jmp 0x6d45
movl $0x3, %eax
leaq 0x100(%rsp), %rsi
movl %eax, -0x10(%rsi)
xorl %ecx, %ecx
movq %rcx, -0x8(%rsi)
movq 0x10(%r9), %rdx
movq %rdx, (%rsi)
movq %r13, 0x8(%rsi)
leaq 0xd8(%rsp), %rdx
movl %eax, -0x10(%rdx)
movq %rcx, -0x8(%rdx)
movq 0x18(%r9), %rax
movq %rax, (%rdx)
leaq 0xf0(%rsp), %rax
movq %rax, 0x8(%rdx)
leaq 0xc8(%rsp), %r8
movl $0x5, %edi
movq %rbx, %rcx
callq 0x4bd6
jmp 0x6d45
movq 0x10(%r9), %rax
jmp 0x6d45
movq %rsp, %r14
movq %r15, %rdi
movq %rbx, %rsi
movq %r14, %rdx
callq 0x7239
movq %rax, 0x38(%rsp)
movq %r15, %rdi
movq %r14, %rsi
callq *0x10(%rbp)
jmp 0x6d45
leaq 0x16ad(%rip), %rsi      # 0x84f7
xorl %eax, %eax
callq 0x4380
leaq 0x1b6a(%rip), %rsi      # 0x89c2
movq %r8, %rdi
jmp 0x6e4a
leaq 0x16be(%rip), %rsi      # 0x8522
movq %r8, %rdi
jmp 0x6e7e
leaq 0x1695(%rip), %rsi      # 0x8505
jmp 0x6e79
leaq 0x1b26(%rip), %rsi      # 0x899f
movq %r8, %rdi
movl %ecx, %edx
xorl %eax, %eax
callq 0x4380