// File: /workspace/github_c_makefile_star2_O1/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 0x2b39c
cmpq $0x0, 0x68(%rax)
je 0x2b3d4
leaq 0x7add5(%rip), %rax     # 0xa6178
movq (%rax), %rsi
movq %r14, %rdi
movq %rbx, %rdx
callq 0x35d95
cmpl $0x0, (%rbx)
jne 0x2b3ca
movq 0x148(%rax), %r12
movq %rax, %rdi
callq 0x2b4c3
cmpl $0x0, (%rbx)
je 0x2b3f4
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 0x145f4
movq 0x48(%r14), %rdi
callq 0x2d00a
movq %rax, %r15
movq 0x48(%r14), %rdi
movq 0x78(%rdi), %rax
testq %rax, %rax
je 0x2b42b
movq 0x8(%rax), %rcx
movl $0x43, %esi
movq %r12, %rdx
movq %r15, %r8
movq %rbx, %r9
callq 0x2c0c2
cmpl $0x0, (%rbx)
jne 0x2b3ca
jmp 0x2b458
cmpq 0x50(%r14), %rdi
je 0x2b43e
movq 0x8(%rdi), %rax
movq 0x8(%rax), %rax
cmpl $0x8, (%rax)
jne 0x2b470
movq 0x98(%rdi), %rcx
movl $0x43, %esi
movq %r12, %rdx
movq %r15, %r8
movq %rbx, %r9
callq 0x2c0c2
movq 0x48(%r14), %rdi
movq %r15, %rsi
movq %rbx, %rdx
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
jmp 0x2d017
callq 0x2d00a
movq %rax, %r13
movq 0x48(%r14), %rdi
movl $0x43, %esi
movq %r12, %rdx
movq %rax, %rcx
movq %r15, %r8
movq %rbx, %r9
callq 0x2c0c2
cmpl $0x0, (%rbx)
jne 0x2b3ca
movq 0x48(%r14), %rdi
movq %r13, %rsi
movq %rbx, %rdx
callq 0x2d017
cmpl $0x0, (%rbx)
jne 0x2b3ca
movq %r14, %rdi
movq %rbx, %rsi
callq 0x2b31d
jmp 0x2b424