// File: /workspace/github_c_makefile_star2_O1/dalnefre[P]kernel_abe/emit.c
// Function: emit_cons
void
emit_cons(CONS* cons, int indent, void (*emit)(char c, void* ctx), void* ctx)
{
	char buf[256];
	int emit_length = 0;
	int i;
	char c;
	char *p;

	XDBUG_ENTER("emit_cons");
	++emit_depth;
	if (boolp(cons)) {
		sprintf(buf, cons ? "-T-" : "-F-");
	} else if (nilp(cons)) {
		sprintf(buf, "NIL");
	} else if (atomp(cons)) {
		char *s = atom_str(cons);
		int qtd = s[strcspn(s, REDUCE_TOKEN_BRKS)]; /* look for special chars */

		if (qtd) {
			(*emit)('"', ctx);
		}
		if (strlen(s) > 250) {
			sprintf(buf, "%.250s...", s);
		} else {
			strncpy(buf, s, 255);
		}
		if (qtd) {
			int n = strlen(buf);

			buf[n++] = '"';
			buf[n] = '\0';
		}
	} else if (numberp(cons)) {
		sprintf(buf, "%d", MK_INT(cons));
#if NUMBER_IS_FUNC
#else
	} else if (funcp(cons)) {
		sprintf(buf, "@%p", MK_PTR(cons));
#endif
	} else if (consp(cons)) {
		if (emit_depth > EMIT_DEPTH_LIMIT) {
			sprintf(buf, "[%p;%p]", (void*)car(cons), (void*)cdr(cons));
		} else {
			(*emit)('(', ctx);
			for (emit_length = 0; emit_length < EMIT_LENGTH_LIMIT; ++emit_length) {
				emit_cons(car(cons), indent, emit, ctx);
				cons = cdr(cons);
				if (nilp(cons)) {
					break;
				} else if (!consp(cons)) {
					(*emit)(' ', ctx);
					(*emit)(':', ctx);
					(*emit)(' ', ctx);
					emit_cons(cons, indent, emit, ctx);
					break;
				}
				if (indent) {
					(*emit)('\n', ctx);
					for (i = 0; i < emit_depth; ++i) {
						(*emit)(' ', ctx);
					}
				} else {
					(*emit)(' ', ctx);
				}
			}
			sprintf(buf, "%s)", (emit_length >= EMIT_LENGTH_LIMIT) ? "... " : "");
		}
	} else {
		sprintf(buf, "#%p", (void*)cons);
	}
	/* tie off the buffer and safely stream it out one character at a time */
	buf[255] = '\0';
	p = buf;
	while ((c = *p++) != '\0') {
		(*emit)(c, ctx);
	}
	--emit_depth;
	XDBUG_RETURN;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x108, %rsp            # imm = 0x108
movq %rcx, %rbx
movq %rdx, %r14
movq %rdi, %r15
movl 0xf0c7(%rip), %eax      # 0x237f8
leal 0x1(%rax), %ecx
movl %ecx, 0xf0be(%rip)      # 0x237f8
cmpq $0x1, %rdi
ja 0x14764
testq %r15, %r15
leaq 0x8be9(%rip), %rax      # 0x1d333
leaq 0x8bde(%rip), %rsi      # 0x1d32f
cmoveq %rax, %rsi
movq %rsp, %rdi
xorl %eax, %eax
callq 0x2220
jmp 0x1497e
cmpq 0xe855(%rip), %r15      # 0x22fc0
je 0x147d2
movl %r15d, %ecx
andl $0x3, %ecx
cmpq $0x3, %rcx
je 0x147de
cmpl $0x2, %ecx
jne 0x147fb
movq %r15, %rdi
callq 0x170e9
movq %rax, %r15
leaq 0x8ba7(%rip), %rsi      # 0x1d337
movq %rax, %rdi
callq 0x2140
movb (%r15,%rax), %bpl
testb %bpl, %bpl
je 0x147ac
movl $0x22, %edi
movq %rbx, %rsi
callq *%r14
movq %r15, %rdi
callq 0x20d0
cmpq $0xfb, %rax
jb 0x1481d
leaq 0x8b7f(%rip), %rsi      # 0x1d342
movq %rsp, %rdi
movq %r15, %rdx
xorl %eax, %eax
callq 0x2220
jmp 0x1482d
movl $0x4c494e, (%rsp)       # imm = 0x4C494E
jmp 0x1497e
shrq $0x2, %r15
leaq 0x8f07(%rip), %rsi      # 0x1d6f0
movq %rsp, %rdi
movl %r15d, %edx
xorl %eax, %eax
callq 0x2220
jmp 0x1497e
testq %r15, %r15
sete %dl
testq %rcx, %rcx
setne %cl
orb %dl, %cl
je 0x14851
leaq 0x8b4b(%rip), %rsi      # 0x1d35d
movq %rsp, %rdi
movq %r15, %rdx
jmp 0x14977
movq %rsp, %rdi
movl $0xff, %edx
movq %r15, %rsi
callq 0x2070
testb %bpl, %bpl
je 0x1497e
movq %rsp, %rdi
callq 0x20d0
cltq
movb $0x22, (%rsp,%rax)
incl %eax
cltq
movb $0x0, (%rsp,%rax)
jmp 0x1497e
cmpl $0x6, %eax
jl 0x14885
movq %r15, %rdi
callq 0x19ba6
movq %rax, %r12
movq %r15, %rdi
callq 0x19c45
leaq 0x8adc(%rip), %rsi      # 0x1d34c
movq %rsp, %rdi
movq %r12, %rdx
movq %rax, %rcx
xorl %eax, %eax
callq 0x2220
jmp 0x1497e
movl %esi, %ebp
movl $0x28, %edi
movq %rbx, %rsi
callq *%r14
xorl %r12d, %r12d
movq %r15, %rdi
callq 0x19ba6
movq %rax, %rdi
movl %ebp, %esi
movq %r14, %rdx
movq %rbx, %rcx
callq 0x14711
movq %r15, %rdi
callq 0x19c45
cmpq 0xe704(%rip), %rax      # 0x22fc0
je 0x14957
movq %rax, %r15
testq %rax, %rax
je 0x14926
movl %r15d, %eax
andl $0x3, %eax
jne 0x14926
testl %ebp, %ebp
je 0x14906
movl $0xa, %edi
movq %rbx, %rsi
callq *%r14
cmpl $0x0, 0xef10(%rip)      # 0x237f8
jle 0x14911
xorl %r13d, %r13d
movl $0x20, %edi
movq %rbx, %rsi
callq *%r14
incl %r13d
cmpl 0xeef6(%rip), %r13d     # 0x237f8
jl 0x148ed
jmp 0x14911
movl $0x20, %edi
movq %rbx, %rsi
callq *%r14
incl %r12d
cmpl $0x9, %r12d
jne 0x14895
movl $0x9, %r12d
jmp 0x14957
movl $0x20, %edi
movq %rbx, %rsi
callq *%r14
movl $0x3a, %edi
movq %rbx, %rsi
callq *%r14
movl $0x20, %edi
movq %rbx, %rsi
callq *%r14
movq %r15, %rdi
movl %ebp, %esi
movq %r14, %rdx
movq %rbx, %rcx
callq 0x14711
cmpl $0x9, %r12d
leaq 0x89f6(%rip), %rax      # 0x1d358
leaq 0x79e1(%rip), %rdx      # 0x1c34a
cmovaeq %rax, %rdx
leaq 0x89e0(%rip), %rsi      # 0x1d354
movq %rsp, %rdi
xorl %eax, %eax
callq 0x2220
movb $0x0, 0xff(%rsp)
movb (%rsp), %al
testb %al, %al
je 0x149a5
leaq 0x1(%rsp), %r15
movsbl %al, %edi
movq %rbx, %rsi
callq *%r14
movb (%r15), %al
incq %r15
testb %al, %al
jne 0x14992
decl 0xee4d(%rip)            # 0x237f8
addq $0x108, %rsp            # imm = 0x108
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq