// File: /workspace/github_c_makefile_star2_O3/michaelforney[P]cproc/qbe.c
// Function: emittype
static void
emittype(struct type *t)
{
	static unsigned id;
	struct member *m, *other;
	struct type *sub;
	unsigned long long off;

	if (t->value || t->kind != TYPESTRUCT && t->kind != TYPEUNION)
		return;
	t->value = xmalloc(sizeof(*t->value));
	t->value->kind = VALUE_TYPE;
	t->value->u.name = t->u.structunion.tag;
	t->value->id = ++id;
	for (m = t->u.structunion.members; m; m = m->next) {
		for (sub = m->type; sub->kind == TYPEARRAY; sub = sub->base)
			;
		emittype(sub);
	}
	fputs("type ", stdout);
	emitname(t->value);
	if (t == targ->typevalist) {
		printf(" = align %d { %llu }\n", t->align, t->size);
		return;
	}
	fputs(" = { ", stdout);
	for (m = t->u.structunion.members, off = 0; m;) {
		if (t->kind == TYPESTRUCT) {
			/* look for a subsequent member with a larger storage unit */
			for (other = m->next; other; other = other->next) {
				if (other->offset >= ALIGNUP(m->offset + 1, 8))
					break;
				if (other->offset <= m->offset)
					m = other;
			}
			off = m->offset + m->type->size;
		} else {
			fputs("{ ", stdout);
		}
		for (sub = m->type; sub->kind == TYPEARRAY; sub = sub->base)
			;
		emitclass(qbetype(sub).data, sub->value);
		if (m->type->size > sub->size)
			printf(" %llu", m->type->size / sub->size);
		if (t->kind == TYPESTRUCT) {
			fputs(", ", stdout);
			/* skip subsequent members contained within the same storage unit */
			do m = m->next;
			while (m && m->offset < off);
		} else {
			fputs(" } ", stdout);
			m = m->next;
		}
	}
	puts("}");
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
cmpq $0x0, 0x18(%rdi)
jne 0xe60f
movq %rdi, %rbx
movl (%rdi), %eax
addl $-0xf, %eax
cmpl $0x1, %eax
ja 0xe60f
movl $0x10, %edi
callq 0xe142
movq %rax, 0x18(%rbx)
movl $0x6, (%rax)
movq 0x40(%rbx), %rcx
movq %rcx, 0x8(%rax)
movl 0xdb6c(%rip), %eax      # 0x1c148
incl %eax
movl %eax, 0xdb64(%rip)      # 0x1c148
movq 0x18(%rbx), %rcx
movl %eax, 0x4(%rcx)
movq 0x48(%rbx), %r14
testq %r14, %r14
je 0xe61e
leaq 0x8(%r14), %rax
movq (%rax), %rdi
leaq 0x20(%rdi), %rax
cmpl $0xd, (%rdi)
je 0xe5f8
callq 0xe59b
movq 0x28(%r14), %r14
jmp 0xe5ef
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0xc99b(%rip), %r14      # 0x1afc0
movq (%r14), %rsi
leaq 0x79a4(%rip), %rdi      # 0x15fd3
callq 0x30f0
movq 0x18(%rbx), %rdi
callq 0x10edd
leaq 0xdabc(%rip), %rax      # 0x1c100
movq (%rax), %rax
cmpq %rbx, 0x8(%rax)
je 0xe76b
movq (%r14), %rsi
leaq 0x7994(%rip), %rdi      # 0x15fef
callq 0x30f0
movq 0x48(%rbx), %r15
testq %r15, %r15
je 0xe751
xorl %r12d, %r12d
cmpl $0xf, (%rbx)
jne 0xe6a4
movq 0x28(%r15), %rax
testq %rax, %rax
je 0xe6b5
movq 0x18(%rax), %rcx
movq 0x18(%r15), %rdx
movq %rdx, %rsi
andq $-0x8, %rsi
addq $0x8, %rsi
cmpq %rsi, %rcx
jae 0xe6b5
cmpq %rdx, %rcx
ja 0xe69e
movq %rax, %r15
movq 0x28(%rax), %rax
jmp 0xe679
movq (%r14), %rsi
leaq 0x7944(%rip), %rdi      # 0x15ff2
callq 0x30f0
jmp 0xe6c1
movq 0x8(%r15), %rax
movq 0x10(%rax), %r12
addq 0x18(%r15), %r12
leaq 0x8(%r15), %r13
movq %r13, %rax
movq (%rax), %rbp
leaq 0x20(%rbp), %rax
cmpl $0xd, (%rbp)
je 0xe6c8
movq %rbp, %rdi
callq 0x102e0
shrl $0x8, %eax
movsbl %al, %edi
movq 0x18(%rbp), %rsi
callq 0x10eb8
movq (%r13), %rax
movq 0x10(%rax), %rax
movq 0x10(%rbp), %rcx
cmpq %rcx, %rax
jbe 0xe713
xorl %edx, %edx
divq %rcx
leaq 0x3f95(%rip), %rdi      # 0x1269e
movq %rax, %rsi
xorl %eax, %eax
callq 0x30b0
cmpl $0xf, (%rbx)
movq (%r14), %rsi
jne 0xe738
leaq 0x7458(%rip), %rdi      # 0x15b7a
callq 0x30f0
movq 0x28(%r15), %r15
testq %r15, %r15
je 0xe751
cmpq %r12, 0x18(%r15)
jb 0xe727
jmp 0xe748
leaq 0x78b6(%rip), %rdi      # 0x15ff5
callq 0x30f0
movq 0x28(%r15), %r15
testq %r15, %r15
jne 0xe670
leaq 0x6bee(%rip), %rdi      # 0x15346
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x3050
movl 0x8(%rbx), %esi
movq 0x10(%rbx), %rdx
leaq 0x7860(%rip), %rdi      # 0x15fd9
xorl %eax, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x30b0