// File: /workspace/github_c_makefile_star2_O3/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 0x2b03f
cmpq $0x0, 0x68(%rax)
je 0x2b077
leaq 0x7b132(%rip), %rax     # 0xa6178
movq (%rax), %rsi
movq %r14, %rdi
movq %rbx, %rdx
callq 0x35c45
cmpl $0x0, (%rbx)
jne 0x2b06d
movq 0x148(%rax), %r12
movq %rax, %rdi
callq 0x2b166
cmpl $0x0, (%rbx)
je 0x2b097
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
retq
movq (%r14), %rax
movq 0x30(%rax), %rdx
movl 0x38(%rax), %ecx
movq %rbx, %rdi
movl $0x33, %esi
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
jmp 0x145a4
movq 0x48(%r14), %rdi
callq 0x2cc99
movq %rax, %r15
movq 0x48(%r14), %rdi
movq 0x78(%rdi), %rax
testq %rax, %rax
je 0x2b0ce
movq 0x8(%rax), %rcx
movl $0x43, %esi
movq %r12, %rdx
movq %r15, %r8
movq %rbx, %r9
callq 0x2bd42
cmpl $0x0, (%rbx)
jne 0x2b06d
jmp 0x2b0fb
cmpq 0x50(%r14), %rdi
je 0x2b0e1
movq 0x8(%rdi), %rax
movq 0x8(%rax), %rax
cmpl $0x8, (%rax)
jne 0x2b113
movq 0x98(%rdi), %rcx
movl $0x43, %esi
movq %r12, %rdx
movq %r15, %r8
movq %rbx, %r9
callq 0x2bd42
movq 0x48(%r14), %rdi
movq %r15, %rsi
movq %rbx, %rdx
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
jmp 0x2cca6
callq 0x2cc99
movq %rax, %r13
movq 0x48(%r14), %rdi
movl $0x43, %esi
movq %r12, %rdx
movq %rax, %rcx
movq %r15, %r8
movq %rbx, %r9
callq 0x2bd42
cmpl $0x0, (%rbx)
jne 0x2b06d
movq 0x48(%r14), %rdi
movq %r13, %rsi
movq %rbx, %rdx
callq 0x2cca6
cmpl $0x0, (%rbx)
jne 0x2b06d
movq %r14, %rdi
movq %rbx, %rsi
callq 0x2afc0
jmp 0x2b0c7