// File: /workspace/github_c_makefile_star2_O1/markdryan[P]subtilis/frontend/parser_error.c
// Function: subtilis_parser_onerror
void subtilis_parser_onerror(subtilis_parser_t *p, subtilis_token_t *t,
			     subtilis_error_t *err)
{
	subtilis_ir_operand_t handler_label;
	subtilis_ir_operand_t target_label;
	unsigned int start;
	subtilis_ir_operand_t var_reg;

	if (p->current->in_error_handler) {
		subtilis_error_set_nested_handler(err, p->l->stream->name,
						  p->l->line);
		return;
	}

	if (p->current->try_depth > 0) {
		subtilis_error_set_handler_in_try(err, p->l->stream->name,
						  p->l->line);
		return;
	}

	p->current->in_error_handler = true;
	handler_label.label = subtilis_ir_section_new_label(p->current);
	subtilis_ir_section_add_label(p->current, handler_label.label, err);
	if (err->type != SUBTILIS_ERROR_OK)
		goto cleanup;

	subtilis_lexer_get(p->l, t, err);
	if (err->type != SUBTILIS_ERROR_OK)
		goto cleanup;

	/*
	 * The error flag needs to be clear when we're inside an error
	 * handler.  Otherwise and procedures or functions call in that
	 * handler may appear to have failed when they return.
	 */

	subtilis_var_set_eflag(p, false, err);
	if (err->type != SUBTILIS_ERROR_OK)
		goto cleanup;

	subtilis_symbol_table_level_up(p->local_st, p->l, err);
	if (err->type != SUBTILIS_ERROR_OK)
		goto cleanup;

	p->level++;
	start = p->l->line;
	while (t->type != SUBTILIS_TOKEN_EOF) {
		if ((t->type == SUBTILIS_TOKEN_KEYWORD) &&
		    (t->tok.keyword.type == SUBTILIS_KEYWORD_ENDERROR))
			break;
		subtilis_parser_statement(p, t, err);
		if (err->type != SUBTILIS_ERROR_OK)
			goto cleanup;
	}

	if (t->type == SUBTILIS_TOKEN_EOF)
		subtilis_error_set_compund_not_term(err, p->l->stream->name,
						    start);

	var_reg.reg = SUBTILIS_IR_REG_LOCAL;
	subtilis_reference_deallocate_refs(p, var_reg, p->local_st, p->level,
					   err);
	if (err->type != SUBTILIS_ERROR_OK)
		goto cleanup;

	if (!p->current->endproc) {
		if (!p->current->handler_list) {
			if (p->current != p->main) {
				subtilis_var_set_eflag(p, true, err);
				if (err->type != SUBTILIS_ERROR_OK)
					return;
			}
			subtilis_exp_return_default_value(p, err);
			if (err->type != SUBTILIS_ERROR_OK)
				return;
		} else {
			target_label.label = p->current->handler_list->label;
			subtilis_ir_section_add_instr_no_reg(
			    p->current, SUBTILIS_OP_INSTR_JMP, target_label,
			    err);
			if (err->type != SUBTILIS_ERROR_OK)
				goto cleanup;
		}
	}

	p->current->handler_list = subtilis_handler_list_update(
	    p->current->handler_list, p->level - 1, handler_label.label, err);
	if (err->type != SUBTILIS_ERROR_OK)
		goto cleanup;

	p->level--;
	subtilis_symbol_table_level_down(p->local_st, err);
	if (err->type != SUBTILIS_ERROR_OK)
		goto cleanup;
	p->current->endproc = false;

	subtilis_lexer_get(p->l, t, err);

cleanup:
	p->current->in_error_handler = false;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
movq %rdx, %rbx
movq %rdi, %r14
movq 0x48(%rdi), %rdi
cmpb $0x1, 0x60(%rdi)
jne 0x24778
movq (%r14), %rax
movq 0x30(%rax), %rdx
movl 0x38(%rax), %ecx
movq %rbx, %rdi
movl $0x31, %esi
jmp 0x24791
cmpq $0x0, 0x68(%rdi)
je 0x2479e
movq (%r14), %rax
movq 0x30(%rax), %rdx
movl 0x38(%rax), %ecx
movq %rbx, %rdi
movl $0x32, %esi
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
jmp 0x145f4
movq %rsi, %r15
movb $0x1, 0x60(%rdi)
callq 0x2d00a
movq %rax, %r12
movq 0x48(%r14), %rdi
movq %rax, %rsi
movq %rbx, %rdx
callq 0x2d017
cmpl $0x0, (%rbx)
jne 0x2487e
movq (%r14), %rdi
movq %r15, %rsi
movq %rbx, %rdx
callq 0x12eda
cmpl $0x0, (%rbx)
jne 0x2487e
movq %r14, %rdi
xorl %esi, %esi
movq %rbx, %rdx
callq 0x35e8d
cmpl $0x0, (%rbx)
jne 0x2487e
movq (%r14), %rsi
movq 0x68(%r14), %rdi
movq %rbx, %rdx
callq 0x2e62b
cmpl $0x0, (%rbx)
jne 0x2487e
incq 0x78(%r14)
movq (%r14), %rax
movl 0x38(%rax), %ebp
movl (%r15), %eax
cmpl $0x1, %eax
je 0x2481e
testl %eax, %eax
jne 0x24825
jmp 0x2483e
cmpl $0x26, 0x8(%r15)
je 0x2483a
movq %r14, %rdi
movq %r15, %rsi
movq %rbx, %rdx
callq 0x150d5
cmpl $0x0, (%rbx)
je 0x24810
jmp 0x2487e
testl %eax, %eax
jne 0x24861
movq (%r14), %rax
movq 0x30(%rax), %rdx
leaq 0x4f154(%rip), %r8      # 0x739a0
movq %rbx, %rdi
movl $0x1e, %esi
movl %ebp, %ecx
movl $0x7a, %r9d
callq 0x14618
movq 0x68(%r14), %rdx
movq 0x78(%r14), %rcx
movl $0x2, %esi
movq %r14, %rdi
movq %rbx, %r8
callq 0x4e94e
cmpl $0x0, (%rbx)
je 0x2488f
movq 0x48(%r14), %rax
movb $0x0, 0x60(%rax)
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
movq 0x48(%r14), %rdi
cmpb $0x0, 0x88(%rdi)
je 0x248f3
movq 0x48(%r14), %rax
movq 0x78(%r14), %rsi
movq 0x78(%rax), %rdi
decq %rsi
movq %r12, %rdx
movq %rbx, %rcx
callq 0x2bea7
movq 0x48(%r14), %rcx
movq %rax, 0x78(%rcx)
cmpl $0x0, (%rbx)
jne 0x2487e
decq 0x78(%r14)
movq 0x68(%r14), %rdi
movq %rbx, %rsi
callq 0x2e667
cmpl $0x0, (%rbx)
jne 0x2487e
movq 0x48(%r14), %rax
movb $0x0, 0x88(%rax)
movq (%r14), %rdi
movq %r15, %rsi
movq %rbx, %rdx
callq 0x12eda
jmp 0x2487e
movq 0x78(%rdi), %rax
testq %rax, %rax
je 0x24918
movq 0x8(%rax), %rdx
movl $0x45, %esi
movq %rbx, %rcx
callq 0x2c19f
cmpl $0x0, (%rbx)
jne 0x2487e
jmp 0x2489c
cmpq 0x50(%r14), %rdi
je 0x24937
movq %r14, %rdi
movl $0x1, %esi
movq %rbx, %rdx
callq 0x35e8d
cmpl $0x0, (%rbx)
jne 0x24886
movq %r14, %rdi
movq %rbx, %rsi
callq 0x2b31d
cmpl $0x0, (%rbx)
jne 0x24886
jmp 0x2489c