// File: /workspace/github_c_makefile_star2_O0/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 %rbp
movq %rsp, %rbp
subq $0xb0, %rsp
movq %rdi, -0x10(%rbp)
movl %esi, -0x14(%rbp)
movq %rdx, -0x20(%rbp)
movq -0x10(%rbp), %rdi
movl -0x14(%rbp), %eax
subl $0x2, %eax
sete %al
movzbl %al, %esi
leaq 0x465c(%rip), %rcx      # 0x60a9
movl $0x2, %edx
movl %edx, -0x78(%rbp)
callq 0x1830
movl -0x78(%rbp), %edx
movq -0x10(%rbp), %rdi
movq -0x20(%rbp), %rax
movq (%rax), %rax
testq %rax, %rax
setne %al
movzbl %al, %esi
leaq 0x4660(%rip), %rcx      # 0x60d8
movq %rcx, -0x80(%rbp)
callq 0x1830
movq -0x80(%rbp), %rcx
movl -0x78(%rbp), %edx
movq -0x10(%rbp), %rdi
movq -0x20(%rbp), %rax
movq 0x8(%rax), %rax
testq %rax, %rax
setne %al
movzbl %al, %esi
callq 0x1830
movl -0x78(%rbp), %edx
movq -0x10(%rbp), %rdi
movq -0x20(%rbp), %rcx
movq (%rcx), %rax
movq 0x8(%rcx), %rcx
movl (%rax), %eax
movl (%rcx), %ecx
subl %ecx, %eax
sete %al
movzbl %al, %esi
leaq 0x4634(%rip), %rcx      # 0x60fb
callq 0x1830
movq -0x20(%rbp), %rax
movq (%rax), %rax
movl (%rax), %eax
movl %eax, -0x24(%rbp)
movl -0x24(%rbp), %eax
movl %eax, -0x74(%rbp)
subl $0xa, %eax
je 0x1b45
jmp 0x1ae5
movl -0x74(%rbp), %eax
subl $0xf, %eax
jne 0x1c5e
jmp 0x1af3
movl $0xf, -0x38(%rbp)
movq -0x20(%rbp), %rax
movq (%rax), %rax
movl 0x8(%rax), %eax
movq -0x20(%rbp), %rcx
movq 0x8(%rcx), %rcx
addl 0x8(%rcx), %eax
movl %eax, -0x30(%rbp)
movl $0x1, %edi
movl $0x10, %esi
callq 0x1110
movq %rax, -0x40(%rbp)
movq -0x40(%rbp), %rax
movq -0x38(%rbp), %rcx
movq %rcx, (%rax)
movq -0x30(%rbp), %rcx
movq %rcx, 0x8(%rax)
movq -0x40(%rbp), %rax
movq %rax, -0x8(%rbp)
jmp 0x1c7b
movq -0x20(%rbp), %rax
movq (%rax), %rax
movq 0x8(%rax), %rax
movq %rax, -0x48(%rbp)
movq -0x20(%rbp), %rax
movq 0x8(%rax), %rax
movq 0x8(%rax), %rax
movq %rax, -0x50(%rbp)
movq -0x48(%rbp), %rdi
callq 0x1060
movq %rax, -0xb0(%rbp)
movq -0x50(%rbp), %rdi
callq 0x1060
movq %rax, %rcx
movq -0xb0(%rbp), %rax
addq %rcx, %rax
movq %rax, -0x58(%rbp)
movl $0xa, -0x68(%rbp)
movq -0x58(%rbp), %rsi
movl $0x1, %edi
callq 0x1110
movq %rax, -0x60(%rbp)
movl $0x1, %edi
movl $0x11, %esi
callq 0x1110
movq %rax, -0x70(%rbp)
movq -0x60(%rbp), %rax
movq %rax, -0xa8(%rbp)
movq -0x48(%rbp), %rax
movq %rax, -0xa0(%rbp)
movq -0x48(%rbp), %rdi
callq 0x1060
movq -0xa8(%rbp), %rdi
movq -0xa0(%rbp), %rsi
movq %rax, %rdx
callq 0x1140
movq -0x60(%rbp), %rax
movq %rax, -0x98(%rbp)
movq -0x48(%rbp), %rdi
callq 0x1060
movq %rax, %rcx
movq -0x98(%rbp), %rax
addq %rcx, %rax
movq %rax, -0x90(%rbp)
movq -0x50(%rbp), %rax
movq %rax, -0x88(%rbp)
movq -0x50(%rbp), %rdi
callq 0x1060
movq -0x90(%rbp), %rdi
movq -0x88(%rbp), %rsi
movq %rax, %rdx
callq 0x1140
movq -0x70(%rbp), %rax
movq -0x68(%rbp), %rcx
movq %rcx, (%rax)
movq -0x60(%rbp), %rcx
movq %rcx, 0x8(%rax)
movq -0x70(%rbp), %rax
movq %rax, -0x8(%rbp)
jmp 0x1c7b
movq -0x10(%rbp), %rdi
movl $0x2, %esi
leaq 0x44bf(%rip), %rdx      # 0x612d
callq 0x1870
movq $0x0, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0xb0, %rsp
popq %rbp
retq
nopl (%rax,%rax)