// File: /workspace/github_c_makefile_star2_O3/michaelforney[P]cproc/qbe.c
// Function: funcalloc
static void
funcalloc(struct func *f, struct decl *d)
{
	enum instkind op;
	struct block *end;
	struct value *v;
	int align;

	assert(!d->type->incomplete);
	calcvla(f, d->type);
	end = f->end;
	if (d->type->size) {
		f->end = f->start;
		v = mkintconst(d->type->size);
	} else {
		assert(d->type->kind == TYPEARRAY);
		assert(d->type->u.array.size);
		v = d->type->u.array.size;
	}
	align = d->u.obj.align;
	switch (align) {
	case 1:
	case 2:
	case 4:  op = IALLOC4; break;
	case 8:  op = IALLOC8; break;
	default: v = funcinst(f, IADD, ptrclass, v, mkintconst(align - 16));  /* fallthrough */
	case 16: op = IALLOC16; break;
	}
	v = funcinst(f, op, ptrclass, v, NULL);
	if (align > 16) {
		/* TODO: implement alloc32 in QBE and use that instead */
		v = funcinst(f, IADD, ptrclass, v, mkintconst(align - 16));
		v = funcinst(f, IAND, ptrclass, v, mkintconst(-align));
	}
	d->value = v;
	f->end = end;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %rsi, %r14
movq 0x10(%rsi), %rsi
cmpb $0x1, 0x3c(%rsi)
je 0xe915
movq %rdi, %rbx
callq 0xfef4
movq 0x30(%rbx), %r12
movq 0x10(%r14), %rax
movq 0x10(%rax), %r13
testq %r13, %r13
je 0xe7e4
movq 0x28(%rbx), %rax
movq %rax, 0x30(%rbx)
movl $0x10, %edi
callq 0xe142
movq %rax, %r15
movl $0x2, (%rax)
movq %r13, 0x8(%rax)
jmp 0xe7fa
cmpl $0xd, (%rax)
jne 0xe934
movq 0x50(%rax), %r15
testq %r15, %r15
je 0xe953
movslq 0x40(%r14), %r13
cmpq $0x7, %r13
jg 0xe81a
movl $0x1d, %esi
leal -0x1(%r13), %eax
cmpl $0x2, %eax
jb 0xe832
cmpl $0x4, %r13d
je 0xe832
jmp 0xe85f
cmpl $0x10, %r13d
je 0xe82d
cmpl $0x8, %r13d
jne 0xe85f
movl $0x1e, %esi
jmp 0xe832
movl $0x1f, %esi
movq %rbx, %rdi
movl $0x6c, %edx
movq %r15, %rcx
xorl %r8d, %r8d
callq 0x10201
movq %rax, %r15
movq %r15, 0x20(%r14)
movq %r12, 0x30(%rbx)
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq -0x10(%r13), %rbp
movl $0x10, %edi
callq 0xe142
movl $0x2, (%rax)
movq %rbp, 0x8(%rax)
movq %rbx, %rdi
movl $0x1, %esi
movl $0x6c, %edx
movq %r15, %rcx
movq %rax, %r8
callq 0x10201
movq %rbx, %rdi
movl $0x1f, %esi
movl $0x6c, %edx
movq %rax, %rcx
xorl %r8d, %r8d
callq 0x10201
movq %rax, %r15
cmpl $0x11, %r13d
jl 0xe848
movl %ebp, %ebp
movl $0x10, %edi
callq 0xe142
movl $0x2, %ecx
movl %ecx, (%rax)
movq %rbp, 0x8(%rax)
movq %rbx, %rdi
movl $0x1, %esi
movl $0x6c, %edx
movq %r15, %rcx
movq %rax, %r8
callq 0x10201
movq %rax, %r15
negl %r13d
movslq %r13d, %r13
movl $0x10, %edi
callq 0xe142
movl $0x2, %ecx
movl %ecx, (%rax)
movq %r13, 0x8(%rax)
movq %rbx, %rdi
movl $0xb, %esi
movl $0x6c, %edx
movq %r15, %rcx
movq %rax, %r8
jmp 0xe840
leaq 0x72cb(%rip), %rdi      # 0x15be7
leaq 0x6fd1(%rip), %rsi      # 0x158f4
leaq 0x72d2(%rip), %rcx      # 0x15bfc
movl $0x16a, %edx            # imm = 0x16A
callq 0x30e0
leaq 0x72ee(%rip), %rdi      # 0x15c29
leaq 0x6fb2(%rip), %rsi      # 0x158f4
leaq 0x72b3(%rip), %rcx      # 0x15bfc
movl $0x171, %edx            # imm = 0x171
callq 0x30e0
leaq 0x72ea(%rip), %rdi      # 0x15c44
leaq 0x6f93(%rip), %rsi      # 0x158f4
leaq 0x7294(%rip), %rcx      # 0x15bfc
movl $0x172, %edx            # imm = 0x172
callq 0x30e0