// File: /workspace/github_c_makefile_star2_O2/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 0x23650
movq (%r14), %rax
movq 0x30(%rax), %rdx
movl 0x38(%rax), %ecx
pushq $0x31
jmp 0x23663
cmpq $0x0, 0x68(%rdi)
je 0x23674
movq (%r14), %rax
movq 0x30(%rax), %rdx
movl 0x38(%rax), %ecx
pushq $0x32
popq %rsi
movq %rbx, %rdi
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
jmp 0x1429e
movq %rsi, %r15
movb $0x1, 0x60(%rdi)
callq 0x2b774
movq %rax, %r12
movq 0x48(%r14), %rdi
movq %rax, %rsi
movq %rbx, %rdx
callq 0x2b781
cmpl $0x0, (%rbx)
jne 0x2374a
movq (%r14), %rdi
movq %r15, %rsi
movq %rbx, %rdx
callq 0x12e0e
cmpl $0x0, (%rbx)
jne 0x2374a
movq %r14, %rdi
xorl %esi, %esi
movq %rbx, %rdx
callq 0x33da7
cmpl $0x0, (%rbx)
jne 0x2374a
movq (%r14), %rsi
movq 0x68(%r14), %rdi
movq %rbx, %rdx
callq 0x2cb0c
cmpl $0x0, (%rbx)
jne 0x2374a
incq 0x78(%r14)
movq (%r14), %rax
movl 0x38(%rax), %ebp
movl (%r15), %eax
cmpl $0x1, %eax
je 0x236f4
testl %eax, %eax
jne 0x236fb
jmp 0x23710
cmpl $0x26, 0x8(%r15)
je 0x2372f
movq %r14, %rdi
movq %r15, %rsi
movq %rbx, %rdx
callq 0x14d03
cmpl $0x0, (%rbx)
je 0x236e6
jmp 0x2374a
movq (%r14), %rax
movq 0x30(%rax), %rdx
leaq 0x4a25a(%rip), %r8      # 0x6d978
pushq $0x1e
popq %rsi
pushq $0x7a
popq %r9
movq %rbx, %rdi
movl %ebp, %ecx
callq 0x142c0
movq 0x68(%r14), %rdx
movq 0x78(%r14), %rcx
pushq $0x2
popq %rsi
movq %r14, %rdi
movq %rbx, %r8
callq 0x4bbc0
cmpl $0x0, (%rbx)
je 0x2375b
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 0x237bf
movq 0x48(%r14), %rax
movq 0x78(%r14), %rsi
movq 0x78(%rax), %rdi
decq %rsi
movq %r12, %rdx
movq %rbx, %rcx
callq 0x2a6b8
movq 0x48(%r14), %rcx
movq %rax, 0x78(%rcx)
cmpl $0x0, (%rbx)
jne 0x2374a
decq 0x78(%r14)
movq 0x68(%r14), %rdi
movq %rbx, %rsi
callq 0x2cb44
cmpl $0x0, (%rbx)
jne 0x2374a
movq 0x48(%r14), %rax
movb $0x0, 0x88(%rax)
movq (%r14), %rdi
movq %r15, %rsi
movq %rbx, %rdx
callq 0x12e0e
jmp 0x2374a
movq 0x78(%rdi), %rax
testq %rax, %rax
je 0x237e2
movq 0x8(%rax), %rdx
pushq $0x45
popq %rsi
movq %rbx, %rcx
callq 0x2a997
cmpl $0x0, (%rbx)
jne 0x2374a
jmp 0x23768
cmpq 0x50(%r14), %rdi
je 0x237ff
pushq $0x1
popq %rsi
movq %r14, %rdi
movq %rbx, %rdx
callq 0x33da7
cmpl $0x0, (%rbx)
jne 0x23752
movq %r14, %rdi
movq %rbx, %rsi
callq 0x29bec
cmpl $0x0, (%rbx)
jne 0x23752
jmp 0x23768