// File: /workspace/github_c_makefile_star2_O3/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 0x24674
movq (%r14), %rax
movq 0x30(%rax), %rdx
movl 0x38(%rax), %ecx
movq %rbx, %rdi
movl $0x31, %esi
jmp 0x2468d
cmpq $0x0, 0x68(%rdi)
je 0x2469a
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 0x145a4
movq %rsi, %r15
movb $0x1, 0x60(%rdi)
callq 0x2cc99
movq %rax, %r12
movq 0x48(%r14), %rdi
movq %rax, %rsi
movq %rbx, %rdx
callq 0x2cca6
cmpl $0x0, (%rbx)
jne 0x24776
movq (%r14), %rdi
movq %r15, %rsi
movq %rbx, %rdx
callq 0x12edc
cmpl $0x0, (%rbx)
jne 0x24776
movq %r14, %rdi
xorl %esi, %esi
movq %rbx, %rdx
callq 0x35d3d
cmpl $0x0, (%rbx)
jne 0x24776
movq (%r14), %rsi
movq 0x68(%r14), %rdi
movq %rbx, %rdx
callq 0x2e306
cmpl $0x0, (%rbx)
jne 0x24776
incq 0x78(%r14)
movq (%r14), %rax
movl 0x38(%rax), %ebp
movl (%r15), %eax
cmpl $0x1, %eax
je 0x2471a
testl %eax, %eax
jne 0x24721
jmp 0x24736
cmpl $0x26, 0x8(%r15)
je 0x24759
movq %r14, %rdi
movq %r15, %rsi
movq %rbx, %rdx
callq 0x15089
cmpl $0x0, (%rbx)
je 0x2470c
jmp 0x24776
movq (%r14), %rax
movq 0x30(%rax), %rdx
leaq 0x4f27c(%rip), %r8      # 0x739c0
movq %rbx, %rdi
movl $0x1e, %esi
movl %ebp, %ecx
movl $0x7a, %r9d
callq 0x145c8
movq 0x68(%r14), %rdx
movq 0x78(%r14), %rcx
movl $0x2, %esi
movq %r14, %rdi
movq %rbx, %r8
callq 0x4e90a
cmpl $0x0, (%rbx)
je 0x24787
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 0x247eb
movq 0x48(%r14), %rax
movq 0x78(%r14), %rsi
movq 0x78(%rax), %rdi
decq %rsi
movq %r12, %rdx
movq %rbx, %rcx
callq 0x2bb24
movq 0x48(%r14), %rcx
movq %rax, 0x78(%rcx)
cmpl $0x0, (%rbx)
jne 0x24776
decq 0x78(%r14)
movq 0x68(%r14), %rdi
movq %rbx, %rsi
callq 0x2e342
cmpl $0x0, (%rbx)
jne 0x24776
movq 0x48(%r14), %rax
movb $0x0, 0x88(%rax)
movq (%r14), %rdi
movq %r15, %rsi
movq %rbx, %rdx
callq 0x12edc
jmp 0x24776
movq 0x78(%rdi), %rax
testq %rax, %rax
je 0x24810
movq 0x8(%rax), %rdx
movl $0x45, %esi
movq %rbx, %rcx
callq 0x2be1f
cmpl $0x0, (%rbx)
jne 0x24776
jmp 0x24794
cmpq 0x50(%r14), %rdi
je 0x2482f
movq %r14, %rdi
movl $0x1, %esi
movq %rbx, %rdx
callq 0x35d3d
cmpl $0x0, (%rbx)
jne 0x2477e
movq %r14, %rdi
movq %rbx, %rsi
callq 0x2afc0
cmpl $0x0, (%rbx)
jne 0x2477e
jmp 0x24794