// File: /workspace/github_c_makefile_star2_O2/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 %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %rdi, %r15
movq 0xba4d(%rip), %rax      # 0x1c6c8
movq 0xb4ee(%rip), %r12      # 0x1c170
movq 0xb937(%rip), %r13      # 0x1c5c0
movq (%r12,%rdi,8), %rdi
movq (%r13,%rdi,8), %rcx
imulq $0x28, (%r12,%rcx,8), %rcx
leaq (%rax,%rcx), %r11
movl 0x14(%rax,%rcx), %ebx
movq (%r13,%r15,8), %r14
cmpl $0x2, %ebx
jge 0x10cb5
testl %ebx, %ebx
jns 0x10ccc
movl 0x10(%r11), %ebx
xorl %eax, %eax
jmp 0x10d0e
movq (%r12,%r14,8), %r14
testq %r14, %r14
js 0x10ce5
movq 0xb91b(%rip), %rax      # 0x1c5e0
testb $0x19, (%rax,%r14)
jne 0x10ce5
movq %rdi, -0x38(%rbp)
movq %r14, -0x30(%rbp)
movq %r14, %rdi
movq %r11, %r14
callq 0x46c4
cmpl 0x10(%r14), %eax
jge 0x10cf2
movq %r15, %rdi
callq 0xcb5c
jmp 0x11009
movq %r14, %r11
cmpl %ebx, %eax
movq -0x38(%rbp), %rdi
movq -0x30(%rbp), %r14
jle 0x10d0e
movq %r15, %rdi
callq 0xcb74
jmp 0x11009
cmpl %eax, %ebx
cmovll %ebx, %eax
movq 0xb8c6(%rip), %rcx      # 0x1c5e0
xorl %esi, %esi
testl %eax, %eax
cmovlel %esi, %eax
leaq 0x33d4(%rip), %r10      # 0x140fc
movq %r14, %r8
cmpq %rsi, %rax
je 0x10f73
movl 0x18(%r11,%rsi,4), %edx
addl $0x24, %edx
cmpl $0xf, %edx
ja 0x10f66
movslq (%r10,%rdx,4), %rdx
addq %r10, %rdx
jmpq *%rdx
movq (%r12,%r8,8), %rdx
testq %rdx, %rdx
js 0x10f9a
testb $0x10, (%rcx,%rdx)
je 0x10f9a
cmpq $-0x24, (%r12,%rdx,8)
je 0x10f66
jmp 0x10f9a
movq (%r12,%r8,8), %rdx
leaq 0x3(%rdx), %r9
cmpq $0x2, %r9
jb 0x10f66
jmp 0x10feb
movq (%r12,%r8,8), %rdx
testq %rdx, %rdx
js 0x10f88
testb $0x1, (%rcx,%rdx)
je 0x10f88
cmpq $-0x18, (%r12,%rdx,8)
je 0x10f66
jmp 0x10f88
movq (%r12,%r8,8), %rdx
testq %rdx, %rdx
js 0x10fc7
testb $0x1, (%rcx,%rdx)
je 0x10fc7
cmpq $-0x18, (%r12,%rdx,8)
je 0x10f66
cmpq $-0x1f, (%r12,%rdx,8)
je 0x10f66
jmp 0x10fc7
movq (%r12,%r8,8), %rdx
testq %rdx, %rdx
js 0x10fbe
testb $0x1, (%rcx,%rdx)
je 0x10fbe
cmpq $-0x16, (%r12,%rdx,8)
je 0x10f66
jmp 0x10fbe
movq (%r12,%r8,8), %rdx
testq %rdx, %rdx
js 0x10fd9
testb $0x1, (%rcx,%rdx)
je 0x10fd9
cmpq $-0x1e, (%r12,%rdx,8)
je 0x10f66
cmpq $-0x1d, (%r12,%rdx,8)
je 0x10f66
cmpq $-0x25, (%r12,%rdx,8)
je 0x10f66
jmp 0x10fd9
movq (%r12,%r8,8), %rdx
testq %rdx, %rdx
js 0x10fb5
movb (%rcx,%rdx), %r9b
notb %r9b
testb $0x21, %r9b
jne 0x10fb5
cmpq $-0x17, (%r12,%rdx,8)
je 0x10f66
jmp 0x10fb5
movq (%r12,%r8,8), %rdx
testq %rdx, %rdx
js 0x10fd0
movb (%rcx,%rdx), %r9b
notb %r9b
testb $0x21, %r9b
jne 0x10fd0
cmpq $-0x17, (%r12,%rdx,8)
je 0x10f66
cmpq $-0x19, (%r12,%rdx,8)
je 0x10f66
jmp 0x10fd0
movq (%r12,%r8,8), %rdx
testq %rdx, %rdx
js 0x10f91
testb $0x10, (%rcx,%rdx)
je 0x10f91
cmpq $-0x21, (%r12,%rdx,8)
je 0x10f66
jmp 0x10f91
movq (%r12,%r8,8), %rdx
testq %rdx, %rdx
js 0x10fa3
testb $0x10, (%rcx,%rdx)
je 0x10fa3
cmpq $-0x22, (%r12,%rdx,8)
je 0x10f66
jmp 0x10fa3
movq (%r12,%r8,8), %rdx
testq %rdx, %rdx
js 0x10f5c
movb (%rcx,%rdx), %r9b
andb $0x19, %r9b
cmpb $0x8, %r9b
je 0x10f66
jmp 0x10ff4
movq (%r12,%r8,8), %rdx
cmpq $-0x6, %rdx
je 0x10f66
jmp 0x10ffd
movq (%r12,%r8,8), %rdx
testq %rdx, %rdx
js 0x10fac
movb (%rcx,%rdx), %r9b
notb %r9b
testb $0x21, %r9b
jne 0x10fac
cmpq $-0x19, (%r12,%rdx,8)
je 0x10f66
jmp 0x10fac
movq (%r12,%r8,8), %rdx
testq %rdx, %rdx
js 0x10fe2
testb $0x11, (%rcx,%rdx)
je 0x10f66
jmp 0x10fe2
cmpq $-0x1, %rdx
jne 0x10ff4
movq (%r13,%r8,8), %r8
incq %rsi
jmp 0x10d2b
movq %r14, %rdi
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmpq *0x8(%r11)
leaq 0x3661(%rip), %rsi      # 0x145f0
jmp 0x11004
leaq 0x3d11(%rip), %rsi      # 0x14ca9
jmp 0x11004
leaq 0x3f08(%rip), %rsi      # 0x14ea9
jmp 0x11004
leaq 0x4162(%rip), %rsi      # 0x1510c
jmp 0x11004
leaq 0x40c5(%rip), %rsi      # 0x15078
jmp 0x11004
leaq 0x408d(%rip), %rsi      # 0x15049
jmp 0x11004
leaq 0x4061(%rip), %rsi      # 0x15026
jmp 0x11004
leaq 0x413a(%rip), %rsi      # 0x15108
jmp 0x11004
leaq 0x3ff3(%rip), %rsi      # 0x14fca
jmp 0x11004
leaq 0x3614(%rip), %rsi      # 0x145f4
jmp 0x11004
leaq 0x37a3(%rip), %rsi      # 0x1478c
jmp 0x11004
leaq 0x3fdf(%rip), %rsi      # 0x14fd1
jmp 0x11004
leaq 0x377d(%rip), %rsi      # 0x14778
jmp 0x11004
leaq 0x40ff(%rip), %rsi      # 0x15103
callq 0x10c01
pushq $-0x5
popq %rax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq