// File: /workspace/github_c_makefile_star2_O1/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 0x15733
movq %rsi, %rbx
movq %rdi, %r14
movq 0x48(%rdi), %rdi
callq 0x2d00a
movq %rax, %r13
movq 0x48(%r14), %rdi
callq 0x2d00a
movq %rax, %r15
leaq 0x90a68(%rip), %rax     # 0xa6188
movq (%rax), %rsi
movq %r14, %rdi
movq %rbx, %rdx
callq 0x35d95
cmpl $0x0, (%rbx)
je 0x15742
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 0x2c193
cmpl $0x0, (%rbx)
je 0x1575f
xorl %ebp, %ebp
jmp 0x15771
movl %eax, %edi
movq %rbx, %rsi
callq 0x2ba99
movq %rax, %rbp
cmpl $0x0, (%rbx)
je 0x1578f
movq %r12, %rdi
callq 0x2b4c3
movq %rbp, %rdi
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x2b4c3
movq %r14, %rdi
movq %r12, %rsi
movq %rbp, %rdx
movq %rbx, %rcx
callq 0x36f23
movq %rax, %r12
cmpl $0x0, (%rbx)
jne 0x1575b
movq 0x48(%r14), %rdi
movq 0x148(%r12), %rdx
movl $0x43, %esi
movq %r13, %rcx
movq %r15, %r8
movq %rbx, %r9
callq 0x2c0c2
cmpl $0x0, (%rbx)
jne 0x1575b
movq 0x48(%r14), %rdi
movq %r13, %rsi
movq %rbx, %rdx
callq 0x2d017
cmpl $0x0, (%rbx)
jne 0x1575b
movb $0x1, 0xb9(%r14)
movq %r14, %rdi
movq %r12, %rsi
movq %rbx, %rdx
callq 0x37740
cmpl $0x0, (%rbx)
jne 0x15733
leaq 0x5dca2(%rip), %rsi     # 0x734ac
movl $0xe, %edx
movq %r14, %rdi
movq %rbx, %rcx
callq 0x48267
cmpl $0x0, (%rbx)
jne 0x15733
movq %rax, %r12
movq 0x48(%r14), %rdi
movl $0xe, %edx
movl $0x1b, %esi
movq %rbx, %rcx
callq 0x2c189
cmpl $0x0, (%rbx)
jne 0x15733
movq 0x48(%r14), %rdi
movl $0x1f, %esi
movq %r12, %rdx
movq %rax, %rcx
movq %rbx, %r8
callq 0x2c1ac
cmpl $0x0, (%rbx)
jne 0x15733
movq 0x48(%r14), %rdi
movq %r15, %rsi
movq %rbx, %rdx
callq 0x2d017
xorl %r12d, %r12d
jmp 0x1575b