// File: /workspace/github_c_makefile_star2_O3/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), %r14
cmpl $0x0, 0x60(%r14)
jne 0x10a30
movq 0x10(%rbx), %rdi
leaq 0x50c1(%rip), %rsi      # 0x15ac5
callq 0x3140
testl %eax, %eax
jne 0x10a22
movq 0x20(%rbx), %rax
movq 0x20(%rax), %rax
cmpq 0xa594(%rip), %rax      # 0x1afb0
je 0x10e4e
xorl %eax, %eax
movl $0x3, 0x60(%r14)
movq %rax, 0x68(%r14)
testb %bpl, %bpl
je 0x10a41
leaq 0x508e(%rip), %rdi      # 0x15aca
callq 0x3050
movq 0xa578(%rip), %r13      # 0x1afc0
movq (%r13), %rsi
leaq 0x507e(%rip), %rdi      # 0x15ad1
callq 0x30f0
movq 0x20(%rbx), %rax
movq 0x20(%rax), %rdi
cmpq 0xa539(%rip), %rdi      # 0x1afa0
je 0x10a8c
callq 0x102e0
movsbl %al, %edi
movq 0x20(%rbx), %rax
movq 0x20(%rax), %rax
movq 0x18(%rax), %rsi
callq 0x10eb8
movl $0x20, %edi
callq 0x3030
movq (%rbx), %rax
movq 0x20(%rax), %rdi
callq 0x10edd
movl $0x28, %edi
callq 0x3030
movq 0x20(%rbx), %rax
movq 0x48(%rax), %r12
testq %r12, %r12
je 0x10b0f
movq 0x18(%rbx), %r14
leaq 0x50c0(%rip), %r15      # 0x15b7a
movq 0x20(%rbx), %rax
cmpq 0x48(%rax), %r12
je 0x10ad0
movq (%r13), %rsi
movq %r15, %rdi
callq 0x30f0
movq 0x10(%r12), %rdi
callq 0x102e0
movsbl %al, %edi
movq 0x10(%r12), %rax
movq 0x18(%rax), %rsi
callq 0x10eb8
movl $0x20, %edi
callq 0x3030
movq %r14, %rdi
callq 0x10edd
addq $0x10, %r14
movq 0x38(%r12), %r12
testq %r12, %r12
jne 0x10aba
movq 0x20(%rbx), %rax
cmpb $0x1, 0x40(%rax)
jne 0x10b3c
cmpq $0x0, 0x48(%rax)
je 0x10b2c
movq (%r13), %rsi
leaq 0x5053(%rip), %rdi      # 0x15b7a
callq 0x30f0
movq (%r13), %rsi
leaq 0x555d(%rip), %rdi      # 0x16094
callq 0x30f0
leaq 0x4f98(%rip), %rdi      # 0x15adb
callq 0x3050
movq 0x28(%rbx), %rbx
testq %rbx, %rbx
je 0x10e34
leaq 0x5536(%rip), %r14      # 0x16092
movq %rbx, %rdi
callq 0x10edd
movl $0xa, %edi
callq 0x3030
cmpl $0x0, 0x50(%rbx)
je 0x10bed
leaq 0x50(%rbx), %rbp
movl $0x9, %edi
callq 0x3030
movq %rbp, %rdi
callq 0x10f79
movl 0x28(%rbx), %esi
leaq 0x4f4b(%rip), %rdi      # 0x15adf
xorl %eax, %eax
callq 0x30b0
movq 0x30(%rbx), %rdi
callq 0x10edd
movl $0x20, %edi
callq 0x3030
movq 0x40(%rbx), %rdi
callq 0x10f79
movq (%r13), %rsi
leaq 0x4fb8(%rip), %rdi      # 0x15b7a
callq 0x30f0
movq 0x38(%rbx), %rdi
callq 0x10edd
movl $0x20, %edi
callq 0x3030
movq 0x48(%rbx), %rdi
callq 0x10f79
movl $0xa, %edi
callq 0x3030
movq %rbx, (%rsp)
movq 0x18(%rbx), %rbp
testq %rbp, %rbp
je 0x10d54
movq (%rsp), %rax
movq 0x10(%rax), %r15
addq %r15, %rbp
movq (%r15), %rbx
movl $0x9, %edi
callq 0x3030
movl (%rbx), %eax
cmpl $0x59, %eax
jae 0x10e7a
cmpl $0x0, 0x8(%rbx)
je 0x10c58
leaq 0x8(%rbx), %rdi
callq 0x10f79
movq (%r13), %rsi
leaq 0x5454(%rip), %rdi      # 0x1608f
callq 0x30f0
movl 0x4(%rbx), %edi
movq 0x20(%rbx), %rsi
callq 0x10eb8
movl $0x20, %edi
callq 0x3030
movl (%rbx), %eax
movl %eax, %eax
leaq 0x9e8f(%rip), %rcx      # 0x1aaf0
movq (%rcx,%rax,8), %rdi
movq (%r13), %rsi
callq 0x30f0
movl $0x20, %edi
callq 0x3030
movq 0x18(%rbx), %rdi
callq 0x10f79
addq $0x8, %r15
cmpl $0x56, (%rbx)
jne 0x10d0f
movl $0x28, %edi
callq 0x3030
movq %rbp, %rbx
cmpq %rbp, %r15
je 0x10d34
movl $0x1, %ebx
movq (%r15), %r12
movl (%r12), %eax
cmpl $0x59, %eax
je 0x10cc8
cmpl $0x5a, %eax
jne 0x10d31
movq (%r13), %rsi
movq %r14, %rdi
callq 0x30f0
jmp 0x10d01
testl %ebx, %ebx
jne 0x10cdc
movq (%r13), %rsi
leaq 0x4ea3(%rip), %rdi      # 0x15b7a
callq 0x30f0
movl 0x4(%r12), %edi
movq 0x20(%r12), %rsi
callq 0x10eb8
movl $0x20, %edi
callq 0x3030
movq 0x18(%r12), %rdi
callq 0x10f79
xorl %ebx, %ebx
addq $0x8, %r15
cmpq %rbp, %r15
jne 0x10ca9
movq %rbp, %rbx
jmp 0x10d34
cmpq $0x0, 0x20(%rbx)
je 0x10d41
movq (%r13), %rsi
leaq 0x4e59(%rip), %rdi      # 0x15b7a
callq 0x30f0
movq 0x20(%rbx), %rdi
callq 0x10f79
jmp 0x10d41
movq %r15, %rbx
movl $0x29, %edi
callq 0x3030
movq %rbx, %r15
movl $0xa, %edi
callq 0x3030
cmpq %rbp, %r15
jne 0x10c09
movq (%rsp), %rbx
movl 0x60(%rbx), %eax
cmpq $0x4, %rax
ja 0x10e99
leaq 0x4b0c(%rip), %rcx      # 0x15878
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq (%r13), %rsi
leaq 0x54ec(%rip), %rdi      # 0x1626c
callq 0x30f0
movq 0x70(%rbx), %rdi
jmp 0x10de5
movq (%r13), %rsi
leaq 0x54e2(%rip), %rdi      # 0x16278
callq 0x30f0
jmp 0x10e24
movq (%r13), %rsi
leaq 0x54c7(%rip), %rdi      # 0x16272
callq 0x30f0
movq 0x68(%rbx), %rdi
callq 0x10f79
movq (%r13), %rsi
leaq 0x4db6(%rip), %r15      # 0x15b7a
movq %r15, %rdi
callq 0x30f0
movq 0x70(%rbx), %rdi
callq 0x10edd
movq (%r13), %rsi
movq %r15, %rdi
callq 0x30f0
movq 0x78(%rbx), %rdi
callq 0x10edd
jmp 0x10e1a
movq (%r13), %rsi
leaq 0x5470(%rip), %rdi      # 0x16267
callq 0x30f0
cmpq $0x0, 0x68(%rbx)
je 0x10e1a
movq (%r13), %rsi
movl $0x20, %edi
callq 0x3110
movq 0x68(%rbx), %rdi
callq 0x10f79
movl $0xa, %edi
callq 0x3030
movq 0x80(%rbx), %rbx
testq %rbx, %rbx
jne 0x10b5c
leaq 0x450b(%rip), %rdi      # 0x15346
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x3050
movl $0x10, %edi
callq 0xe142
movl $0x2, (%rax)
movq $0x0, 0x8(%rax)
movq 0x30(%rbx), %r14
cmpl $0x0, 0x60(%r14)
jne 0x10a30
jmp 0x10a24
leaq 0x51bc(%rip), %rdi      # 0x1603d
leaq 0x4a6c(%rip), %rsi      # 0x158f4
leaq 0x51c9(%rip), %rcx      # 0x16058
movl $0x4a6, %edx            # imm = 0x4A6
callq 0x30e0
leaq 0x4ebe(%rip), %rdi      # 0x15d5e
leaq 0x4a4d(%rip), %rsi      # 0x158f4
leaq 0x53d0(%rip), %rcx      # 0x1627e
movl $0x4f1, %edx            # imm = 0x4F1
callq 0x30e0