// File: /workspace/github_c_makefile_star2_O2/markdryan[P]subtilis/frontend/expression.c
// Function: subtilis_exp_handle_errors
void subtilis_exp_handle_errors(subtilis_parser_t *p, subtilis_error_t *err)
{
	subtilis_ir_operand_t error_label;
	subtilis_ir_operand_t ok_label;
	subtilis_ir_operand_t op1;
	subtilis_exp_t *ecode;

	if (p->current->in_error_handler && (p->current->try_depth == 0)) {
		/*
		 * We're in an error handler and not inside a try block.
		 * This is an error.  Implicit errors are not allowed
		 * in error handlers.
		 */

		subtilis_error_set_error_handler(err, p->l->stream->name,
						 p->l->line);
		return;
	}

	ecode = subtilis_var_lookup_var(p, subtilis_eflag_hidden_var, err);
	if (err->type != SUBTILIS_ERROR_OK)
		return;
	op1.reg = ecode->exp.ir_op.reg;
	subtilis_exp_delete(ecode);
	if (err->type != SUBTILIS_ERROR_OK)
		return;

	ok_label.label = subtilis_ir_section_new_label(p->current);

	if (p->current->handler_list) {
		/*
		 * We're not in an error handler but there is one.
		 * Let's transfer control to it.
		 */

		error_label.label = p->current->handler_list->label;
		subtilis_ir_section_add_instr_reg(p->current,
						  SUBTILIS_OP_INSTR_JMPC, op1,
						  error_label, ok_label, err);
		if (err->type != SUBTILIS_ERROR_OK)
			return;
	} else if ((p->current == p->main) ||
		   (p->current->type->type.params.fn.ret_val->type ==
		    SUBTILIS_TYPE_VOID)) {
		/*
		 * There's no error handler so we need to return.  We can jump
		 * straight to the exit code for the procedure as theres no
		 * return value to zero.
		 */

		error_label.label = p->current->end_label;
		subtilis_ir_section_add_instr_reg(p->current,
						  SUBTILIS_OP_INSTR_JMPC, op1,
						  error_label, ok_label, err);
	} else {
		/*
		 * There's no error handler so we need to return.
		 */

		error_label.label = subtilis_ir_section_new_label(p->current);

		subtilis_ir_section_add_instr_reg(p->current,
						  SUBTILIS_OP_INSTR_JMPC, op1,
						  error_label, ok_label, err);
		if (err->type != SUBTILIS_ERROR_OK)
			return;

		subtilis_ir_section_add_label(p->current, error_label.label,
					      err);
		if (err->type != SUBTILIS_ERROR_OK)
			return;

		subtilis_exp_return_default_value(p, err);
		if (err->type != SUBTILIS_ERROR_OK)
			return;
	}

	subtilis_ir_section_add_label(p->current, ok_label.label, err);
}

// Assembly:
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
movq %rsi, %rbx
movq %rdi, %r14
movq 0x48(%rdi), %rax
cmpb $0x1, 0x60(%rax)
jne 0x29c69
cmpq $0x0, 0x68(%rax)
je 0x29ca1
leaq 0x7c508(%rip), %rax     # 0xa6178
movq (%rax), %rsi
movq %r14, %rdi
movq %rbx, %rdx
callq 0x33cb3
cmpl $0x0, (%rbx)
jne 0x29c97
movq 0x148(%rax), %r12
movq %rax, %rdi
callq 0x29d88
cmpl $0x0, (%rbx)
je 0x29cbf
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
retq
movq (%r14), %rax
movq 0x30(%rax), %rdx
movl 0x38(%rax), %ecx
pushq $0x33
popq %rsi
movq %rbx, %rdi
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
jmp 0x1429e
movq 0x48(%r14), %rdi
callq 0x2b774
movq %rax, %r15
movq 0x48(%r14), %rdi
movq 0x78(%rdi), %rax
testq %rax, %rax
je 0x29cf4
movq 0x8(%rax), %rcx
pushq $0x43
popq %rsi
movq %r12, %rdx
movq %r15, %r8
movq %rbx, %r9
callq 0x2a8c1
cmpl $0x0, (%rbx)
jne 0x29c97
jmp 0x29d1f
cmpq 0x50(%r14), %rdi
je 0x29d07
movq 0x8(%rdi), %rax
movq 0x8(%rax), %rax
cmpl $0x8, (%rax)
jne 0x29d37
movq 0x98(%rdi), %rcx
pushq $0x43
popq %rsi
movq %r12, %rdx
movq %r15, %r8
movq %rbx, %r9
callq 0x2a8c1
movq 0x48(%r14), %rdi
movq %r15, %rsi
movq %rbx, %rdx
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
jmp 0x2b781
callq 0x2b774
movq %rax, %r13
movq 0x48(%r14), %rdi
pushq $0x43
popq %rsi
movq %r12, %rdx
movq %rax, %rcx
movq %r15, %r8
movq %rbx, %r9
callq 0x2a8c1
cmpl $0x0, (%rbx)
jne 0x29c97
movq 0x48(%r14), %rdi
movq %r13, %rsi
movq %rbx, %rdx
callq 0x2b781
cmpl $0x0, (%rbx)
jne 0x29c97
movq %r14, %rdi
movq %rbx, %rsi
callq 0x29bec
jmp 0x29ced