// File: /workspace/github_c_makefile_star2_O0/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 %rbp
movq %rsp, %rbp
subq $0x30, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq -0x8(%rbp), %rax
movq 0x48(%rax), %rax
testb $0x1, 0x60(%rax)
je 0x36d35
movq -0x8(%rbp), %rax
movq 0x48(%rax), %rax
cmpq $0x0, 0x68(%rax)
jne 0x36d35
movq -0x10(%rbp), %rdi
movq -0x8(%rbp), %rax
movq (%rax), %rax
movq 0x30(%rax), %rdx
movq -0x8(%rbp), %rax
movq (%rax), %rax
movl 0x38(%rax), %ecx
movl $0x33, %esi
callq 0x158e0
jmp 0x36eda
movq -0x8(%rbp), %rdi
leaq 0x9daf8(%rip), %rax     # 0xd4838
movq (%rax), %rsi
movq -0x10(%rbp), %rdx
callq 0x47240
movq %rax, -0x30(%rbp)
movq -0x10(%rbp), %rax
cmpl $0x0, (%rax)
je 0x36d5e
jmp 0x36eda
movq -0x30(%rbp), %rax
movq 0x148(%rax), %rax
movq %rax, -0x28(%rbp)
movq -0x30(%rbp), %rdi
callq 0x36ee0
movq -0x10(%rbp), %rax
cmpl $0x0, (%rax)
je 0x36d84
jmp 0x36eda
movq -0x8(%rbp), %rax
movq 0x48(%rax), %rdi
callq 0x39940
movq %rax, -0x20(%rbp)
movq -0x8(%rbp), %rax
movq 0x48(%rax), %rax
cmpq $0x0, 0x78(%rax)
je 0x36ded
movq -0x8(%rbp), %rax
movq 0x48(%rax), %rax
movq 0x78(%rax), %rax
movq 0x8(%rax), %rax
movq %rax, -0x18(%rbp)
movq -0x8(%rbp), %rax
movq 0x48(%rax), %rdi
movq -0x10(%rbp), %r9
movq -0x28(%rbp), %rdx
movq -0x18(%rbp), %rcx
movq -0x20(%rbp), %r8
movl $0x43, %esi
callq 0x38360
movq -0x10(%rbp), %rax
cmpl $0x0, (%rax)
je 0x36de8
jmp 0x36eda
jmp 0x36ec5
movq -0x8(%rbp), %rax
movq 0x48(%rax), %rax
movq -0x8(%rbp), %rcx
cmpq 0x50(%rcx), %rax
je 0x36e14
movq -0x8(%rbp), %rax
movq 0x48(%rax), %rax
movq 0x8(%rax), %rax
movq 0x8(%rax), %rax
cmpl $0x8, (%rax)
jne 0x36e4b
movq -0x8(%rbp), %rax
movq 0x48(%rax), %rax
movq 0x98(%rax), %rax
movq %rax, -0x18(%rbp)
movq -0x8(%rbp), %rax
movq 0x48(%rax), %rdi
movq -0x10(%rbp), %r9
movq -0x28(%rbp), %rdx
movq -0x18(%rbp), %rcx
movq -0x20(%rbp), %r8
movl $0x43, %esi
callq 0x38360
jmp 0x36ec3
movq -0x8(%rbp), %rax
movq 0x48(%rax), %rdi
callq 0x39940
movq %rax, -0x18(%rbp)
movq -0x8(%rbp), %rax
movq 0x48(%rax), %rdi
movq -0x10(%rbp), %r9
movq -0x28(%rbp), %rdx
movq -0x18(%rbp), %rcx
movq -0x20(%rbp), %r8
movl $0x43, %esi
callq 0x38360
movq -0x10(%rbp), %rax
cmpl $0x0, (%rax)
je 0x36e89
jmp 0x36eda
movq -0x8(%rbp), %rax
movq 0x48(%rax), %rdi
movq -0x18(%rbp), %rsi
movq -0x10(%rbp), %rdx
callq 0x39960
movq -0x10(%rbp), %rax
cmpl $0x0, (%rax)
je 0x36ea9
jmp 0x36eda
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
callq 0x36c20
movq -0x10(%rbp), %rax
cmpl $0x0, (%rax)
je 0x36ec1
jmp 0x36eda
jmp 0x36ec3
jmp 0x36ec5
movq -0x8(%rbp), %rax
movq 0x48(%rax), %rdi
movq -0x20(%rbp), %rsi
movq -0x10(%rbp), %rdx
callq 0x39960
addq $0x30, %rsp
popq %rbp
retq