// File: /workspace/github_c_makefile_star2_O3/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 0xc0b6(%rip), %rax      # 0x1e6c8
movq 0xbb57(%rip), %rcx      # 0x1e170
movq 0xbfa0(%rip), %r8       # 0x1e5c0
movq (%rcx,%rdi,8), %rdi
movq (%r8,%rdi,8), %rdx
movq (%rcx,%rdx,8), %rdx
leaq (%rdx,%rdx,4), %rdx
leaq (%rax,%rdx,8), %r9
movl 0x14(%rax,%rdx,8), %edx
movq (%r8,%rsi,8), %rax
cmpl $0x2, %edx
jge 0x12657
testl %edx, %edx
js 0x126b6
cmpq $-0x1, %rax
jne 0x1266e
xorl %r10d, %r10d
movq $-0x1, %rax
jmp 0x12681
movq (%rcx,%rax,8), %rax
testq %rax, %rax
js 0x1268a
movq 0xbf79(%rip), %r10      # 0x1e5e0
testb $0x19, (%r10,%rax)
jne 0x1268a
xorl %r10d, %r10d
movq %rax, %r11
incl %r10d
movq (%r8,%r11,8), %r11
cmpq $-0x1, %r11
jne 0x12674
movl 0x10(%r9), %r11d
cmpl %r11d, %r10d
jge 0x126a8
leaq 0x43ce(%rip), %rdi      # 0x16a5f
callq 0x33eb
movq $-0x5, %rax
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
cmpl %edx, %r10d
jle 0x126bf
leaq 0x43bd(%rip), %rdi      # 0x16a71
jmp 0x12691
movl 0x10(%r9), %r11d
xorl %r10d, %r10d
jmp 0x126c5
testl %edx, %edx
cmovnsl %edx, %r11d
cmpl %r10d, %r11d
cmovll %r11d, %r10d
testl %r10d, %r10d
jle 0x12932
movq 0xbf04(%rip), %rsi      # 0x1e5e0
movl %r10d, %r10d
xorl %r11d, %r11d
leaq 0x3a13(%rip), %rbx      # 0x160fc
movq %rax, %r14
movl 0x18(%r9,%r11,4), %edx
addl $0x24, %edx
cmpl $0xf, %edx
ja 0x12922
movslq (%rbx,%rdx,4), %rdx
addq %rbx, %rdx
jmpq *%rdx
movq (%rcx,%r14,8), %rdx
testq %rdx, %rdx
js 0x12967
testb $0x10, (%rsi,%rdx)
je 0x12967
cmpq $-0x24, (%rcx,%rdx,8)
je 0x12922
jmp 0x12967
movq (%rcx,%r14,8), %rdx
leaq 0x3(%rdx), %r15
cmpq $0x2, %r15
jb 0x12922
jmp 0x129b8
movq (%rcx,%r14,8), %rdx
testq %rdx, %rdx
js 0x12943
testb $0x1, (%rsi,%rdx)
je 0x12943
cmpq $-0x18, (%rcx,%rdx,8)
je 0x12922
jmp 0x12943
movq (%rcx,%r14,8), %rdx
testq %rdx, %rdx
js 0x12982
testb $0x1, (%rsi,%rdx)
je 0x12982
cmpq $-0x18, (%rcx,%rdx,8)
je 0x12922
cmpq $-0x1f, (%rcx,%rdx,8)
je 0x12922
jmp 0x12982
movq (%rcx,%r14,8), %rdx
testq %rdx, %rdx
js 0x1294c
testb $0x1, (%rsi,%rdx)
je 0x1294c
cmpq $-0x16, (%rcx,%rdx,8)
je 0x12922
jmp 0x1294c
movq (%rcx,%r14,8), %rdx
testq %rdx, %rdx
js 0x12994
testb $0x1, (%rsi,%rdx)
je 0x12994
cmpq $-0x1e, (%rcx,%rdx,8)
je 0x12922
cmpq $-0x1d, (%rcx,%rdx,8)
je 0x12922
cmpq $-0x25, (%rcx,%rdx,8)
je 0x12922
jmp 0x12994
movq (%rcx,%r14,8), %rdx
testq %rdx, %rdx
js 0x1295e
movb (%rsi,%rdx), %r15b
notb %r15b
testb $0x21, %r15b
jne 0x1295e
cmpq $-0x17, (%rcx,%rdx,8)
je 0x12922
jmp 0x1295e
movq (%rcx,%r14,8), %rdx
testq %rdx, %rdx
js 0x1298b
movb (%rsi,%rdx), %r15b
notb %r15b
testb $0x21, %r15b
jne 0x1298b
cmpq $-0x17, (%rcx,%rdx,8)
je 0x12922
cmpq $-0x19, (%rcx,%rdx,8)
je 0x12922
jmp 0x1298b
movq (%rcx,%r14,8), %rdx
testq %rdx, %rdx
js 0x12979
testb $0x10, (%rsi,%rdx)
je 0x12979
cmpq $-0x21, (%rcx,%rdx,8)
je 0x12922
jmp 0x12979
movq (%rcx,%r14,8), %rdx
testq %rdx, %rdx
js 0x12955
testb $0x10, (%rsi,%rdx)
je 0x12955
cmpq $-0x22, (%rcx,%rdx,8)
je 0x12922
jmp 0x12955
movq (%rcx,%r14,8), %rdx
testq %rdx, %rdx
js 0x12918
movb (%rsi,%rdx), %r15b
andb $0x19, %r15b
cmpb $0x8, %r15b
je 0x12922
jmp 0x129a6
movq (%rcx,%r14,8), %rdx
cmpq $-0x6, %rdx
je 0x12922
jmp 0x129af
movq (%rcx,%r14,8), %rdx
testq %rdx, %rdx
js 0x12970
movb (%rsi,%rdx), %r15b
notb %r15b
testb $0x21, %r15b
jne 0x12970
cmpq $-0x19, (%rcx,%rdx,8)
je 0x12922
jmp 0x12970
movq (%rcx,%r14,8), %rdx
testq %rdx, %rdx
js 0x1299d
testb $0x11, (%rsi,%rdx)
je 0x12922
jmp 0x1299d
cmpq $-0x1, %rdx
jne 0x129a6
movq (%r8,%r14,8), %r14
incq %r11
cmpq %r11, %r10
jne 0x126ec
movq %rax, %rdi
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
jmpq *0x8(%r9)
leaq 0x3ca6(%rip), %rsi      # 0x165f0
jmp 0x129bf
leaq 0x46d3(%rip), %rsi      # 0x17026
jmp 0x129bf
leaq 0x47b0(%rip), %rsi      # 0x1710c
jmp 0x129bf
leaq 0x46e4(%rip), %rsi      # 0x17049
jmp 0x129bf
leaq 0x453b(%rip), %rsi      # 0x16ea9
jmp 0x129bf
leaq 0x4701(%rip), %rsi      # 0x17078
jmp 0x129bf
leaq 0x4329(%rip), %rsi      # 0x16ca9
jmp 0x129bf
leaq 0x477f(%rip), %rsi      # 0x17108
jmp 0x129bf
leaq 0x4638(%rip), %rsi      # 0x16fca
jmp 0x129bf
leaq 0x3c59(%rip), %rsi      # 0x165f4
jmp 0x129bf
leaq 0x3de8(%rip), %rsi      # 0x1678c
jmp 0x129bf
leaq 0x3dcb(%rip), %rsi      # 0x16778
jmp 0x129bf
leaq 0x474d(%rip), %rsi      # 0x17103
jmp 0x129bf
leaq 0x4612(%rip), %rsi      # 0x16fd1
callq 0x12598
jmp 0x12696