// File: /workspace/github_c_makefile_star2_O3/markdryan[P]subtilis/frontend/parser.c
// Function: prv_check_free_mem
static void prv_check_free_mem(subtilis_parser_t *p, subtilis_token_t *t,
			       subtilis_error_t *err)
{
	size_t reg;
	subtilis_ir_operand_t msg_ptr;
	subtilis_ir_operand_t msg_len_reg;
	subtilis_ir_operand_t msg_len;
	subtilis_ir_operand_t leak_label;
	subtilis_ir_operand_t no_leak_label;
	const char *msg = " BYTES LEAKED!";
	subtilis_exp_t *old_value = NULL;
	subtilis_exp_t *new_value = NULL;

	if (!p->settings.check_mem_leaks)
		return;

	leak_label.label = subtilis_ir_section_new_label(p->current);
	no_leak_label.label = subtilis_ir_section_new_label(p->current);

	old_value =
	    subtilis_var_lookup_var(p, subtilis_heap_free_on_startup_var, err);
	if (err->type != SUBTILIS_ERROR_OK)
		return;

	reg = subtilis_ir_section_add_instr1(p->current,
					     SUBTILIS_OP_INSTR_HEAP_FREE, err);
	if (err->type != SUBTILIS_ERROR_OK)
		goto cleanup;

	new_value = subtilis_exp_new_int32_var(reg, err);
	if (err->type != SUBTILIS_ERROR_OK)
		goto cleanup;

	old_value = subtilis_type_if_sub(p, old_value, new_value, err);
	new_value = NULL;
	if (err->type != SUBTILIS_ERROR_OK)
		goto cleanup;

	subtilis_ir_section_add_instr_reg(p->current, SUBTILIS_OP_INSTR_JMPC,
					  old_value->exp.ir_op, leak_label,
					  no_leak_label, err);
	if (err->type != SUBTILIS_ERROR_OK)
		goto cleanup;

	subtilis_ir_section_add_label(p->current, leak_label.label, err);
	if (err->type != SUBTILIS_ERROR_OK)
		goto cleanup;

	/*
	 * Any error here would cause the program to loop and possibly never
	 * end.  This is a debug feature but still.  We know dectostr will
	 * not generate an error but we need to ensure backends with native
	 * support for this function won't either.
	 */

	p->settings.ignore_graphics_errors = true;

	subtilis_type_if_print(p, old_value, err);
	old_value = NULL;
	if (err->type != SUBTILIS_ERROR_OK)
		return;

	msg_len.integer = strlen(msg);
	msg_ptr.reg =
	    subtilis_string_type_lca_const(p, msg, msg_len.integer, err);
	if (err->type != SUBTILIS_ERROR_OK)
		return;

	msg_len_reg.reg = subtilis_ir_section_add_instr2(
	    p->current, SUBTILIS_OP_INSTR_MOVI_I32, msg_len, err);
	if (err->type != SUBTILIS_ERROR_OK)
		return;

	subtilis_ir_section_add_instr_no_reg2(
	    p->current, SUBTILIS_OP_INSTR_PRINT_STR, msg_ptr, msg_len_reg, err);
	if (err->type != SUBTILIS_ERROR_OK)
		return;

	subtilis_ir_section_add_label(p->current, no_leak_label.label, err);

cleanup:

	subtilis_exp_delete(old_value);
	subtilis_exp_delete(new_value);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
cmpb $0x1, 0xba(%rdi)
jne 0x156ad
movq %rsi, %rbx
movq %rdi, %r14
movq 0x48(%rdi), %rdi
callq 0x2cc99
movq %rax, %r13
movq 0x48(%r14), %rdi
callq 0x2cc99
movq %rax, %r15
leaq 0x90aee(%rip), %rax     # 0xa6188
movq (%rax), %rsi
movq %r14, %rdi
movq %rbx, %rdx
callq 0x35c45
cmpl $0x0, (%rbx)
je 0x156bc
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %r12
movq 0x48(%r14), %rdi
movl $0x87, %esi
movq %rbx, %rdx
callq 0x2be13
cmpl $0x0, (%rbx)
je 0x156d9
xorl %ebp, %ebp
jmp 0x156eb
movl %eax, %edi
movq %rbx, %rsi
callq 0x2b71f
movq %rax, %rbp
cmpl $0x0, (%rbx)
je 0x15709
movq %r12, %rdi
callq 0x2b166
movq %rbp, %rdi
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x2b166
movq %r14, %rdi
movq %r12, %rsi
movq %rbp, %rdx
movq %rbx, %rcx
callq 0x36de4
movq %rax, %r12
cmpl $0x0, (%rbx)
jne 0x156d5
movq 0x48(%r14), %rdi
movq 0x148(%r12), %rdx
movl $0x43, %esi
movq %r13, %rcx
movq %r15, %r8
movq %rbx, %r9
callq 0x2bd42
cmpl $0x0, (%rbx)
jne 0x156d5
movq 0x48(%r14), %rdi
movq %r13, %rsi
movq %rbx, %rdx
callq 0x2cca6
cmpl $0x0, (%rbx)
jne 0x156d5
movb $0x1, 0xb9(%r14)
movq %r14, %rdi
movq %r12, %rsi
movq %rbx, %rdx
callq 0x375fe
cmpl $0x0, (%rbx)
jne 0x156ad
leaq 0x5dd25(%rip), %rsi     # 0x734a9
movl $0xe, %edx
movq %r14, %rdi
movq %rbx, %rcx
callq 0x481e7
cmpl $0x0, (%rbx)
jne 0x156ad
movq %rax, %r12
movq 0x48(%r14), %rdi
movl $0xe, %edx
movl $0x1b, %esi
movq %rbx, %rcx
callq 0x2be09
cmpl $0x0, (%rbx)
jne 0x156ad
movq 0x48(%r14), %rdi
movl $0x1f, %esi
movq %r12, %rdx
movq %rax, %rcx
movq %rbx, %r8
callq 0x2be2c
cmpl $0x0, (%rbx)
jne 0x156ad
movq 0x48(%r14), %rdi
movq %r15, %rsi
movq %rbx, %rdx
callq 0x2cca6
xorl %r12d, %r12d
jmp 0x156d5