// File: /workspace/github_c_makefile_star2_O1/qpfiffer[P]lair/src/lair_std.c
// Function: lair_builtin_str
const struct _lair_type *_lair_builtin_str(LAIR_FUNCTION_SIG) {
	printf("ARGC IS %i", argc);
	check(r, argc == 1, ERR_RUNTIME, "Incorrect number of arguments to 'str' function.");

	struct _lair_type *new_string = calloc(1, sizeof(struct _lair_type));
	new_string->type = LR_STRING;

	if (argv[0] == NULL) {
		char buf[] = "(null)";
		char *ptr = calloc(1, sizeof(buf));
		memcpy(ptr, buf, sizeof(buf));
		new_string->value.str = ptr;
	} else {
		char *friendly = _friendly_enum(argv[0]->type);
		char buf[512] = {0};
		char *ptr = NULL;
		size_t siz = 0;

		switch (argv[0]->type) {
		case LR_STRING:
			siz = strlen(argv[0]->value.str);
			ptr = calloc(1, siz);
			memcpy(ptr, argv[0]->value.str, siz);
			new_string->value.str = ptr;
			break;
		case LR_NUM:
			snprintf(buf, sizeof(buf), "%i", argv[0]->value.num);

			siz = strlen(buf);
			ptr = calloc(1, siz);
			memcpy(ptr, buf, siz);
			new_string->value.str = ptr;
			break;
		case LR_FUNCTION_DEF:
		case LR_FUNCTION_CALL:
			snprintf(buf, sizeof(buf), "<%s: %s>", friendly, argv[0]->value.str);

			siz = strlen(buf);
			ptr = calloc(1, siz);
			memcpy(ptr, buf, siz);
			new_string->value.str = ptr;
			break;
		default:
			snprintf(buf, sizeof(buf), "<%s: %p>", friendly, argv[0]);

			siz = strlen(buf);
			ptr = calloc(1, siz);
			memcpy(ptr, buf, siz);
			new_string->value.str = ptr;
			break;
		}
	}

	return new_string;
}

// Assembly:
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0x208, %rsp            # imm = 0x208
movq %rdx, %r14
movl %esi, %ebx
movq %rdi, %r15
leaq 0x276a(%rip), %rdi      # 0x4315
xorl %eax, %eax
callq 0x10a0
xorl %esi, %esi
cmpl $0x1, %ebx
sete %sil
leaq 0x275e(%rip), %rcx      # 0x4320
movq %r15, %rdi
movl $0x2, %edx
callq 0x1600
movl $0x1, %edi
movl $0x10, %esi
callq 0x1130
movq %rax, %rbx
movl $0xa, (%rax)
movq (%r14), %rax
testq %rax, %rax
je 0x1c26
movl (%rax), %edi
callq 0x2b90
movq %rax, %r15
movq %rsp, %rdi
movl $0x200, %edx            # imm = 0x200
xorl %esi, %esi
callq 0x10d0
movq (%r14), %r8
movl (%r8), %eax
leal -0x1(%rax), %ecx
cmpl $0x2, %ecx
jb 0x1c4b
cmpl $0xf, %eax
je 0x1c58
cmpl $0xa, %eax
jne 0x1c9b
movq 0x8(%r8), %r15
jmp 0x1c75
movl $0x1, %edi
movl $0x7, %esi
callq 0x1130
movl $0x6c756e28, (%rax)     # imm = 0x6C756E28
movl $0x296c6c, 0x3(%rax)    # imm = 0x296C6C
movq %rax, 0x8(%rbx)
jmp 0x1ce4
movq 0x8(%r8), %r8
leaq 0x2702(%rip), %rdx      # 0x4358
jmp 0x1ca2
movl 0x8(%r8), %ecx
leaq 0x26ba(%rip), %rdx      # 0x431d
movq %rsp, %r15
movl $0x200, %esi            # imm = 0x200
movq %r15, %rdi
xorl %eax, %eax
callq 0x10b0
movq %r15, %rdi
callq 0x1080
movq %rax, %r12
movl $0x1, %edi
movq %rax, %rsi
callq 0x1130
movq %rax, %r14
movq %rax, %rdi
movq %r15, %rsi
movq %r12, %rdx
jmp 0x1cdb
leaq 0x2635(%rip), %rdx      # 0x42d7
movq %rsp, %r12
movl $0x200, %esi            # imm = 0x200
movq %r12, %rdi
movq %r15, %rcx
xorl %eax, %eax
callq 0x10b0
movq %r12, %rdi
callq 0x1080
movq %rax, %r15
movl $0x1, %edi
movq %rax, %rsi
callq 0x1130
movq %rax, %r14
movq %rax, %rdi
movq %r12, %rsi
movq %r15, %rdx
callq 0x1160
movq %r14, 0x8(%rbx)
movq %rbx, %rax
addq $0x208, %rsp            # imm = 0x208
popq %rbx
popq %r12
popq %r14
popq %r15
retq
nop