// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x80, %rsp
movb %sil, %al
movq %rdi, -0x8(%rbp)
andb $0x1, %al
movb %al, -0x9(%rbp)
movq -0x8(%rbp), %rax
movq 0x30(%rax), %rax
cmpl $0x0, 0x60(%rax)
jne 0x16155
movq $0x0, -0x38(%rbp)
movq -0x8(%rbp), %rax
movq 0x10(%rax), %rdi
leaq 0x613d(%rip), %rsi      # 0x1c259
callq 0x3160
cmpl $0x0, %eax
jne 0x16148
movq -0x8(%rbp), %rax
movq 0x20(%rax), %rax
leaq 0xbb6b(%rip), %rcx      # 0x21ca0
cmpq %rcx, 0x20(%rax)
jne 0x16148
xorl %eax, %eax
movl %eax, %edi
callq 0x12cc0
movq %rax, -0x38(%rbp)
movq -0x8(%rbp), %rdi
movq -0x38(%rbp), %rsi
callq 0x13ee0
testb $0x1, -0x9(%rbp)
je 0x16167
leaq 0x60fc(%rip), %rdi      # 0x1c25e
callq 0x3060
movq 0xae62(%rip), %rax      # 0x20fd0
movq (%rax), %rsi
leaq 0x60ed(%rip), %rdi      # 0x1c265
callq 0x3100
movq -0x8(%rbp), %rax
movq 0x20(%rax), %rax
leaq 0xb8ac(%rip), %rcx      # 0x21a38
cmpq %rcx, 0x20(%rax)
je 0x161db
movq -0x8(%rbp), %rax
movq 0x20(%rax), %rax
movq 0x20(%rax), %rdi
callq 0x158f0
movl %edx, -0x50(%rbp)
movq %rax, -0x58(%rbp)
movq -0x58(%rbp), %rax
movq %rax, -0x44(%rbp)
movl -0x50(%rbp), %eax
movl %eax, -0x3c(%rbp)
movsbl -0x44(%rbp), %edi
movq -0x8(%rbp), %rax
movq 0x20(%rax), %rax
movq 0x20(%rax), %rax
movq 0x18(%rax), %rsi
callq 0x16450
movl $0x20, %edi
callq 0x3030
movq -0x8(%rbp), %rax
movq (%rax), %rax
movq 0x20(%rax), %rdi
callq 0x164a0
movl $0x28, %edi
callq 0x3030
movq -0x8(%rbp), %rax
movq 0x20(%rax), %rax
movq 0x48(%rax), %rax
movq %rax, -0x30(%rbp)
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rax
movq %rax, -0x38(%rbp)
cmpq $0x0, -0x30(%rbp)
je 0x162ab
movq -0x30(%rbp), %rax
movq -0x8(%rbp), %rcx
movq 0x20(%rcx), %rcx
cmpq 0x48(%rcx), %rax
je 0x16244
movq 0xad9b(%rip), %rax      # 0x20fd0
movq (%rax), %rsi
leaq 0x60cf(%rip), %rdi      # 0x1c30e
callq 0x3100
movq -0x30(%rbp), %rax
movq 0x10(%rax), %rdi
callq 0x158f0
movl %edx, -0x70(%rbp)
movq %rax, -0x78(%rbp)
movq -0x78(%rbp), %rax
movq %rax, -0x64(%rbp)
movl -0x70(%rbp), %eax
movl %eax, -0x5c(%rbp)
movsbl -0x64(%rbp), %edi
movq -0x30(%rbp), %rax
movq 0x10(%rax), %rax
movq 0x18(%rax), %rsi
callq 0x16450
movl $0x20, %edi
callq 0x3030
movq -0x38(%rbp), %rdi
callq 0x164a0
movq -0x30(%rbp), %rax
movq 0x38(%rax), %rax
movq %rax, -0x30(%rbp)
movq -0x38(%rbp), %rax
addq $0x10, %rax
movq %rax, -0x38(%rbp)
jmp 0x16211
movq -0x8(%rbp), %rax
movq 0x20(%rax), %rax
testb $0x1, 0x40(%rax)
je 0x162f4
movq -0x8(%rbp), %rax
movq 0x20(%rax), %rax
cmpq $0x0, 0x48(%rax)
je 0x162de
movq 0xad01(%rip), %rax      # 0x20fd0
movq (%rax), %rsi
leaq 0x6035(%rip), %rdi      # 0x1c30e
callq 0x3100
movq 0xaceb(%rip), %rax      # 0x20fd0
movq (%rax), %rsi
leaq 0x6539(%rip), %rdi      # 0x1c828
callq 0x3100
leaq 0x5f74(%rip), %rdi      # 0x1c26f
callq 0x3060
movq -0x8(%rbp), %rax
movq 0x28(%rax), %rax
movq %rax, -0x18(%rbp)
cmpq $0x0, -0x18(%rbp)
je 0x1642e
movq -0x18(%rbp), %rdi
callq 0x164a0
movl $0xa, %edi
callq 0x3030
movq -0x18(%rbp), %rax
cmpl $0x0, 0x50(%rax)
je 0x163d0
movl $0x9, %edi
callq 0x3030
movq -0x18(%rbp), %rdi
addq $0x28, %rdi
addq $0x28, %rdi
callq 0x16570
movq -0x18(%rbp), %rax
movl 0x28(%rax), %esi
leaq 0x5f12(%rip), %rdi      # 0x1c273
movb $0x0, %al
callq 0x30c0
movq -0x18(%rbp), %rax
movq 0x30(%rax), %rdi
callq 0x164a0
movl $0x20, %edi
callq 0x3030
movq -0x18(%rbp), %rax
movq 0x40(%rax), %rdi
callq 0x16570
movq 0xac3d(%rip), %rax      # 0x20fd0
movq (%rax), %rsi
leaq 0x5f71(%rip), %rdi      # 0x1c30e
callq 0x3100
movq -0x18(%rbp), %rax
movq 0x38(%rax), %rdi
callq 0x164a0
movl $0x20, %edi
callq 0x3030
movq -0x18(%rbp), %rax
movq 0x48(%rax), %rdi
callq 0x16570
movl $0xa, %edi
callq 0x3030
movq -0x18(%rbp), %rax
movq 0x10(%rax), %rax
movq -0x18(%rbp), %rcx
addq 0x18(%rcx), %rax
movq %rax, -0x28(%rbp)
movq -0x18(%rbp), %rax
movq 0x10(%rax), %rax
movq %rax, -0x20(%rbp)
movq -0x20(%rbp), %rax
cmpq -0x28(%rbp), %rax
je 0x1640d
movq -0x20(%rbp), %rdi
movq -0x28(%rbp), %rsi
callq 0x16630
movq %rax, -0x20(%rbp)
jmp 0x163f0
movq -0x18(%rbp), %rdi
addq $0x60, %rdi
callq 0x16830
movq -0x18(%rbp), %rax
movq 0x80(%rax), %rax
movq %rax, -0x18(%rbp)
jmp 0x1630c
leaq 0x55a1(%rip), %rdi      # 0x1b9d6
callq 0x3060
addq $0x80, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)