// File: /workspace/github_c_makefile_star2_O2/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, %r12
movq 0x30(%rdi), %rbx
cmpl $0x0, 0x60(%rbx)
jne 0xf3dd
movq %r12, %r14
movq 0x10(%r12), %rdi
leaq 0x56d7(%rip), %rsi      # 0x14a89
callq 0x3140
testl %eax, %eax
jne 0xf3d0
movq 0x20(%r14), %rax
movq 0x20(%rax), %rax
cmpq 0xbbe6(%rip), %rax      # 0x1afb0
je 0xf819
xorl %eax, %eax
movl $0x3, 0x60(%rbx)
movq %rax, 0x68(%rbx)
testb %bpl, %bpl
je 0xf3ee
leaq 0x56a5(%rip), %rdi      # 0x14a8e
callq 0x3050
movq 0xbbcb(%rip), %r13      # 0x1afc0
movq (%r13), %rsi
leaq 0x5695(%rip), %rdi      # 0x14a95
callq 0x30f0
movq %r12, %rbx
movq 0x20(%r12), %rax
movq 0x20(%rax), %rdi
cmpq 0xbb88(%rip), %rdi      # 0x1afa0
je 0xf43b
callq 0xee06
movsbl %al, %edi
movq 0x20(%rbx), %rax
movq 0x20(%rax), %rax
movq 0x18(%rax), %rsi
callq 0xf871
pushq $0x20
popq %rdi
callq 0x3030
movq (%rbx), %rax
movq 0x20(%rax), %rdi
callq 0xf896
pushq $0x28
popq %rdi
callq 0x3030
movq 0x18(%rbx), %r14
movq 0x20(%rbx), %rbx
addq $0x48, %rbx
pushq $0x20
popq %rbp
leaq 0x56d9(%rip), %r15      # 0x14b3e
movq (%rbx), %rbx
movq 0x20(%r12), %rax
testq %rbx, %rbx
je 0xf4b6
cmpq 0x48(%rax), %rbx
je 0xf484
movq (%r13), %rsi
movq %r15, %rdi
callq 0x30f0
movq 0x10(%rbx), %rdi
callq 0xee06
movsbl %al, %edi
movq 0x10(%rbx), %rax
movq 0x18(%rax), %rsi
callq 0xf871
movl %ebp, %edi
callq 0x3030
movq %r14, %rdi
callq 0xf896
addq $0x38, %rbx
addq $0x10, %r14
jmp 0xf465
cmpb $0x1, 0x40(%rax)
movq %r12, %r15
jne 0xf4e6
cmpq $0x0, 0x48(%rax)
je 0xf4d6
movq (%r13), %rsi
leaq 0x566d(%rip), %rdi      # 0x14b3e
callq 0x30f0
movq (%r13), %rsi
leaq 0x5b77(%rip), %rdi      # 0x15058
callq 0x30f0
leaq 0x55b2(%rip), %rdi      # 0x14a9f
callq 0x3050
addq $0x28, %r15
pushq $0xa
popq %r14
pushq $0x20
popq %r13
movq (%r15), %r15
testq %r15, %r15
je 0xf7ff
movq %r15, %rdi
callq 0xf896
movl %r14d, %edi
callq 0x3030
cmpl $0x0, 0x50(%r15)
je 0xf599
leaq 0x50(%r15), %rbx
pushq $0x9
popq %rdi
callq 0x3030
movq %rbx, %rdi
callq 0xf930
movl 0x28(%r15), %esi
leaq 0x5563(%rip), %rdi      # 0x14aa3
xorl %eax, %eax
callq 0x30b0
movq 0x30(%r15), %rdi
callq 0xf896
movl %r13d, %edi
callq 0x3030
movq 0x40(%r15), %rdi
callq 0xf930
movq 0xba58(%rip), %rax      # 0x1afc0
movq (%rax), %rsi
leaq 0x55cc(%rip), %rdi      # 0x14b3e
callq 0x30f0
movq 0x38(%r15), %rdi
callq 0xf896
movl %r13d, %edi
callq 0x3030
movq 0x48(%r15), %rdi
callq 0xf930
movl %r14d, %edi
callq 0x3030
movq 0x10(%r15), %rbx
movq %r15, (%rsp)
movq 0x18(%r15), %rbp
addq %rbx, %rbp
cmpq %rbp, %rbx
je 0xf711
movq (%rbx), %r12
pushq $0x9
popq %rdi
callq 0x3030
movl (%r12), %eax
cmpl $0x59, %eax
jae 0xf833
cmpl $0x0, 0x8(%r12)
movl %r13d, %r15d
movq 0xb9e7(%rip), %r14      # 0x1afc0
je 0xf60f
leaq 0x8(%r12), %rdi
callq 0xf930
movq (%r14), %rsi
leaq 0x5a64(%rip), %rdi      # 0x15053
callq 0x30f0
movl 0x4(%r12), %edi
movq 0x20(%r12), %rsi
callq 0xf871
movl %r15d, %edi
callq 0x3030
movl (%r12), %eax
movl %eax, %eax
leaq 0xb4d8(%rip), %rcx      # 0x1aaf0
movq (%rcx,%rax,8), %rdi
movq (%r14), %rsi
callq 0x30f0
movl %r15d, %edi
callq 0x3030
movq 0x18(%r12), %rdi
callq 0xf930
addq $0x8, %rbx
cmpl $0x56, (%r12)
jne 0xf6cb
pushq $0x28
popq %rdi
callq 0x3030
pushq $0x1
popq %r12
leaq 0x59fe(%rip), %r14      # 0x15056
cmpq %rbp, %rbx
je 0xf6f5
movq (%rbx), %r15
movl (%r15), %eax
cmpl $0x59, %eax
je 0xf689
cmpl $0x5a, %eax
jne 0xf6f8
movq 0xb944(%rip), %rax      # 0x1afc0
movq (%rax), %rsi
movq %r14, %rdi
callq 0x30f0
jmp 0xf6c5
testl %r12d, %r12d
jne 0xf6a4
movq 0xb92b(%rip), %rax      # 0x1afc0
movq (%rax), %rsi
leaq 0x549f(%rip), %rdi      # 0x14b3e
callq 0x30f0
movl 0x4(%r15), %edi
movq 0x20(%r15), %rsi
callq 0xf871
movl %r13d, %edi
callq 0x3030
movq 0x18(%r15), %rdi
callq 0xf930
xorl %r12d, %r12d
addq $0x8, %rbx
jmp 0xf658
cmpq $0x0, 0x20(%r12)
je 0xf700
movq 0xb8e6(%rip), %rax      # 0x1afc0
movq (%rax), %rsi
leaq 0x545a(%rip), %rdi      # 0x14b3e
callq 0x30f0
movq 0x20(%r12), %rdi
callq 0xf930
jmp 0xf700
movq %rbp, %rbx
pushq $0x29
popq %rdi
callq 0x3030
pushq $0xa
popq %r14
movl %r14d, %edi
callq 0x3030
jmp 0xf5a8
movq (%rsp), %r15
movl 0x60(%r15), %eax
cmpq $0x4, %rax
ja 0xf852
leaq 0x50de(%rip), %rcx      # 0x14808
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq 0xb886(%rip), %rax      # 0x1afc0
movq (%rax), %rsi
leaq 0x5aec(%rip), %rdi      # 0x15230
callq 0x30f0
movq 0x70(%r15), %rdi
jmp 0xf7b6
movq 0xb86a(%rip), %rax      # 0x1afc0
movq (%rax), %rsi
leaq 0x5adc(%rip), %rdi      # 0x1523c
callq 0x30f0
jmp 0xf7f6
movq 0xb84f(%rip), %r12      # 0x1afc0
movq (%r12), %rsi
leaq 0x5aba(%rip), %rdi      # 0x15236
callq 0x30f0
movq 0x68(%r15), %rdi
callq 0xf930
movq (%r12), %rsi
leaq 0x53a9(%rip), %rbx      # 0x14b3e
movq %rbx, %rdi
callq 0x30f0
movq 0x70(%r15), %rdi
callq 0xf896
movq (%r12), %rsi
movq %rbx, %rdi
callq 0x30f0
movq 0x78(%r15), %rdi
callq 0xf896
jmp 0xf7ee
movq 0xb7fc(%rip), %rbx      # 0x1afc0
movq (%rbx), %rsi
leaq 0x5a5d(%rip), %rdi      # 0x1522b
callq 0x30f0
cmpq $0x0, 0x68(%r15)
je 0xf7ee
movq (%rbx), %rsi
movl %r13d, %edi
callq 0x3110
movq 0x68(%r15), %rdi
callq 0xf930
movl %r14d, %edi
callq 0x3030
subq $-0x80, %r15
jmp 0xf4fe
leaq 0x4b08(%rip), %rdi      # 0x1430e
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x3050
xorl %edi, %edi
callq 0xd317
movq 0x30(%r14), %rbx
cmpl $0x0, 0x60(%rbx)
jne 0xf3dd
jmp 0xf3d2
leaq 0x57c7(%rip), %rdi      # 0x15001
leaq 0x5077(%rip), %rsi      # 0x148b8
leaq 0x57d4(%rip), %rcx      # 0x1501c
movl $0x4a6, %edx            # imm = 0x4A6
callq 0x30e0
leaq 0x54c9(%rip), %rdi      # 0x14d22
leaq 0x5058(%rip), %rsi      # 0x148b8
leaq 0x59db(%rip), %rcx      # 0x15242
movl $0x4f1, %edx            # imm = 0x4F1
callq 0x30e0