// File: /workspace/github_c_makefile_star2_O1/markdryan[P]subtilis/frontend/fn_type.c
// Function: prv_generate_zero_fn
static size_t prv_generate_zero_fn(subtilis_parser_t *p,
				   const subtilis_type_t *type,
				   subtilis_error_t *err)
{
	subtilis_type_section_t *stype;
	subtilis_buffer_t name;
	subtilis_exp_t *e;
	const char *fn_name;
	const subtilis_symbol_t *s;
	subtilis_ir_operand_t result;
	subtilis_ir_operand_t ret_reg;
	subtilis_symbol_table_t *local_st = NULL;
	size_t call_index = SIZE_MAX;
	subtilis_symbol_table_t *old_local_st = p->local_st;
	subtilis_ir_section_t *old_section = p->current;

	subtilis_buffer_init(&name, 64);

	if (type->type == SUBTILIS_TYPE_ARRAY_FN) {
		/* I need a loop here that generates functions recursively. */
		subtilis_error_set_assertion_failed(err);
		return SIZE_MAX;
	}

	local_st = subtilis_symbol_table_new(err);
	if (err->type != SUBTILIS_ERROR_OK)
		return SIZE_MAX;
	p->local_st = local_st;

	stype = subtilis_type_section_new(type, 0, NULL, NULL, err);
	if (err->type != SUBTILIS_ERROR_OK)
		goto cleanup;

	subtilis_buffer_append_string(&name, "!", err);
	if (err->type != SUBTILIS_ERROR_OK)
		goto cleanup;

	subtilis_full_type_name(type, &name, err);
	if (err->type != SUBTILIS_ERROR_OK)
		goto cleanup;

	fn_name = subtilis_buffer_get_string(&name);
	if (subtilis_string_pool_find(p->prog->string_pool, fn_name,
				      &call_index))
		goto cleanup;

	p->current = subtilis_ir_prog_section_new(
	    p->prog, fn_name, 0, stype, SUBTILIS_BUILTINS_MAX,
	    p->l->stream->name, p->l->line, p->eflag_offset, p->error_offset,
	    &call_index, err);
	stype = NULL;
	if (err->type != SUBTILIS_ERROR_OK)
		goto cleanup;

	if (type->type != SUBTILIS_TYPE_VOID) {
		if (subtilis_type_if_is_reference(type)) {
			s = subtilis_symbol_table_insert_tmp(local_st, type,
							     NULL, err);
			if (err->type != SUBTILIS_ERROR_OK)
				goto cleanup;

			subtilis_type_if_zero_ref(
			    p, type, SUBTILIS_IR_REG_LOCAL, s->loc, false, err);
			if (err->type != SUBTILIS_ERROR_OK)
				goto cleanup;

			result.reg = subtilis_reference_get_pointer(
			    p, SUBTILIS_IR_REG_LOCAL, s->loc, err);
			if (err->type != SUBTILIS_ERROR_OK)
				goto cleanup;

			/*
			 * Arrays are trickier as they don't have a zero value
			 */

			if (subtilis_type_if_is_array(type)) {
				ret_reg.reg = p->current->ret_reg;
				subtilis_ir_section_add_instr_no_reg2(
				    p->current, SUBTILIS_OP_INSTR_MOV, ret_reg,
				    result, err);
				if (err->type != SUBTILIS_ERROR_OK)
					goto cleanup;

				subtilis_ir_section_add_label(
				    p->current, p->current->end_label, err);
				if (err->type != SUBTILIS_ERROR_OK)
					goto cleanup;
			} else {
				ret_reg.reg = result.reg;
			}
			e = subtilis_exp_new_var(type, ret_reg.reg, err);
			if (err->type != SUBTILIS_ERROR_OK)
				goto cleanup;

			p->current->locals = local_st->max_allocated;
		} else {
			e = subtilis_type_if_zero(p, type, err);
		}
		if (err->type != SUBTILIS_ERROR_OK)
			goto cleanup;

		subtilis_type_if_ret(p, type, e->exp.ir_op.reg, err);
		subtilis_exp_delete(e);
	} else {
		subtilis_ir_section_add_instr_no_arg(
		    p->current, SUBTILIS_OP_INSTR_RET, err);
	}

cleanup:
	p->current = old_section;

	subtilis_type_section_delete(stype);
	p->local_st = old_local_st;
	subtilis_symbol_table_delete(local_st);
	subtilis_buffer_free(&name);

	return call_index;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movq %rdx, %r15
movq %rsi, %r12
movq %rdi, %rbx
movq $-0x1, 0x18(%rsp)
movq 0x48(%rdi), %r13
movq 0x68(%rdi), %rbp
leaq 0x20(%rsp), %rdi
movl $0x40, %esi
callq 0x14a40
cmpl $0xe, (%r12)
jne 0x412d9
leaq 0x34629(%rip), %rdx     # 0x758e4
movq %r15, %rdi
movl $0xf, %esi
movl $0x2d, %ecx
callq 0x145f4
movq $-0x1, %rax
jmp 0x41399
movq %r15, %rdi
callq 0x2e528
movq %rax, %r14
movq $-0x1, %rax
cmpl $0x0, (%r15)
jne 0x41399
movq %r14, 0x68(%rbx)
movq %r12, %rdi
xorl %esi, %esi
xorl %edx, %edx
xorl %ecx, %ecx
movq %r15, %r8
callq 0x2f57c
movq %rax, %rdi
cmpl $0x0, (%r15)
jne 0x41375
movq %rdi, 0x8(%rsp)
leaq 0x3219a(%rip), %rsi     # 0x734b9
leaq 0x20(%rsp), %rdi
movq %r15, %rdx
callq 0x14bd4
cmpl $0x0, (%r15)
jne 0x41370
leaq 0x20(%rsp), %rsi
movq %r12, %rdi
movq %r15, %rdx
callq 0x2f8ac
cmpl $0x0, (%r15)
jne 0x41370
leaq 0x20(%rsp), %rdi
callq 0x14dfb
movq %rax, %rsi
movq 0x58(%rbx), %rax
movq 0x18(%rax), %rdi
leaq 0x18(%rsp), %rdx
movq %rsi, 0x10(%rsp)
callq 0x2f216
testb %al, %al
je 0x413a8
movq 0x8(%rsp), %rdi
movq %r13, 0x48(%rbx)
callq 0x2f7d2
movq %rbp, 0x68(%rbx)
movq %r14, %rdi
callq 0x2e5e7
leaq 0x20(%rsp), %rdi
callq 0x14da6
movq 0x18(%rsp), %rax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq (%rbx), %rax
movq 0x58(%rbx), %rdi
movq 0x30(%rax), %r9
movl 0x38(%rax), %eax
movq %rax, 0x30(%rsp)
movl 0xb0(%rbx), %r10d
movl 0xb4(%rbx), %r11d
subq $0x8, %rsp
movq 0x18(%rsp), %rsi
xorl %edx, %edx
movq 0x10(%rsp), %rcx
movl $0x9, %r8d
pushq %r15
leaq 0x28(%rsp), %rax
pushq %rax
pushq %r11
pushq %r10
pushq 0x58(%rsp)
callq 0x2c522
addq $0x30, %rsp
movq %rax, 0x48(%rbx)
cmpl $0x0, (%r15)
movl $0x0, %edi
jne 0x41375
cmpl $0x8, (%r12)
jne 0x41427
movq %rax, %rdi
movl $0x46, %esi
movq %r15, %rdx
callq 0x2c1b7
jmp 0x41525
movq %r12, %rdi
callq 0x37833
testb %al, %al
je 0x414f1
movq %r14, %rdi
movq %r12, %rsi
xorl %edx, %edx
movq %r15, %rcx
callq 0x2ea12
xorl %edi, %edi
cmpl $0x0, (%r15)
jne 0x41375
movq %rax, 0x8(%rsp)
movq (%rax), %rcx
movl $0x2, %edx
movq %rbx, %rdi
movq %r12, %rsi
xorl %r8d, %r8d
movq %r15, %r9
callq 0x35fa9
cmpl $0x0, (%r15)
jne 0x41525
movq 0x8(%rsp), %rax
movq (%rax), %rdx
movl $0x2, %esi
movq %rbx, %rdi
movq %r15, %rcx
callq 0x4d763
movq %rax, 0x8(%rsp)
cmpl $0x0, (%r15)
jne 0x41525
movq %r12, %rdi
callq 0x377f7
testb %al, %al
je 0x4152c
movq 0x48(%rbx), %rdi
movq 0xa8(%rdi), %rdx
movl $0x1d, %esi
movq %rdx, 0x10(%rsp)
movq 0x8(%rsp), %rcx
movq %r15, %r8
callq 0x2c1ac
cmpl $0x0, (%r15)
jne 0x41525
movq 0x48(%rbx), %rdi
movq 0x98(%rdi), %rsi
movq %r15, %rdx
callq 0x2d017
cmpl $0x0, (%r15)
jne 0x41525
jmp 0x41536
movq %rbx, %rdi
movq %r12, %rsi
movq %r15, %rdx
callq 0x35f70
cmpl $0x0, (%r15)
jne 0x41525
movq 0x148(%rax), %rdx
movq %rbx, %rdi
movq %r12, %rsi
movq %r15, %rcx
movq %rax, %r15
callq 0x37706
movq %r15, %rdi
callq 0x2b4c3
xorl %edi, %edi
jmp 0x41375
movq 0x8(%rsp), %rax
movq %rax, 0x10(%rsp)
movq %r12, %rdi
movq 0x10(%rsp), %rsi
movq %r15, %rdx
callq 0x2b971
cmpl $0x0, (%r15)
jne 0x41525
movq 0x310(%r14), %rdx
movq 0x48(%rbx), %rcx
movq %rdx, 0x10(%rcx)
jmp 0x414ff