// File: /workspace/github_c_makefile_star2_O1/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 $0x128, %rsp            # imm = 0x128
movl $0x3, %r8d
leaq 0x20(%rsp), %rbx
movl %r8d, -0x10(%rbx)
xorl %eax, %eax
movq %rax, -0x8(%rbx)
movq (%rdi), %rcx
movq %rcx, (%rbx)
movq %rdx, 0x8(%rbx)
leaq 0x110(%rsp), %r14
movl %r8d, -0x10(%r14)
movq %rax, -0x8(%r14)
movq (%rsi), %rcx
movq %rcx, (%r14)
leaq 0x10(%rsp), %rcx
movq %rcx, 0x8(%r14)
leaq 0xe8(%rsp), %r15
movl %r8d, -0x10(%r15)
movq %rax, -0x8(%r15)
movq 0x6506(%rip), %rcx      # 0xd208
movq %rcx, (%r15)
leaq 0x100(%rsp), %rdx
movq %rdx, 0x8(%r15)
leaq 0x98(%rsp), %r12
movl %r8d, -0x10(%r12)
movq %rax, -0x8(%r12)
movq %rcx, (%r12)
leaq 0xd8(%rsp), %rdx
movq %rdx, 0x8(%r12)
leaq 0xc0(%rsp), %r13
movl %r8d, -0x10(%r13)
movq %rax, -0x8(%r13)
movq %rcx, (%r13)
leaq 0x88(%rsp), %rax
movq %rax, 0x8(%r13)
leaq 0xb0(%rsp), %rbp
movq %rax, 0x8(%rsp)
movq 0x20(%rsp), %rdi
movl (%rdi), %eax
cmpl $0x3, %eax
jne 0x6fcf
movq 0x10(%rdi), %rax
movq %rax, 0xe8(%rsp)
movq 0x18(%rdi), %rax
movq %rax, 0x98(%rsp)
movq %r15, %rdi
movq %r14, %rsi
movq %rbp, %rdx
callq 0x6c9c
movq %rax, %r8
movq %rax, 0xe8(%rsp)
movq 0x645f(%rip), %rcx      # 0xd208
movq %rcx, 0xc0(%rsp)
movl (%rax), %eax
cmpl $0x4, %eax
je 0x6dd0
cmpl $0x5, %eax
jne 0x6e20
movq %r15, %rdi
movq %r12, %rsi
movq %rbx, %rdx
movq %rbp, %rcx
callq 0x7358
jmp 0x6e16
movq 0x18(%r8), %rax
movq %rax, 0xc0(%rsp)
movq %r12, %rdi
movq %r14, %rsi
movq %rbp, %rdx
callq 0x73f7
movq %rax, 0x98(%rsp)
movq %r15, %rdi
movq %r12, %rsi
movq %rbp, %rdx
callq 0x4cea
movq %rax, 0x110(%rsp)
movq %r13, %rdi
movq %r14, %rsi
movq %rbp, %rdx
callq 0x703a
movq %rax, 0x20(%rsp)
jmp 0x6d61
cmpl $0x6, %eax
jne 0x6ff8
movslq 0x10(%r8), %r9
movq 0x98(%rsp), %rsi
xorl %eax, %eax
cmpq %rcx, %rsi
je 0x6e53
movq %rsi, %rdi
cmpl $0x3, (%rdi)
jne 0x7004
movq 0x18(%rdi), %rdi
incl %eax
cmpq %rcx, %rdi
jne 0x6e3f
leaq (%r9,%r9,2), %rcx
leaq 0x63c2(%rip), %rdx      # 0xd220
leaq (%rdx,%rcx,8), %rbx
movl 0x8(%rbx), %edx
cmpl %edx, %eax
jl 0x7012
movl 0xc(%rbx), %ecx
cmpl %eax, %ecx
jb 0x701e
testl %ecx, %ecx
jns 0x6e8a
negl %ecx
xorl %edx, %edx
divl %ecx
testl %edx, %edx
jne 0x7027
cmpl $0x6, %r9d
ja 0x6ef0
movl %r9d, %eax
leaq 0x15a2(%rip), %rcx      # 0x843c
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq 0x10(%rsi), %rax
jmp 0x6fbe
movq %r12, %rdi
movq %r14, %rsi
movq %rbp, %rdx
callq 0x711e
jmp 0x6eda
movq %r12, %rdi
movq %r14, %rsi
movq %rbp, %rdx
callq 0x703a
jmp 0x6eda
movq %r12, %rdi
movq %r14, %rsi
movq %rbp, %rdx
callq 0x70c1
movq %rax, 0x20(%rsp)
movb $0x1, %cl
leaq 0x20(%rsp), %rbx
movq 0x8(%rsp), %rax
jmp 0x6fc5
movq %r12, %rdi
movq %r14, %rsi
movq %rbp, %rdx
callq 0x73f7
movq %rax, 0x98(%rsp)
movq %r12, %rdi
movq %rbp, %rsi
callq *0x10(%rbx)
jmp 0x6fbe
movq %r12, %rdi
movq %r14, %rsi
movq %rbp, %rdx
callq 0x6b74
jmp 0x6fbe
movl $0x3, %ecx
movl %ecx, 0x60(%rsp)
xorl %edx, %edx
movq %rdx, 0x68(%rsp)
movq 0x10(%rsi), %rax
movq %rax, 0x70(%rsp)
movq %rbp, 0x78(%rsp)
movl %ecx, 0x38(%rsp)
movq %rdx, 0x40(%rsp)
movq 0x18(%rsi), %rax
movq %rax, 0x48(%rsp)
leaq 0x60(%rsp), %rax
movq %rax, 0x50(%rsp)
movl $0x4, %edi
jmp 0x6fa7
movl $0x3, %ecx
movl %ecx, 0x60(%rsp)
xorl %edx, %edx
movq %rdx, 0x68(%rsp)
movq 0x10(%rsi), %rax
movq %rax, 0x70(%rsp)
movq %rbp, 0x78(%rsp)
movl %ecx, 0x38(%rsp)
movq %rdx, 0x40(%rsp)
movq 0x18(%rsi), %rax
movq %rax, 0x48(%rsp)
leaq 0x60(%rsp), %rax
movq %rax, 0x50(%rsp)
movl $0x5, %edi
leaq 0x70(%rsp), %rsi
leaq 0x48(%rsp), %rdx
movq %r14, %rcx
leaq 0x38(%rsp), %r8
callq 0x4bf8
xorl %ecx, %ecx
leaq 0x20(%rsp), %rbx
testb %cl, %cl
jne 0x6d5c
jmp 0x6fe6
cmpl $0x2, %eax
jne 0x6fe3
movq 0x110(%rsp), %rsi
callq 0x5810
jmp 0x6fe6
movq %rdi, %rax
addq $0x128, %rsp            # imm = 0x128
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x19c3(%rip), %rsi      # 0x89c2
movq %r8, %rdi
jmp 0x700b
leaq 0x14ec(%rip), %rsi      # 0x84f7
xorl %eax, %eax
callq 0x4388
leaq 0x1509(%rip), %rsi      # 0x8522
movq %r8, %rdi
jmp 0x7033
leaq 0x14e0(%rip), %rsi      # 0x8505
jmp 0x702e
leaq 0x1971(%rip), %rsi      # 0x899f
movq %r8, %rdi
movl %ecx, %edx
xorl %eax, %eax
callq 0x4388