// File: /workspace/github_c_makefile_star2_O2/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 0xd521
movq %rdi, %rbx
movl (%rdi), %eax
addl $-0xf, %eax
cmpl $0x1, %eax
ja 0xd521
pushq $0x10
popq %rdi
callq 0xd0e3
movq %rax, 0x18(%rbx)
movl $0x6, (%rax)
movq 0x40(%rbx), %rcx
movq %rcx, 0x8(%rax)
movl 0xec60(%rip), %eax      # 0x1c148
incl %eax
movl %eax, 0xec58(%rip)      # 0x1c148
movq 0x18(%rbx), %rcx
movl %eax, 0x4(%rcx)
leaq 0x48(%rbx), %r15
movq %r15, %r14
movq (%r14), %r14
testq %r14, %r14
je 0xd530
leaq 0x8(%r14), %rax
movq (%rax), %rdi
leaq 0x20(%rdi), %rax
cmpl $0xd, (%rdi)
je 0xd50a
callq 0xd4a9
addq $0x28, %r14
jmp 0xd4fe
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0xda89(%rip), %r14      # 0x1afc0
movq (%r14), %rsi
leaq 0x7a56(%rip), %rdi      # 0x14f97
callq 0x30f0
movq 0x18(%rbx), %rdi
callq 0xf896
leaq 0xebaa(%rip), %rax      # 0x1c100
movq (%rax), %rax
cmpq %rbx, 0x8(%rax)
je 0xd68d
movq (%r14), %rsi
leaq 0x7a46(%rip), %rdi      # 0x14fb3
callq 0x30f0
movq (%r15), %rbp
xorl %r15d, %r15d
testq %rbp, %rbp
je 0xd673
cmpl $0xf, (%rbx)
jne 0xd5b4
movq %rbp, %r12
movq 0x28(%rbp), %rbp
testq %rbp, %rbp
je 0xd5c8
movq 0x18(%rbp), %rax
movq 0x18(%r12), %r15
movq %r15, %rcx
andq $-0x8, %rcx
addq $0x8, %rcx
cmpq %rcx, %rax
jae 0xd5cd
cmpq %r15, %rax
cmovbeq %rbp, %r12
jmp 0xd589
movq (%r14), %rsi
leaq 0x79f8(%rip), %rdi      # 0x14fb6
callq 0x30f0
movq %rbp, %r12
jmp 0xd5d6
movq 0x18(%r12), %r15
movq 0x8(%r12), %rax
addq 0x10(%rax), %r15
leaq 0x8(%r12), %r13
movq %r13, %rax
movq (%rax), %rbp
leaq 0x20(%rbp), %rax
cmpl $0xd, (%rbp)
je 0xd5de
movq %rbp, %rdi
callq 0xee06
shrl $0x8, %eax
movsbl %al, %edi
movq 0x18(%rbp), %rsi
callq 0xf871
movq (%r13), %rax
movq 0x10(%rax), %rax
movq 0x10(%rbp), %rcx
cmpq %rcx, %rax
jbe 0xd629
xorl %edx, %edx
divq %rcx
leaq 0x407f(%rip), %rdi      # 0x1169e
movq %rax, %rsi
xorl %eax, %eax
callq 0x30b0
cmpl $0xf, (%rbx)
movq (%r14), %rsi
jne 0xd656
leaq 0x7506(%rip), %rdi      # 0x14b3e
callq 0x30f0
movq 0x28(%r12), %r12
testq %r12, %r12
je 0xd66c
cmpq %r15, 0x18(%r12)
jb 0xd63d
movq %r12, %rbp
jmp 0xd578
leaq 0x795c(%rip), %rdi      # 0x14fb9
callq 0x30f0
movq 0x28(%r12), %rbp
jmp 0xd578
xorl %ebp, %ebp
jmp 0xd578
leaq 0x6c94(%rip), %rdi      # 0x1430e
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 0x7902(%rip), %rdi      # 0x14f9d
xorl %eax, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x30b0