// File: /workspace/github_c_makefile_star2_O1/azhai[P]mlite/mlite.c
// Function: apply_primitive
cell apply_primitive(cell x) {
	PRIM	*p;
	cell	args, a;
	int	k, na, i;

	p = &Primitives[cadar(x)];
	if (p->max_args < 2)
		a = args = cdr(x);
	else if (tuple_p(cadr(x)))
		a = args = cadr(x);
	else
		return too_few_args(x);
	if (p->max_args >= 0) {
		k = length(args);
		if (k < p->min_args)
			return too_few_args(x);
		if (k > p->max_args && p->max_args >= 0)
			return too_many_args(x);
	}
	else {
		/* All variadic functions accept 0..n arguments of any type */
		k = 0;
	}
	na = p->max_args < 0? p->min_args: p->max_args;
	if (na > k)
		na = k;
	for (i=1; i<=na; i++) {
		switch (p->arg_types[i-1]) {
		case T_NONE:
			break;
		case T_BOOLEAN:
			if (!boolean_p(car(a)))
				return expected(car(x), "bool", car(a));
			break;
		case T_CHAR:
			if (!char_p(car(a)))
				return expected(car(x), "char", car(a));
			break;
		case T_INSTREAM:
			if (!instream_p(car(a)))
				return expected(car(x), "instream", car(a));
			break;
		case T_INTEGER:
			if (!integer_p(car(a)))
				return expected(car(x), "int", car(a));
			break;
		case T_OUTSTREAM:
			if (!outstream_p(car(a)))
				return expected(car(x), "outstream", car(a));
			break;
		case T_TUPLE:
			if (atom_p(car(a)))
				return expected(car(x), "tuple", car(a));
			break;
		case T_UNIT:
			if (car(a) != UNIT)
				return expected(car(x), "unit", car(a));
			break;
		case T_LIST:
			if (!list_p(car(a)))
				return expected(car(x), "list", car(a));
			break;
		case T_FUNCTION:
			if (	!procedure_p(car(a)) &&
				!primitive_p(car(a)) &&
				!continuation_p(car(a))
			)
				return expected(car(x), "fn", car(a));
			break;
		case T_REAL:
			if (!integer_p(car(a)) && !real_p(car(a)))
				return expected(car(x), "num", car(a));
			break;
		case T_STREAM:
			if (!instream_p(car(a)) && !outstream_p(car(a)))
				return expected(car(x), "stream", car(a));
			break;
		case T_STRING:
			if (!string_p(car(a)))
				return expected(car(x), "str", car(a));
			break;
		case T_SYMBOL:
			if (!symbol_p(car(a)))
				return expected(car(x), "id", car(a));
			break;
		case T_VECTOR:
			if (!vector_p(car(a)))
				return expected(car(x), "vec", car(a));
			break;
		}
		a = cdr(a);
	}
	return (*p->handler)(args);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %rbx
pushq %rax
movq %rdi, %rsi
movq 0xbd91(%rip), %r9       # 0x1e6c8
movq 0xb832(%rip), %rcx      # 0x1e170
movq 0xbc7b(%rip), %r8       # 0x1e5c0
movq (%rcx,%rdi,8), %rdi
movq (%r8,%rdi,8), %rax
movq (%rcx,%rax,8), %rax
leaq (%rax,%rax,4), %r10
movl 0x14(%r9,%r10,8), %edx
movq (%r8,%rsi,8), %rax
cmpl $0x2, %edx
jge 0x12998
leaq (%r9,%r10,8), %r9
xorl %r10d, %r10d
testl %edx, %edx
js 0x129cd
cmpq $-0x1, %rax
je 0x12984
movq %rax, %r11
incl %r10d
movq (%r8,%r11,8), %r11
cmpq $-0x1, %r11
jne 0x12977
cmpl 0x10(%r9), %r10d
jl 0x129af
cmpl %edx, %r10d
jle 0x129cd
leaq 0x40f6(%rip), %rdi      # 0x16a8c
jmp 0x129b6
movq (%rcx,%rax,8), %rax
testq %rax, %rax
js 0x129af
movq 0xbc38(%rip), %r11      # 0x1e5e0
testb $0x19, (%r11,%rax)
je 0x12963
leaq 0x40c4(%rip), %rdi      # 0x16a7a
callq 0x33eb
movq $-0x5, %rax
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
testl %edx, %edx
jns 0x129d5
movl 0x10(%r9), %edx
cmpl %r10d, %edx
cmovll %edx, %r10d
testl %r10d, %r10d
jle 0x12c89
movq 0xbbf4(%rip), %rsi      # 0x1e5e0
movl %r10d, %r10d
xorl %r11d, %r11d
leaq 0x3703(%rip), %rbx      # 0x160fc
movq %rax, %r14
movl 0x18(%r9,%r11,4), %edx
addl $0x24, %edx
cmpl $0xf, %edx
ja 0x12c79
movslq (%rbx,%rdx,4), %rdx
addq %rbx, %rdx
jmpq *%rdx
movq (%rcx,%r14,8), %rdx
testq %rdx, %rdx
js 0x12cc7
testb $0x10, (%rsi,%rdx)
je 0x12cc7
cmpq $-0x24, (%rcx,%rdx,8)
je 0x12c79
jmp 0x12cc7
movq (%rcx,%r14,8), %rdx
leaq 0x3(%rdx), %r15
cmpq $0x2, %r15
jb 0x12c79
jmp 0x12d0f
movq (%rcx,%r14,8), %rdx
testq %rdx, %rdx
js 0x12cbe
testb $0x1, (%rsi,%rdx)
je 0x12cbe
cmpq $-0x18, (%rcx,%rdx,8)
je 0x12c79
jmp 0x12cbe
movq (%rcx,%r14,8), %rdx
testq %rdx, %rdx
js 0x12cac
testb $0x1, (%rsi,%rdx)
je 0x12a99
cmpq $-0x18, (%rcx,%rdx,8)
je 0x12c79
testq %rdx, %rdx
js 0x12cac
testb $0x1, (%rsi,%rdx)
je 0x12cac
cmpq $-0x1f, (%rcx,%rdx,8)
je 0x12c79
jmp 0x12cac
movq (%rcx,%r14,8), %rdx
testq %rdx, %rdx
js 0x12ceb
testb $0x1, (%rsi,%rdx)
je 0x12ceb
cmpq $-0x16, (%rcx,%rdx,8)
je 0x12c79
jmp 0x12ceb
movq (%rcx,%r14,8), %rdx
testq %rdx, %rdx
js 0x12c9a
testb $0x1, (%rsi,%rdx)
je 0x12b01
cmpq $-0x1e, (%rcx,%rdx,8)
je 0x12c79
testq %rdx, %rdx
js 0x12c9a
testb $0x1, (%rsi,%rdx)
je 0x12b1b
cmpq $-0x1d, (%rcx,%rdx,8)
je 0x12c79
testq %rdx, %rdx
js 0x12c9a
testb $0x1, (%rsi,%rdx)
je 0x12c9a
cmpq $-0x25, (%rcx,%rdx,8)
je 0x12c79
jmp 0x12c9a
movq (%rcx,%r14,8), %rdx
testq %rdx, %rdx
js 0x12cb5
movb (%rsi,%rdx), %r15b
notb %r15b
testb $0x21, %r15b
jne 0x12cb5
cmpq $-0x17, (%rcx,%rdx,8)
je 0x12c79
jmp 0x12cb5
movq (%rcx,%r14,8), %rdx
testq %rdx, %rdx
js 0x12ca3
movb (%rsi,%rdx), %r15b
notb %r15b
testb $0x21, %r15b
jne 0x12b91
cmpq $-0x17, (%rcx,%rdx,8)
je 0x12c79
testq %rdx, %rdx
js 0x12ca3
movb (%rsi,%rdx), %r15b
notb %r15b
testb $0x21, %r15b
jne 0x12ca3
cmpq $-0x19, (%rcx,%rdx,8)
je 0x12c79
jmp 0x12ca3
movq (%rcx,%r14,8), %rdx
testq %rdx, %rdx
js 0x12cd9
testb $0x10, (%rsi,%rdx)
je 0x12cd9
cmpq $-0x21, (%rcx,%rdx,8)
je 0x12c79
jmp 0x12cd9
movq (%rcx,%r14,8), %rdx
testq %rdx, %rdx
js 0x12ce2
testb $0x10, (%rsi,%rdx)
je 0x12ce2
cmpq $-0x22, (%rcx,%rdx,8)
je 0x12c79
jmp 0x12ce2
movq (%rcx,%r14,8), %rdx
testq %rdx, %rdx
js 0x12c6f
movb (%rsi,%rdx), %r15b
andb $0x19, %r15b
cmpb $0x8, %r15b
je 0x12c79
jmp 0x12d06
movq (%rcx,%r14,8), %rdx
cmpq $-0x6, %rdx
je 0x12c79
jmp 0x12cfd
movq (%rcx,%r14,8), %rdx
testq %rdx, %rdx
js 0x12cd0
movb (%rsi,%rdx), %r15b
notb %r15b
testb $0x21, %r15b
jne 0x12cd0
cmpq $-0x19, (%rcx,%rdx,8)
je 0x12c79
jmp 0x12cd0
movq (%rcx,%r14,8), %rdx
testq %rdx, %rdx
js 0x12cf4
testb $0x11, (%rsi,%rdx)
je 0x12c79
jmp 0x12cf4
cmpq $-0x1, %rdx
jne 0x12d06
movq (%r8,%r14,8), %r14
incq %r11
cmpq %r11, %r10
jne 0x129fc
movq %rax, %rdi
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
jmpq *0x8(%r9)
leaq 0x396b(%rip), %rsi      # 0x1660c
jmp 0x12d16
leaq 0x433b(%rip), %rsi      # 0x16fe5
jmp 0x12d16
leaq 0x4470(%rip), %rsi      # 0x17123
jmp 0x12d16
leaq 0x43a8(%rip), %rsi      # 0x17064
jmp 0x12d16
leaq 0x3943(%rip), %rsi      # 0x16608
jmp 0x12d16
leaq 0x41f6(%rip), %rsi      # 0x16ec4
jmp 0x12d16
leaq 0x43bc(%rip), %rsi      # 0x17093
jmp 0x12d16
leaq 0x3fe4(%rip), %rsi      # 0x16cc4
jmp 0x12d16
leaq 0x443e(%rip), %rsi      # 0x17127
jmp 0x12d16
leaq 0x434f(%rip), %rsi      # 0x17041
jmp 0x12d16
leaq 0x3aac(%rip), %rsi      # 0x167a7
jmp 0x12d16
leaq 0x441a(%rip), %rsi      # 0x1711e
jmp 0x12d16
leaq 0x3a86(%rip), %rsi      # 0x16793
jmp 0x12d16
leaq 0x42d6(%rip), %rsi      # 0x16fec
callq 0x128bd
jmp 0x129bb