// File: /workspace/github_c_makefile_star2_O1/michaelforney[P]cproc/qbe.c
// Function: emitfunc
void
emitfunc(struct func *f, bool global)
{
	struct block *b;
	struct inst **inst, **instend;
	struct decl *p;
	struct value *v;

	if (f->end->jump.kind == JUMP_NONE) {
		v = NULL;
		/* implicitly return 0 from main if we reach the end of the function */
		if (strcmp(f->name, "main") == 0 && f->type->base == &typeint)
			v = mkintconst(0);
		funcret(f, v);
	}
	if (global)
		puts("export");
	fputs("function ", stdout);
	if (f->type->base != &typevoid) {
		emitclass(qbetype(f->type->base).base, f->type->base->value);
		putchar(' ');
	}
	emitname(f->decl->value);
	putchar('(');
	for (p = f->type->u.func.params, v = f->paramtemps; p; p = p->next, ++v) {
		if (p != f->type->u.func.params)
			fputs(", ", stdout);
		emitclass(qbetype(p->type).base, p->type->value);
		putchar(' ');
		emitname(v);
	}
	if (f->type->u.func.isvararg) {
		if (f->type->u.func.params)
			fputs(", ", stdout);
		fputs("...", stdout);
	}
	puts(") {");
	for (b = f->start; b; b = b->next) {
		emitname(&b->label);
		putchar('\n');
		if (b->phi.res.kind) {
			putchar('\t');
			emitvalue(&b->phi.res);
			printf(" =%c phi ", b->phi.class);
			emitname(&b->phi.blk[0]->label);
			putchar(' ');
			emitvalue(b->phi.val[0]);
			fputs(", ", stdout);
			emitname(&b->phi.blk[1]->label);
			putchar(' ');
			emitvalue(b->phi.val[1]);
			putchar('\n');
		}
		instend = (struct inst **)((char *)b->insts.val + b->insts.len);
		for (inst = b->insts.val; inst != instend;)
			inst = emitinst(inst, instend);
		emitjump(&b->jump);
	}
	puts("}");
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movl %esi, %ebp
movq %rdi, %rbx
movq 0x30(%rdi), %rax
cmpl $0x0, 0x60(%rax)
jne 0x10a39
movq 0x10(%rbx), %rdi
leaq 0x5021(%rip), %rsi      # 0x15a25
callq 0x3140
testl %eax, %eax
jne 0x10a22
movq 0x20(%rbx), %rax
movq 0x20(%rax), %rax
cmpq 0xa594(%rip), %rax      # 0x1afb0
je 0x10e41
xorl %eax, %eax
movq 0x30(%rbx), %rcx
cmpl $0x0, 0x60(%rcx)
jne 0x10a39
movl $0x3, 0x60(%rcx)
movq %rax, 0x68(%rcx)
testb %bpl, %bpl
je 0x10a4a
leaq 0x4fe5(%rip), %rdi      # 0x15a2a
callq 0x3050
movq 0xa56f(%rip), %r13      # 0x1afc0
movq (%r13), %rsi
leaq 0x4fd5(%rip), %rdi      # 0x15a31
callq 0x30f0
movq 0x20(%rbx), %rax
movq 0x20(%rax), %rdi
cmpq 0xa530(%rip), %rdi      # 0x1afa0
je 0x10a95
callq 0x102ec
movsbl %al, %edi
movq 0x20(%rbx), %rax
movq 0x20(%rax), %rax
movq 0x18(%rax), %rsi
callq 0x10e9c
movl $0x20, %edi
callq 0x3030
movq (%rbx), %rax
movq 0x20(%rax), %rdi
callq 0x10ec1
movl $0x28, %edi
callq 0x3030
movq 0x20(%rbx), %rax
movq 0x48(%rax), %r12
testq %r12, %r12
je 0x10b14
movq 0x18(%rbx), %r14
leaq 0x5017(%rip), %r15      # 0x15ada
movq 0x20(%rbx), %rax
cmpq 0x48(%rax), %r12
je 0x10ad9
movq (%r13), %rsi
movq %r15, %rdi
callq 0x30f0
movq 0x10(%r12), %rdi
callq 0x102ec
movsbl %al, %edi
movq 0x10(%r12), %rax
movq 0x18(%rax), %rsi
callq 0x10e9c
movl $0x20, %edi
callq 0x3030
movq %r14, %rdi
callq 0x10ec1
addq $0x10, %r14
movq 0x38(%r12), %r12
testq %r12, %r12
jne 0x10ac3
movq 0x20(%rbx), %rax
cmpb $0x1, 0x40(%rax)
jne 0x10b45
cmpq $0x0, 0x48(%rax)
je 0x10b35
movq (%r13), %rsi
leaq 0x4faa(%rip), %rdi      # 0x15ada
callq 0x30f0
movq (%r13), %rsi
leaq 0x54b4(%rip), %rdi      # 0x15ff4
callq 0x30f0
leaq 0x4eef(%rip), %rdi      # 0x15a3b
callq 0x3050
movq 0x28(%rbx), %rbx
testq %rbx, %rbx
je 0x10e27
leaq 0x548d(%rip), %r14      # 0x15ff2
movq %rbx, %rdi
callq 0x10ec1
movl $0xa, %edi
callq 0x3030
cmpl $0x0, 0x50(%rbx)
je 0x10bf6
leaq 0x50(%rbx), %rbp
movl $0x9, %edi
callq 0x3030
movq %rbp, %rdi
callq 0x10f5d
movl 0x28(%rbx), %esi
leaq 0x4ea2(%rip), %rdi      # 0x15a3f
xorl %eax, %eax
callq 0x30b0
movq 0x30(%rbx), %rdi
callq 0x10ec1
movl $0x20, %edi
callq 0x3030
movq 0x40(%rbx), %rdi
callq 0x10f5d
movq (%r13), %rsi
leaq 0x4f0f(%rip), %rdi      # 0x15ada
callq 0x30f0
movq 0x38(%rbx), %rdi
callq 0x10ec1
movl $0x20, %edi
callq 0x3030
movq 0x48(%rbx), %rdi
callq 0x10f5d
movl $0xa, %edi
callq 0x3030
movq %rbx, (%rsp)
movq 0x18(%rbx), %rbp
testq %rbp, %rbp
je 0x10d47
movq (%rsp), %rax
movq 0x10(%rax), %r15
addq %r15, %rbp
movq (%r15), %rbx
movl $0x9, %edi
callq 0x3030
cmpl $0x59, (%rbx)
jae 0x10e5e
cmpl $0x0, 0x8(%rbx)
je 0x10c5d
leaq 0x8(%rbx), %rdi
callq 0x10f5d
movq (%r13), %rsi
leaq 0x53ad(%rip), %rdi      # 0x15fef
callq 0x30f0
movl 0x4(%rbx), %edi
movq 0x20(%rbx), %rsi
callq 0x10e9c
movl $0x20, %edi
callq 0x3030
movl (%rbx), %eax
leaq 0x9e8a(%rip), %rcx      # 0x1aaf0
movq (%rcx,%rax,8), %rdi
movq (%r13), %rsi
callq 0x30f0
movl $0x20, %edi
callq 0x3030
movq 0x18(%rbx), %rdi
callq 0x10f5d
addq $0x8, %r15
cmpl $0x56, (%rbx)
jne 0x10d14
movl $0x28, %edi
callq 0x3030
cmpq %rbp, %r15
je 0x10d08
movl $0x1, %ebx
movq (%r15), %r12
movl (%r12), %eax
cmpl $0x59, %eax
je 0x10cc6
cmpl $0x5a, %eax
jne 0x10d08
movq (%r13), %rsi
movq %r14, %rdi
callq 0x30f0
jmp 0x10cff
testl %ebx, %ebx
jne 0x10cda
movq (%r13), %rsi
leaq 0x4e05(%rip), %rdi      # 0x15ada
callq 0x30f0
movl 0x4(%r12), %edi
movq 0x20(%r12), %rsi
callq 0x10e9c
movl $0x20, %edi
callq 0x3030
movq 0x18(%r12), %rdi
callq 0x10f5d
xorl %ebx, %ebx
addq $0x8, %r15
cmpq %rbp, %r15
jne 0x10ca7
movl $0x29, %edi
callq 0x3030
jmp 0x10d34
cmpq $0x0, 0x20(%rbx)
je 0x10d34
movq (%r13), %rsi
leaq 0x4db4(%rip), %rdi      # 0x15ada
callq 0x30f0
movq 0x20(%rbx), %rdi
callq 0x10f5d
movl $0xa, %edi
callq 0x3030
cmpq %rbp, %r15
jne 0x10c12
movq (%rsp), %rbx
movl 0x60(%rbx), %eax
cmpq $0x4, %rax
ja 0x10e7d
leaq 0x4a79(%rip), %rcx      # 0x157d8
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq (%r13), %rsi
leaq 0x5459(%rip), %rdi      # 0x161cc
callq 0x30f0
movq 0x70(%rbx), %rdi
jmp 0x10dd8
movq (%r13), %rsi
leaq 0x544f(%rip), %rdi      # 0x161d8
callq 0x30f0
jmp 0x10e17
movq (%r13), %rsi
leaq 0x5434(%rip), %rdi      # 0x161d2
callq 0x30f0
movq 0x68(%rbx), %rdi
callq 0x10f5d
movq (%r13), %rsi
leaq 0x4d23(%rip), %r15      # 0x15ada
movq %r15, %rdi
callq 0x30f0
movq 0x70(%rbx), %rdi
callq 0x10ec1
movq (%r13), %rsi
movq %r15, %rdi
callq 0x30f0
movq 0x78(%rbx), %rdi
callq 0x10ec1
jmp 0x10e0d
movq (%r13), %rsi
leaq 0x53dd(%rip), %rdi      # 0x161c7
callq 0x30f0
cmpq $0x0, 0x68(%rbx)
je 0x10e0d
movq (%r13), %rsi
movl $0x20, %edi
callq 0x3110
movq 0x68(%rbx), %rdi
callq 0x10f5d
movl $0xa, %edi
callq 0x3030
movq 0x80(%rbx), %rbx
testq %rbx, %rbx
jne 0x10b65
leaq 0x4480(%rip), %rdi      # 0x152ae
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x3050
movl $0x10, %edi
callq 0xe13e
movl $0x2, (%rax)
movq $0x0, 0x8(%rax)
jmp 0x10a24
leaq 0x5138(%rip), %rdi      # 0x15f9d
leaq 0x49e8(%rip), %rsi      # 0x15854
leaq 0x5145(%rip), %rcx      # 0x15fb8
movl $0x4a6, %edx            # imm = 0x4A6
callq 0x30e0
leaq 0x4e3a(%rip), %rdi      # 0x15cbe
leaq 0x49c9(%rip), %rsi      # 0x15854
leaq 0x534c(%rip), %rcx      # 0x161de
movl $0x4f1, %edx            # imm = 0x4F1
callq 0x30e0