// File: /workspace/github_c_makefile_star2_O1/markdryan[P]subtilis/frontend/parser_mem.c
// Function: subtilis_parser_append_exp
subtilis_exp_t *subtilis_parser_append_exp(subtilis_parser_t *p,
					   subtilis_token_t *t,
					   subtilis_error_t *err)
{
	bool check_size;
	bool tmp;
	subtilis_exp_t *objs[3] = {NULL};
	subtilis_exp_t *retval = NULL;
	const subtilis_symbol_t *s;
	size_t i;

	prv_append_statement(p, t, objs, err);
	if (err->type != SUBTILIS_ERROR_OK)
		return NULL;

	retval = subtilis_type_if_dup(objs[0], err);
	if (err->type != SUBTILIS_ERROR_OK)
		goto cleanup;

	tmp = objs[0]->temporary;

	subtilis_type_if_append(p, objs[0], objs[1], objs[2], err);
	objs[0] = NULL;
	objs[1] = NULL;
	objs[2] = NULL;
	if (err->type != SUBTILIS_ERROR_OK)
		goto cleanup;

	/*
	 * If we're appending to a non-temporary variable with a ref
	 * count of 1 we  need to temporarily increase its reference
	 * count for the remainder of the current block.  This is to prevent
	 * a use after free error  which can happen when appending to an
	 * existing variable and then assigning the return value to that same
	 * variable.
	 *
	 * We could just push the existing reference, rather than making a copy
	 * and make some fake entry in the symbol table, with a size of 0, but
	 * this seems a bit hacky.  Would result in smaller code if we could get
	 * it to work though.
	 */

	if (subtilis_type_if_is_reference(&retval->type) && !tmp) {
		check_size = !subtilis_type_if_is_array(&retval->type);
		s = subtilis_symbol_table_insert_tmp(p->local_st, &retval->type,
						     NULL, err);
		if (err->type != SUBTILIS_ERROR_OK)
			goto cleanup;

		subtilis_reference_type_init_ref(p, SUBTILIS_IR_REG_LOCAL,
						 s->loc, retval->exp.ir_op.reg,
						 check_size, true, err);
		if (err->type != SUBTILIS_ERROR_OK)
			goto cleanup;

		subtilis_reference_type_push_reference(
		    p, &retval->type, SUBTILIS_IR_REG_LOCAL, s->loc, err);
		if (err->type != SUBTILIS_ERROR_OK)
			goto cleanup;
	}

	return retval;

cleanup:
	subtilis_exp_delete(retval);

	for (i = 0; i < 3; i++)
		subtilis_exp_delete(objs[i]);

	return NULL;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0x30, %rsp
movq %rdx, %r14
movq %rdi, %r15
xorps %xmm0, %xmm0
leaq 0x10(%rsp), %rdx
movaps %xmm0, (%rdx)
movq $0x0, 0x10(%rdx)
movq %r14, %rcx
callq 0x262f3
cmpl $0x0, (%r14)
je 0x26444
xorl %ebx, %ebx
jmp 0x264b2
movq 0x10(%rsp), %rdi
movq %r14, %rsi
callq 0x362d2
movq %rax, %rbx
cmpl $0x0, (%r14)
jne 0x26492
movq 0x10(%rsp), %rsi
movq 0x18(%rsp), %rdx
movq 0x158(%rsi), %r12
movq 0x20(%rsp), %rcx
movq %r15, %rdi
movq %r14, %r8
callq 0x36876
xorps %xmm0, %xmm0
movaps %xmm0, 0x10(%rsp)
movq $0x0, 0x20(%rsp)
cmpl $0x0, (%r14)
je 0x264c2
movq %rbx, %rdi
callq 0x2b4c3
xorl %ebx, %ebx
xorl %r14d, %r14d
movq 0x10(%rsp,%r14,8), %rdi
callq 0x2b4c3
incq %r14
cmpq $0x3, %r14
jne 0x2649f
movq %rbx, %rax
addq $0x30, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
movq %rbx, %rdi
callq 0x37833
testb %al, %al
je 0x264b2
testq %r12, %r12
jne 0x264b2
movq %rbx, %rdi
callq 0x377f7
movl %eax, %ebp
movq 0x68(%r15), %rdi
movq %rbx, %rsi
xorl %edx, %edx
movq %r14, %rcx
callq 0x2ea12
cmpl $0x0, (%r14)
jne 0x26492
movq %rax, %r12
xorb $0x1, %bpl
movq (%rax), %rdx
movq 0x148(%rbx), %rcx
movq %r14, (%rsp)
movzbl %bpl, %r8d
movl $0x2, %esi
movq %r15, %rdi
movl $0x1, %r9d
callq 0x4ce10
cmpl $0x0, (%r14)
jne 0x26492
movq (%r12), %rcx
movl $0x2, %edx
movq %r15, %rdi
movq %rbx, %rsi
movq %r14, %r8
callq 0x4d4ea
cmpl $0x0, (%r14)
jne 0x26492
jmp 0x264b2