// File: /workspace/github_c_makefile_star2_O3/michaelforney[P]cproc/qbe.c
// Function: mkfunc
struct func *
mkfunc(struct decl *decl, char *name, struct type *t, struct scope *s)
{
	struct func *f;
	struct decl *d;
	struct value *v;

	f = xmalloc(sizeof(*f));
	f->decl = decl;
	f->name = name;
	f->type = t;
	f->start = f->end = mkblock("start");
	f->lastid = 0;
	mapinit(&f->gotos, 8);
	emittype(t->base);

	/* allocate space for parameters */
	f->paramtemps = xreallocarray(NULL, t->u.func.nparam, sizeof *f->paramtemps);
	for (d = t->u.func.params, v = f->paramtemps; d; d = d->next, ++v) {
		emittype(d->type);
		functemp(f, v);
		if(!d->name)
			continue;
		if (d->type->value) {
			d->value = v;
		} else {
			funcalloc(f, d);
			funcstore(f, d->type, QUALNONE, (struct lvalue){d->value}, v);
		}
	}

	t = mkarraytype(&typechar, QUALCONST, strlen(name) + 1);
	d = mkdecl("__func__", DECLOBJECT, t, QUALNONE, LINKNONE);
	d->u.obj.storage = SDSTATIC;
	d->value = mkglobal(d);
	scopeputdecl(s, d);
	f->namedecl = d;

	funclabel(f, mkblock("body"));

	return f;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %rcx, 0x10(%rsp)
movq %rdx, %r13
movq %rsi, %r14
movq %rdi, %r12
movl $0x60, %edi
callq 0xe142
movq %rax, %rbx
movq %r12, (%rax)
movq %r14, 0x8(%rsp)
movq %r14, 0x10(%rax)
movq %r13, 0x20(%rax)
movl $0x88, %edi
callq 0xe142
movl $0x7, (%rax)
leaq 0x6ba4(%rip), %rcx      # 0x14f8b
movq %rcx, 0x8(%rax)
movl 0xdd4f(%rip), %ecx      # 0x1c140
incl %ecx
movl %ecx, 0xdd47(%rip)      # 0x1c140
movl %ecx, 0x4(%rax)
xorps %xmm0, %xmm0
movups %xmm0, 0x10(%rax)
xorl %r14d, %r14d
movq %r14, 0x20(%rax)
movl %r14d, 0x60(%rax)
movl %r14d, 0x50(%rax)
movq %r14, 0x80(%rax)
movq %rax, 0x30(%rbx)
movq %rax, 0x28(%rbx)
movl %r14d, 0x58(%rbx)
leaq 0x38(%rbx), %rdi
movl $0x8, %esi
callq 0xa52f
movq 0x20(%r13), %rdi
callq 0xe59b
movq 0x50(%r13), %rsi
movl $0x10, %edx
xorl %edi, %edi
callq 0xe10e
movq %rax, 0x18(%rbx)
movq 0x48(%r13), %r13
testq %r13, %r13
je 0xe4d8
movq %rax, %r12
movabsq $-0x100000000, %r15     # imm = 0xFFFFFFFF00000000
movq 0x10(%r13), %rdi
callq 0xe59b
movl $0x5, (%r12)
movq $0x0, 0x8(%r12)
movl 0x58(%rbx), %eax
incl %eax
movl %eax, 0x58(%rbx)
movl %eax, 0x4(%r12)
cmpq $0x0, (%r13)
je 0xe4cb
movq 0x10(%r13), %rax
cmpq $0x0, 0x18(%rax)
je 0xe4a5
movq %r12, 0x20(%r13)
jmp 0xe4cb
movq %rbx, %rdi
movq %r13, %rsi
callq 0xe78e
movq 0x10(%r13), %rsi
movq 0x20(%r13), %rcx
andq %r15, %rbp
movq %rbx, %rdi
xorl %edx, %edx
movq %rbp, %r8
movq %r12, %r9
callq 0xe972
addq $0x10, %r12
movq 0x38(%r13), %r13
testq %r13, %r13
jne 0xe466
movq 0x8(%rsp), %rdi
callq 0x3090
leaq 0x1(%rax), %rdx
leaq 0xd55b(%rip), %rdi      # 0x1ba48
movl $0x2, %esi
callq 0xd85e
leaq 0x73ed(%rip), %rdi      # 0x158eb
movl $0x1, %esi
movq %rax, %rdx
xorl %ecx, %ecx
xorl %r8d, %r8d
callq 0x37e4
movq %rax, %r15
movl %r14d, 0x44(%rax)
movq %rax, %rdi
callq 0xe324
movq %rax, 0x20(%r15)
movq 0x10(%rsp), %rdi
movq %r15, %rsi
callq 0xc644
movq %r15, 0x8(%rbx)
movl $0x88, %edi
callq 0xe142
movl $0x7, (%rax)
leaq 0x6bc2(%rip), %rcx      # 0x1510d
movq %rcx, 0x8(%rax)
movl 0xdbeb(%rip), %ecx      # 0x1c140
incl %ecx
movl %ecx, 0xdbe3(%rip)      # 0x1c140
movl %ecx, 0x4(%rax)
xorps %xmm0, %xmm0
movups %xmm0, 0x10(%rax)
movq %r14, 0x20(%rax)
movl %r14d, 0x60(%rax)
movl %r14d, 0x50(%rax)
movq %r14, 0x80(%rax)
movq 0x30(%rbx), %rcx
movq %rax, 0x80(%rcx)
movq %rax, 0x30(%rbx)
movq %rbx, %rax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq