// File: /workspace/github_c_makefile_star2_O0/michaelforney[P]cproc/qbe.c
// Function: emitdata
void
emitdata(struct decl *d, struct init *init)
{
	struct init *cur;
	struct type *t;
	unsigned long long offset = 0, start, end, bits = 0;
	size_t i;
	int align;

	align = d->u.obj.align;
	for (cur = init; cur; cur = cur->next)
		cur->expr = eval(cur->expr);
	if (d->u.obj.storage == SDTHREAD)
		fputs("thread ", stdout);
	if (d->linkage == LINKEXTERN)
		fputs("export ", stdout);
	fputs("data ", stdout);
	emitname(d->value);
	printf(" = align %d { ", align);

	while (init) {
		cur = init;
		while ((init = init->next) && init->start * 8 + init->bits.before < cur->end * 8 - cur->bits.after) {
			/*
			XXX: Currently, if multiple union members are
			initialized, these assertions may not hold.
			(https://todo.sr.ht/~mcf/cproc/38)
			*/
			assert(cur->expr->kind == EXPRSTRING);
			assert(init->expr->kind == EXPRCONST);
			i = (init->start - cur->start) / cur->expr->type->base->size;
			switch (cur->expr->type->base->size) {
			case 1: ((unsigned char *)cur->expr->u.string.data)[i]  = init->expr->u.constant.u; break;
			case 2: ((uint_least16_t *)cur->expr->u.string.data)[i] = init->expr->u.constant.u; break;
			case 4: ((uint_least32_t *)cur->expr->u.string.data)[i] = init->expr->u.constant.u; break;
			}
		}
		start = cur->start + cur->bits.before / 8;
		end = cur->end - (cur->bits.after + 7) / 8;
		if (offset < start && bits) {
			printf("b %u, ", (unsigned)bits);  /* unfinished byte from previous bit-field */
			++offset;
			bits = 0;
		}
		if (offset < start)
			printf("z %llu, ", start - offset);
		if (cur->bits.before || cur->bits.after) {
			/* little-endian target specific */
			assert(cur->expr->type->prop & PROPINT);
			assert(cur->expr->kind == EXPRCONST);
			bits |= cur->expr->u.constant.u << cur->bits.before % 8;
			for (offset = start; offset < end; ++offset, bits >>= 8)
				printf("b %u, ", (unsigned)bits & 0xff);
			/*
			clear the upper `after` bits in the last byte,
			or all bits when `after` is 0 (we ended on a
			byte boundary).
			*/
			bits &= 0x7f >> (cur->bits.after + 7) % 8;
		} else {
			t = cur->expr->type;
			if (t->kind == TYPEARRAY)
				t = t->base;
			printf("%c ", qbetype(t).data);
			dataitem(cur->expr, cur->end - cur->start);
			fputs(", ", stdout);
		}
		offset = end;
	}
	if (bits) {
		printf("b %u, ", (unsigned)bits);
		++offset;
	}
	assert(offset <= d->type->size);
	if (offset < d->type->size)
		printf("z %llu ", d->type->size - offset);
	puts("}");
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x90, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq $0x0, -0x28(%rbp)
movq $0x0, -0x40(%rbp)
movq -0x8(%rbp), %rax
movl 0x40(%rax), %eax
movl %eax, -0x4c(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x18(%rbp)
cmpq $0x0, -0x18(%rbp)
je 0x16a02
movq -0x18(%rbp), %rax
movq 0x10(%rax), %rdi
callq 0x7010
movq %rax, %rcx
movq -0x18(%rbp), %rax
movq %rcx, 0x10(%rax)
movq -0x18(%rbp), %rax
movq 0x20(%rax), %rax
movq %rax, -0x18(%rbp)
jmp 0x169d5
movq -0x8(%rbp), %rax
cmpl $0x1, 0x44(%rax)
jne 0x16a22
movq 0xa5bd(%rip), %rax      # 0x20fd0
movq (%rax), %rsi
leaq 0x5860(%rip), %rdi      # 0x1c27d
callq 0x3100
movq -0x8(%rbp), %rax
cmpl $0x2, 0xc(%rax)
jne 0x16a42
movq 0xa59d(%rip), %rax      # 0x20fd0
movq (%rax), %rsi
leaq 0x5848(%rip), %rdi      # 0x1c285
callq 0x3100
movq 0xa587(%rip), %rax      # 0x20fd0
movq (%rax), %rsi
leaq 0x583a(%rip), %rdi      # 0x1c28d
callq 0x3100
movq -0x8(%rbp), %rax
movq 0x20(%rax), %rdi
callq 0x164a0
movl -0x4c(%rbp), %esi
leaq 0x5824(%rip), %rdi      # 0x1c293
movb $0x0, %al
callq 0x30c0
cmpq $0x0, -0x10(%rbp)
je 0x16e89
movq -0x10(%rbp), %rax
movq %rax, -0x18(%rbp)
movq -0x10(%rbp), %rax
movq 0x20(%rax), %rcx
movq %rcx, -0x10(%rbp)
xorl %eax, %eax
cmpq $0x0, %rcx
movb %al, -0x69(%rbp)
je 0x16ad8
movq -0x10(%rbp), %rax
movq (%rax), %rax
shlq $0x3, %rax
movq -0x10(%rbp), %rcx
movswq 0x18(%rcx), %rcx
addq %rcx, %rax
movq -0x18(%rbp), %rcx
movq 0x8(%rcx), %rcx
shlq $0x3, %rcx
movq -0x18(%rbp), %rdx
movswq 0x1a(%rdx), %rdx
subq %rdx, %rcx
cmpq %rcx, %rax
setb %al
movb %al, -0x69(%rbp)
movb -0x69(%rbp), %al
testb $0x1, %al
jne 0x16ae4
jmp 0x16c10
movq -0x18(%rbp), %rax
movq 0x10(%rax), %rax
cmpl $0x2, (%rax)
jne 0x16af3
jmp 0x16b12
leaq 0x57a8(%rip), %rdi      # 0x1c2a2
leaq 0x5587(%rip), %rsi      # 0x1c088
movl $0x58b, %edx            # imm = 0x58B
leaq 0x57b3(%rip), %rcx      # 0x1c2c0
callq 0x30f0
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
cmpl $0x1, (%rax)
jne 0x16b21
jmp 0x16b40
leaq 0x57c4(%rip), %rdi      # 0x1c2ec
leaq 0x5559(%rip), %rsi      # 0x1c088
movl $0x58c, %edx            # imm = 0x58C
leaq 0x5785(%rip), %rcx      # 0x1c2c0
callq 0x30f0
movq -0x10(%rbp), %rax
movq (%rax), %rax
movq -0x18(%rbp), %rcx
movq (%rcx), %rdx
movq 0x10(%rcx), %rcx
subq %rdx, %rax
movq 0x8(%rcx), %rcx
movq 0x20(%rcx), %rcx
movq 0x10(%rcx), %rcx
xorl %edx, %edx
divq %rcx
movq %rax, -0x48(%rbp)
movq -0x18(%rbp), %rax
movq 0x10(%rax), %rax
movq 0x8(%rax), %rax
movq 0x20(%rax), %rax
movq 0x10(%rax), %rax
movq %rax, -0x78(%rbp)
subq $0x1, %rax
je 0x16ba2
jmp 0x16b8a
movq -0x78(%rbp), %rax
subq $0x2, %rax
je 0x16bc5
jmp 0x16b96
movq -0x78(%rbp), %rax
subq $0x4, %rax
je 0x16bea
jmp 0x16c0b
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
movq 0x30(%rax), %rax
movb %al, %dl
movq -0x18(%rbp), %rax
movq 0x10(%rax), %rax
movq 0x38(%rax), %rax
movq -0x48(%rbp), %rcx
movb %dl, (%rax,%rcx)
jmp 0x16c0b
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
movq 0x30(%rax), %rax
movw %ax, %dx
movq -0x18(%rbp), %rax
movq 0x10(%rax), %rax
movq 0x38(%rax), %rax
movq -0x48(%rbp), %rcx
movw %dx, (%rax,%rcx,2)
jmp 0x16c0b
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
movq 0x30(%rax), %rax
movl %eax, %edx
movq -0x18(%rbp), %rax
movq 0x10(%rax), %rax
movq 0x38(%rax), %rax
movq -0x48(%rbp), %rcx
movl %edx, (%rax,%rcx,4)
jmp 0x16a89
movq -0x18(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x88(%rbp)
movq -0x18(%rbp), %rax
movswl 0x18(%rax), %eax
movl $0x8, %ecx
cltd
idivl %ecx
movl %eax, %ecx
movq -0x88(%rbp), %rax
movslq %ecx, %rcx
addq %rcx, %rax
movq %rax, -0x30(%rbp)
movq -0x18(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x80(%rbp)
movq -0x18(%rbp), %rax
movswl 0x1a(%rax), %eax
addl $0x7, %eax
movl $0x8, %ecx
cltd
idivl %ecx
movl %eax, %ecx
movq -0x80(%rbp), %rax
movslq %ecx, %rcx
subq %rcx, %rax
movq %rax, -0x38(%rbp)
movq -0x28(%rbp), %rax
cmpq -0x30(%rbp), %rax
jae 0x16ca9
cmpq $0x0, -0x40(%rbp)
je 0x16ca9
movq -0x40(%rbp), %rax
movl %eax, %esi
leaq 0x567c(%rip), %rdi      # 0x1c30a
movb $0x0, %al
callq 0x30c0
movq -0x28(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x28(%rbp)
movq $0x0, -0x40(%rbp)
movq -0x28(%rbp), %rax
cmpq -0x30(%rbp), %rax
jae 0x16cc9
movq -0x30(%rbp), %rsi
subq -0x28(%rbp), %rsi
leaq 0x564f(%rip), %rdi      # 0x1c311
movb $0x0, %al
callq 0x30c0
movq -0x18(%rbp), %rax
movswl 0x18(%rax), %eax
cmpl $0x0, %eax
jne 0x16ce7
movq -0x18(%rbp), %rax
movswl 0x1a(%rax), %eax
cmpl $0x0, %eax
je 0x16df5
movq -0x18(%rbp), %rax
movq 0x10(%rax), %rax
movq 0x8(%rax), %rax
movl 0x4(%rax), %eax
andl $0x2, %eax
cmpl $0x0, %eax
je 0x16d00
jmp 0x16d1f
leaq 0x5613(%rip), %rdi      # 0x1c31a
leaq 0x537a(%rip), %rsi      # 0x1c088
movl $0x59f, %edx            # imm = 0x59F
leaq 0x55a6(%rip), %rcx      # 0x1c2c0
callq 0x30f0
movq -0x18(%rbp), %rax
movq 0x10(%rax), %rax
cmpl $0x1, (%rax)
jne 0x16d2e
jmp 0x16d4d
leaq 0x5605(%rip), %rdi      # 0x1c33a
leaq 0x534c(%rip), %rsi      # 0x1c088
movl $0x5a0, %edx            # imm = 0x5A0
leaq 0x5578(%rip), %rcx      # 0x1c2c0
callq 0x30f0
movq -0x18(%rbp), %rax
movq 0x10(%rax), %rax
movq 0x30(%rax), %rax
movq %rax, -0x90(%rbp)
movq -0x18(%rbp), %rax
movswl 0x18(%rax), %eax
movl $0x8, %ecx
cltd
idivl %ecx
movq -0x90(%rbp), %rax
movl %edx, %ecx
shlq %cl, %rax
orq -0x40(%rbp), %rax
movq %rax, -0x40(%rbp)
movq -0x30(%rbp), %rax
movq %rax, -0x28(%rbp)
movq -0x28(%rbp), %rax
cmpq -0x38(%rbp), %rax
jae 0x16dca
movq -0x40(%rbp), %rax
movl %eax, %esi
andl $0xff, %esi
leaq 0x5561(%rip), %rdi      # 0x1c30a
movb $0x0, %al
callq 0x30c0
movq -0x28(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x28(%rbp)
movq -0x40(%rbp), %rax
shrq $0x8, %rax
movq %rax, -0x40(%rbp)
jmp 0x16d8c
movq -0x18(%rbp), %rax
movswl 0x1a(%rax), %eax
addl $0x7, %eax
movl $0x8, %ecx
cltd
idivl %ecx
movl %edx, %ecx
movl $0x7f, %eax
sarl %cl, %eax
cltq
andq -0x40(%rbp), %rax
movq %rax, -0x40(%rbp)
jmp 0x16e7c
movq -0x18(%rbp), %rax
movq 0x10(%rax), %rax
movq 0x8(%rax), %rax
movq %rax, -0x20(%rbp)
movq -0x20(%rbp), %rax
cmpl $0xd, (%rax)
jne 0x16e1a
movq -0x20(%rbp), %rax
movq 0x20(%rax), %rax
movq %rax, -0x20(%rbp)
movq -0x20(%rbp), %rdi
callq 0x158f0
movl %edx, -0x60(%rbp)
movq %rax, -0x68(%rbp)
movq -0x68(%rbp), %rax
movq %rax, -0x58(%rbp)
movl -0x60(%rbp), %eax
movl %eax, -0x50(%rbp)
movsbl -0x57(%rbp), %esi
leaq 0x5514(%rip), %rdi      # 0x1c357
movb $0x0, %al
callq 0x30c0
movq -0x18(%rbp), %rax
movq 0x10(%rax), %rdi
movq -0x18(%rbp), %rax
movq 0x8(%rax), %rsi
movq -0x18(%rbp), %rax
subq (%rax), %rsi
callq 0x16f30
movq 0xa163(%rip), %rax      # 0x20fd0
movq (%rax), %rsi
leaq 0x5497(%rip), %rdi      # 0x1c30e
callq 0x3100
movq -0x38(%rbp), %rax
movq %rax, -0x28(%rbp)
jmp 0x16a76
cmpq $0x0, -0x40(%rbp)
je 0x16eb0
movq -0x40(%rbp), %rax
movl %eax, %esi
leaq 0x546d(%rip), %rdi      # 0x1c30a
movb $0x0, %al
callq 0x30c0
movq -0x28(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x28(%rbp)
movq -0x28(%rbp), %rax
movq -0x8(%rbp), %rcx
movq 0x10(%rcx), %rcx
cmpq 0x10(%rcx), %rax
ja 0x16ec4
jmp 0x16ee3
leaq 0x5490(%rip), %rdi      # 0x1c35b
leaq 0x51b6(%rip), %rsi      # 0x1c088
movl $0x5b8, %edx            # imm = 0x5B8
leaq 0x53e2(%rip), %rcx      # 0x1c2c0
callq 0x30f0
movq -0x28(%rbp), %rax
movq -0x8(%rbp), %rcx
movq 0x10(%rcx), %rcx
cmpq 0x10(%rcx), %rax
jae 0x16f13
movq -0x8(%rbp), %rax
movq 0x10(%rax), %rax
movq 0x10(%rax), %rsi
subq -0x28(%rbp), %rsi
leaq 0x5467(%rip), %rdi      # 0x1c373
movb $0x0, %al
callq 0x30c0
leaq 0x4abc(%rip), %rdi      # 0x1b9d6
callq 0x3060
addq $0x90, %rsp
popq %rbp
retq
nopl (%rax,%rax)