// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x70, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
testb $0x1, 0x3c(%rax)
jne 0x132c0
jmp 0x132df
leaq 0x90b4(%rip), %rdi      # 0x1c37b
leaq 0x8dba(%rip), %rsi      # 0x1c088
movl $0x16a, %edx            # imm = 0x16A
leaq 0x90b6(%rip), %rcx      # 0x1c390
callq 0x30f0
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rsi
callq 0x153b0
movq -0x8(%rbp), %rax
movq 0x30(%rax), %rax
movq %rax, -0x20(%rbp)
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
cmpq $0x0, 0x10(%rax)
je 0x13332
movq -0x8(%rbp), %rax
movq 0x28(%rax), %rcx
movq -0x8(%rbp), %rax
movq %rcx, 0x30(%rax)
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
movq 0x10(%rax), %rdi
callq 0x12cc0
movq %rax, -0x28(%rbp)
jmp 0x133a0
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
cmpl $0xd, (%rax)
jne 0x13341
jmp 0x13360
leaq 0x9075(%rip), %rdi      # 0x1c3bd
leaq 0x8d39(%rip), %rsi      # 0x1c088
movl $0x171, %edx            # imm = 0x171
leaq 0x9035(%rip), %rcx      # 0x1c390
callq 0x30f0
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
cmpq $0x0, 0x50(%rax)
je 0x13371
jmp 0x13390
leaq 0x9060(%rip), %rdi      # 0x1c3d8
leaq 0x8d09(%rip), %rsi      # 0x1c088
movl $0x172, %edx            # imm = 0x172
leaq 0x9005(%rip), %rcx      # 0x1c390
callq 0x30f0
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
movq 0x50(%rax), %rax
movq %rax, -0x28(%rbp)
movq -0x10(%rbp), %rax
movl 0x40(%rax), %eax
movl %eax, -0x2c(%rbp)
movl -0x2c(%rbp), %eax
decl %eax
movl %eax, %ecx
movq %rcx, -0x38(%rbp)
subl $0xf, %eax
ja 0x133e0
movq -0x38(%rbp), %rax
leaq 0x8a2b(%rip), %rcx      # 0x1bdf0
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movl $0x1d, -0x14(%rbp)
jmp 0x13423
movl $0x1e, -0x14(%rbp)
jmp 0x13423
movq -0x8(%rbp), %rax
movq %rax, -0x48(%rbp)
movq -0x28(%rbp), %rax
movq %rax, -0x40(%rbp)
movl -0x2c(%rbp), %eax
subl $0x10, %eax
movslq %eax, %rdi
callq 0x12cc0
movq -0x48(%rbp), %rdi
movq -0x40(%rbp), %rcx
movq %rax, %r8
movl $0x1, %esi
movl $0x6c, %edx
callq 0x15860
movq %rax, -0x28(%rbp)
movl $0x1f, -0x14(%rbp)
movq -0x8(%rbp), %rdi
movl -0x14(%rbp), %esi
movq -0x28(%rbp), %rcx
movl $0x6c, %edx
xorl %eax, %eax
movl %eax, %r8d
callq 0x15860
movq %rax, -0x28(%rbp)
cmpl $0x10, -0x2c(%rbp)
jle 0x134be
movq -0x8(%rbp), %rax
movq %rax, -0x68(%rbp)
movq -0x28(%rbp), %rax
movq %rax, -0x60(%rbp)
movl -0x2c(%rbp), %eax
subl $0x10, %eax
movslq %eax, %rdi
callq 0x12cc0
movq -0x68(%rbp), %rdi
movq -0x60(%rbp), %rcx
movq %rax, %r8
movl $0x1, %esi
movl $0x6c, %edx
callq 0x15860
movq %rax, -0x28(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x58(%rbp)
movq -0x28(%rbp), %rax
movq %rax, -0x50(%rbp)
xorl %eax, %eax
subl -0x2c(%rbp), %eax
movslq %eax, %rdi
callq 0x12cc0
movq -0x58(%rbp), %rdi
movq -0x50(%rbp), %rcx
movq %rax, %r8
movl $0xb, %esi
movl $0x6c, %edx
callq 0x15860
movq %rax, -0x28(%rbp)
movq -0x28(%rbp), %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x20(%rax)
movq -0x20(%rbp), %rcx
movq -0x8(%rbp), %rax
movq %rcx, 0x30(%rax)
addq $0x70, %rsp
popq %rbp
retq
nopl (%rax)