// File: /workspace/github_c_makefile_star2_O2/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 0x27e5(%rip), %rdi      # 0x4315
xorl %eax, %eax
callq 0x10a0
xorl %esi, %esi
cmpl $0x1, %ebx
sete %sil
leaq 0x27d9(%rip), %rcx      # 0x4320
pushq $0x2
popq %rdx
movq %r15, %rdi
callq 0x15c8
pushq $0x1
popq %rdi
pushq $0x10
popq %rsi
callq 0x1130
movq %rax, %rbx
movl $0xa, (%rax)
movq (%r14), %rax
testq %rax, %rax
je 0x1ba5
movl (%rax), %edi
callq 0x2a50
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 0x1bc6
cmpl $0xf, %eax
je 0x1bd3
cmpl $0xa, %eax
jne 0x1c14
movq 0x8(%r8), %r15
jmp 0x1bf0
pushq $0x1
popq %rdi
pushq $0x7
popq %rsi
callq 0x1130
movl $0x6c756e28, (%rax)     # imm = 0x6C756E28
movl $0x296c6c, 0x3(%rax)    # imm = 0x296C6C
movq %rax, 0x8(%rbx)
jmp 0x1c5b
movq 0x8(%r8), %r8
leaq 0x2787(%rip), %rdx      # 0x4358
jmp 0x1c1b
movl 0x8(%r8), %ecx
leaq 0x273f(%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
pushq $0x1
popq %rdi
movq %rax, %rsi
callq 0x1130
movq %rax, %r14
movq %rax, %rdi
movq %r15, %rsi
movq %r12, %rdx
jmp 0x1c52
leaq 0x26bc(%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
pushq $0x1
popq %rdi
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
nopl (%rax)