// File: /workspace/github_c_makefile_star2_O2/michaelforney[P]cproc/qbe.c
// Function: funcinit
void
funcinit(struct func *func, struct decl *d, struct init *init, bool hasinit)
{
	struct lvalue dst;
	struct value *src, *v;
	unsigned long long offset = 0, max = 0;
	size_t i, w;

	funcalloc(func, d);
	if (!hasinit)
		return;
	for (; init; init = init->next) {
		zero(func, d->value, d->type->align, offset, init->start);
		dst.bits = init->bits;
		if (init->expr->kind == EXPRSTRING) {
			w = init->expr->type->base->size;
			for (i = 0; i < init->expr->u.string.size && i * w < init->end - init->start; ++i) {
				v = mkintconst(init->start + i * w);
				dst.addr = funcinst(func, IADD, ptrclass, d->value, v);
				switch (w) {
				case 1: v = mkintconst(((unsigned char *)init->expr->u.string.data)[i]); break;
				case 2: v = mkintconst(((uint_least16_t *)init->expr->u.string.data)[i]); break;
				case 4: v = mkintconst(((uint_least32_t *)init->expr->u.string.data)[i]); break;
				}
				funcstore(func, init->expr->type->base, QUALNONE, dst, v);
			}
			offset = init->start + i * w;
		} else {
			if (offset < init->end && (dst.bits.before || dst.bits.after))
				zero(func, d->value, d->type->align, offset, init->end);
			dst.addr = d->value;
			/*
			QBE's memopt does not eliminate the store for ptr + 0,
			so only emit the add if the offset is non-zero
			*/
			if (init->start > 0)
				dst.addr = funcinst(func, IADD, ptrclass, dst.addr, mkintconst(init->start));
			src = funcexpr(func, init->expr);
			funcstore(func, init->expr->type, QUALNONE, dst, src);
			offset = init->end;
		}
		if (max < offset)
			max = offset;
	}
	zero(func, d->value, d->type->align, max, d->type->size);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movl %ecx, %ebp
movq %rdx, %r14
movq %rdi, %r13
movq %rsi, 0x8(%rsp)
callq 0xd6b0
testl %ebp, %ebp
je 0xf109
xorl %r15d, %r15d
movabsq $-0x100000000, %r12     # imm = 0xFFFFFFFF00000000
xorl %ebx, %ebx
movq 0x8(%rsp), %rcx
movq 0x10(%rcx), %rax
movq 0x20(%rcx), %rsi
movl 0x8(%rax), %edx
testq %r14, %r14
je 0xf118
movq (%r14), %r8
movq %r13, %rdi
movq %r15, %rcx
callq 0xf132
movl 0x18(%r14), %ecx
movq 0x10(%rsp), %rax
andq %r12, %rax
orq %rcx, %rax
movq %rax, 0x10(%rsp)
movq 0x10(%r14), %rax
cmpl $0x2, (%rax)
jne 0xf063
movq %rbx, 0x18(%rsp)
movq 0x8(%rax), %rcx
movq 0x20(%rcx), %rcx
movq 0x10(%rcx), %r12
xorl %r15d, %r15d
xorl %ebx, %ebx
movq (%r14), %rdi
cmpq 0x30(%rax), %rbx
jae 0xf0e7
movq 0x8(%r14), %rax
subq %rdi, %rax
cmpq %rax, %r15
jae 0xf0e7
movq %r15, 0x20(%rsp)
addq %r15, %rdi
callq 0xd317
movq %rax, %r15
movq 0x8(%rsp), %rax
movq 0x20(%rax), %rcx
movq %r13, %rbp
movq %r13, %rdi
pushq $0x1
popq %rsi
pushq $0x6c
popq %rdx
movq %r15, %r8
callq 0xed68
movq %rax, %r13
cmpq $0x4, %r12
je 0xf018
cmpq $0x2, %r12
je 0xf00a
cmpq $0x1, %r12
jne 0xf02b
movq 0x10(%r14), %rax
movq 0x38(%rax), %rax
movzbl (%rax,%rbx), %edi
jmp 0xf023
movq 0x10(%r14), %rax
movq 0x38(%rax), %rax
movzwl (%rax,%rbx,2), %edi
jmp 0xf023
movq 0x10(%r14), %rax
movq 0x38(%rax), %rax
movl (%rax,%rbx,4), %edi
callq 0xd317
movq %rax, %r15
movq 0x10(%r14), %rax
movq 0x8(%rax), %rax
movq 0x20(%rax), %rsi
movq %rbp, %rdi
xorl %edx, %edx
movq %r13, %rcx
movq %rbp, %r13
movq 0x10(%rsp), %r8
movq %r15, %r9
callq 0xd82c
incq %rbx
movq 0x10(%r14), %rax
movq 0x20(%rsp), %r15
addq %r12, %r15
jmp 0xef9d
movq 0x8(%r14), %r8
cmpq %r8, %r15
jae 0xf08b
testl %ecx, %ecx
je 0xf08b
movq 0x8(%rsp), %rcx
movq 0x10(%rcx), %rax
movq 0x20(%rcx), %rsi
movl 0x8(%rax), %edx
movq %r13, %rdi
movq %r15, %rcx
callq 0xf132
movq 0x8(%rsp), %rax
movq 0x20(%rax), %r15
movq (%r14), %rdi
testq %rdi, %rdi
je 0xf0b8
callq 0xd317
movq %r13, %rdi
pushq $0x1
popq %rsi
pushq $0x6c
popq %rdx
movq %r15, %rcx
movq %rax, %r8
callq 0xed68
movq %rax, %r15
movq 0x10(%r14), %rsi
movq %r13, %rdi
callq 0xdfc5
movq 0x10(%r14), %rcx
movq 0x8(%rcx), %rsi
movq %r13, %rdi
xorl %edx, %edx
movq %r15, %rcx
movq 0x10(%rsp), %r8
movq %rax, %r9
callq 0xd82c
movq 0x8(%r14), %r15
jmp 0xf0f9
addq %rdi, %r15
movq 0x18(%rsp), %rbx
movabsq $-0x100000000, %r12     # imm = 0xFFFFFFFF00000000
cmpq %r15, %rbx
cmovbeq %r15, %rbx
movq 0x20(%r14), %r14
jmp 0xef3f
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x10(%rax), %r8
movq %r13, %rdi
movq %rbx, %rcx
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0xf132