// File: /workspace/github_c_makefile_star2_O3/qpfiffer[P]lair/src/lair_std.c
// Function: lair_builtin_operator_plus
const struct _lair_type *_lair_builtin_operator_plus(LAIR_FUNCTION_SIG) {
	check(r, argc == 2, ERR_RUNTIME, "Incorrect number of arguments to `+` function.");
	check(r, argv[0] != NULL, ERR_RUNTIME, "Argument to `+` function was NULL.");
	check(r, argv[1] != NULL, ERR_RUNTIME, "Argument to `+` function was NULL.");
	check(r, argv[0]->type == argv[1]->type, ERR_RUNTIME, "Cannot add variables of different types together.");

	/* We already know (probably) that the types are the same. */
	const LAIR_TOKEN first_arg_type = argv[0]->type;
	switch (first_arg_type) {
		/* Integer addition. */
		case LR_NUM: {
			struct _lair_type _stack = {
				.type = LR_NUM,
				.value = {
					.num = argv[0]->value.num + argv[1]->value.num
				}
			};
			struct _lair_type *to_return = calloc(1, sizeof(struct _lair_type));
			memcpy(to_return, &_stack, sizeof(struct _lair_type));
			return to_return;
		}
		/* Append two strings together. */
		case LR_STRING: {
			const char *str0 = argv[0]->value.str;
			const char *str1 = argv[1]->value.str;
			const size_t str_siz = strlen(str0) + strlen(str1);

			struct _lair_type _stack = {
				.type = LR_STRING,
				.value = {
					.str = calloc(1, str_siz)
				}
			};

			struct _lair_type *to_return = calloc(1, sizeof(struct _lair_type) + 1);
			memcpy(_stack.value.str, str0, strlen(str0));
			memcpy(_stack.value.str + strlen(str0), str1, strlen(str1));
			memcpy(to_return, &_stack, sizeof(struct _lair_type));

			return to_return;
		}
		default:
			throw_exception(r, ERR_RUNTIME, "Don't know how to add these things together.");
	}
	return NULL;
}

// Assembly:
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
movq %rdx, %rbx
movq %rdi, %r14
xorl %eax, %eax
cmpl $0x2, %esi
sete %al
leaq 0x298a(%rip), %rcx      # 0x40b8
movl %eax, %esi
movl $0x2, %edx
callq 0x1608
xorl %esi, %esi
cmpq $0x0, (%rbx)
setne %sil
leaq 0x299c(%rip), %r15      # 0x40e7
movq %r14, %rdi
movl $0x2, %edx
movq %r15, %rcx
callq 0x1608
xorl %esi, %esi
cmpq $0x0, 0x8(%rbx)
setne %sil
movq %r14, %rdi
movl $0x2, %edx
movq %r15, %rcx
callq 0x1608
movq (%rbx), %rax
movq 0x8(%rbx), %rcx
movl (%rax), %eax
xorl %esi, %esi
cmpl (%rcx), %eax
sete %sil
leaq 0x297c(%rip), %rcx      # 0x410a
movq %r14, %rdi
movl $0x2, %edx
callq 0x1608
movq (%rbx), %rax
movl (%rax), %ecx
cmpl $0xa, %ecx
je 0x17d8
cmpl $0xf, %ecx
jne 0x1857
movq 0x8(%rbx), %rcx
movl 0x8(%rcx), %ebx
addl 0x8(%rax), %ebx
movl $0x1, %edi
movl $0x10, %esi
callq 0x1130
movq %rax, %r14
movl $0xf, (%rax)
movl %ebx, 0x8(%rax)
jmp 0x186e
movq 0x8(%rax), %r15
movq 0x8(%rbx), %rax
movq 0x8(%rax), %rbx
movq %r15, %rdi
callq 0x1080
movq %rax, %r13
movq %rbx, %rdi
callq 0x1080
leaq (%rax,%r13), %rsi
movl $0x1, %edi
callq 0x1130
movq %rax, %r12
movl $0x1, %edi
movl $0x11, %esi
callq 0x1130
movq %rax, %r14
movq %r12, %rdi
movq %r15, %rsi
movq %r13, %rdx
callq 0x1160
movq %r15, %rdi
callq 0x1080
leaq (%rax,%r12), %r15
movq %rbx, %rdi
callq 0x1080
movq %r15, %rdi
movq %rbx, %rsi
movq %rax, %rdx
callq 0x1160
movl $0xa, (%r14)
movq %r12, 0x8(%r14)
jmp 0x186e
leaq 0x28de(%rip), %rdx      # 0x413c
movq %r14, %rdi
movl $0x2, %esi
callq 0x1630
xorl %r14d, %r14d
movq %r14, %rax
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
retq