// File: /workspace/github_c_makefile_star2_O1/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 0xe613
movq %rdi, %rbx
movl (%rdi), %eax
addl $-0xf, %eax
cmpl $0x1, %eax
ja 0xe613
movl $0x10, %edi
callq 0xe13e
movq %rax, 0x18(%rbx)
movl $0x6, (%rax)
movq 0x40(%rbx), %rcx
movq %rcx, 0x8(%rax)
movl 0xdb68(%rip), %eax      # 0x1c148
incl %eax
movl %eax, 0xdb60(%rip)      # 0x1c148
movq 0x18(%rbx), %rcx
movl %eax, 0x4(%rcx)
movq 0x48(%rbx), %r14
testq %r14, %r14
je 0xe622
leaq 0x8(%r14), %rax
movq (%rax), %rdi
leaq 0x20(%rdi), %rax
cmpl $0xd, (%rdi)
je 0xe5fc
callq 0xe59f
movq 0x28(%r14), %r14
jmp 0xe5f3
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0xc997(%rip), %r14      # 0x1afc0
movq (%r14), %rsi
leaq 0x7900(%rip), %rdi      # 0x15f33
callq 0x30f0
movq 0x18(%rbx), %rdi
callq 0x10ec1
leaq 0xdab8(%rip), %rax      # 0x1c100
movq (%rax), %rax
cmpq %rbx, 0x8(%rax)
je 0xe774
movq (%r14), %rsi
leaq 0x78f0(%rip), %rdi      # 0x15f4f
callq 0x30f0
movq 0x48(%rbx), %r15
testq %r15, %r15
je 0xe75a
xorl %r12d, %r12d
cmpl $0xf, (%rbx)
jne 0xe6a8
movq 0x28(%r15), %rax
testq %rax, %rax
je 0xe6b9
movq 0x18(%rax), %rcx
movq 0x18(%r15), %rdx
movq %rdx, %rsi
andq $-0x8, %rsi
addq $0x8, %rsi
cmpq %rsi, %rcx
jae 0xe6b9
cmpq %rdx, %rcx
ja 0xe6a2
movq %rax, %r15
movq 0x28(%rax), %rax
jmp 0xe67d
movq (%r14), %rsi
leaq 0x78a0(%rip), %rdi      # 0x15f52
callq 0x30f0
jmp 0xe6c5
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 0xe6cc
movq %rbp, %rdi
callq 0x102ec
shrl $0x8, %eax
movsbl %al, %edi
movq 0x18(%rbp), %rsi
callq 0x10e9c
movq (%r13), %rax
movq 0x10(%rax), %rax
movq 0x10(%rbp), %rcx
cmpq %rcx, %rax
jbe 0xe717
xorl %edx, %edx
divq %rcx
leaq 0x3f31(%rip), %rdi      # 0x1263e
movq %rax, %rsi
xorl %eax, %eax
callq 0x30b0
cmpl $0xf, (%rbx)
movq (%r14), %rsi
jne 0xe73c
leaq 0x73b4(%rip), %rdi      # 0x15ada
callq 0x30f0
movq 0x28(%r15), %r15
testq %r15, %r15
je 0xe74e
cmpq %r12, 0x18(%r15)
jb 0xe72b
jmp 0xe751
leaq 0x7812(%rip), %rdi      # 0x15f55
callq 0x30f0
movq 0x28(%r15), %r15
jmp 0xe751
xorl %r15d, %r15d
testq %r15, %r15
jne 0xe674
leaq 0x6b4d(%rip), %rdi      # 0x152ae
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 0x77b7(%rip), %rdi      # 0x15f39
xorl %eax, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x30b0