// File: /workspace/github_c_makefile_star2_O0/lucvoo[P]sparse-dev/linearize.c
// Function: linearize_fn
static struct entrypoint *linearize_fn(struct symbol *sym, struct symbol *base_type)
{
	struct statement *stmt = base_type->stmt;
	struct entrypoint *ep;
	struct basic_block *bb;
	struct symbol *ret_type;
	struct symbol *arg;
	struct instruction *entry;
	struct instruction *ret;
	pseudo_t result;
	int i;

	if (!stmt || sym->bogus_linear)
		return NULL;

	ep = alloc_entrypoint();
	ep->name = sym;
	sym->ep = ep;
	bb = alloc_basic_block(ep, sym->pos);
	set_activeblock(ep, bb);

	if (stmt->type == STMT_ASM) {	// top-level asm
		linearize_asm_statement(ep, stmt);
		return ep;
	}

	entry = alloc_instruction(OP_ENTRY, 0);
	add_one_insn(ep, entry);
	ep->entry = entry;

	concat_symbol_list(base_type->arguments, &ep->syms);

	/* FIXME!! We should do something else about varargs.. */
	i = 0;
	FOR_EACH_PTR(base_type->arguments, arg) {
		linearize_argument(ep, arg, ++i);
	} END_FOR_EACH_PTR(arg);

	result = linearize_fn_statement(ep, stmt);
	ret_type = base_type->ctype.base_type;
	ret = alloc_typed_instruction(OP_RET, ret_type);
	if (type_size(ret_type) > 0)
		use_pseudo(ret, result, &ret->src);
	add_one_insn(ep, ret);

	optimize(ep);
	late_warnings(ep);
	return ep;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x80, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq -0x18(%rbp), %rax
movq 0x90(%rax), %rax
movq %rax, -0x20(%rbp)
cmpq $0x0, -0x20(%rbp)
je 0x1ab8b
movq -0x10(%rbp), %rax
movl 0x54(%rax), %eax
shrl $0x8, %eax
andl $0x1, %eax
cmpl $0x0, %eax
je 0x1ab98
movq $0x0, -0x8(%rbp)
jmp 0x1ad6e
callq 0x1b100
movq %rax, -0x28(%rbp)
movq -0x10(%rbp), %rcx
movq -0x28(%rbp), %rax
movq %rcx, (%rax)
movq -0x28(%rbp), %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0xc0(%rax)
movq -0x28(%rbp), %rdi
movq -0x10(%rbp), %rax
movq 0x4(%rax), %rsi
callq 0x1b110
movq %rax, -0x30(%rbp)
movq -0x28(%rbp), %rdi
movq -0x30(%rbp), %rsi
callq 0x1b170
movq -0x20(%rbp), %rax
cmpl $0xb, (%rax)
jne 0x1ac00
movq -0x28(%rbp), %rdi
movq -0x20(%rbp), %rsi
callq 0x1b1d0
movq -0x28(%rbp), %rax
movq %rax, -0x8(%rbp)
jmp 0x1ad6e
movl $0x1, %edi
xorl %esi, %esi
callq 0x1afb0
movq %rax, -0x48(%rbp)
movq -0x28(%rbp), %rdi
movq -0x48(%rbp), %rsi
callq 0x1b5b0
movq -0x48(%rbp), %rcx
movq -0x28(%rbp), %rax
movq %rcx, 0x28(%rax)
movq -0x18(%rbp), %rax
movq 0x88(%rax), %rdi
movq -0x28(%rbp), %rsi
addq $0x8, %rsi
callq 0x1b600
movl $0x0, -0x5c(%rbp)
movq -0x18(%rbp), %rax
movq 0x88(%rax), %rax
movq %rax, -0x68(%rbp)
movq -0x68(%rbp), %rax
movq %rax, -0x70(%rbp)
movq -0x68(%rbp), %rax
movq %rax, -0x78(%rbp)
cmpq $0x0, -0x68(%rbp)
jne 0x1ac73
jmp 0x1acf5
jmp 0x1ac75
movl $0x0, -0x7c(%rbp)
movl -0x7c(%rbp), %eax
movq -0x70(%rbp), %rcx
movw (%rcx), %cx
shlw $0x8, %cx
sarw $0x8, %cx
movswl %cx, %ecx
cmpl %ecx, %eax
jge 0x1ace1
movq -0x70(%rbp), %rax
movslq -0x7c(%rbp), %rcx
movq 0x18(%rax,%rcx,8), %rax
movq %rax, -0x40(%rbp)
movq -0x70(%rbp), %rax
movw (%rax), %ax
sarw $0x8, %ax
cwtl
cmpl $0x0, %eax
je 0x1acc0
cmpq $0x0, -0x40(%rbp)
jne 0x1acc0
jmp 0x1acd6
movq -0x28(%rbp), %rdi
movq -0x40(%rbp), %rsi
movl -0x5c(%rbp), %edx
addl $0x1, %edx
movl %edx, -0x5c(%rbp)
callq 0x1b630
movl -0x7c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x7c(%rbp)
jmp 0x1ac7c
jmp 0x1ace3
movq -0x70(%rbp), %rax
movq 0x10(%rax), %rax
movq %rax, -0x70(%rbp)
cmpq -0x68(%rbp), %rax
jne 0x1ac75
movq -0x28(%rbp), %rdi
movq -0x20(%rbp), %rsi
callq 0x1b6a0
movq %rax, -0x58(%rbp)
movq -0x18(%rbp), %rax
movq 0x60(%rax), %rax
movq %rax, -0x38(%rbp)
movq -0x38(%rbp), %rsi
movl $0x2, %edi
callq 0x1a240
movq %rax, -0x50(%rbp)
movq -0x38(%rbp), %rdi
callq 0x19440
cmpl $0x0, %eax
jle 0x1ad47
movq -0x50(%rbp), %rdi
movq -0x58(%rbp), %rsi
movq -0x50(%rbp), %rdx
addq $0x30, %rdx
callq 0x1a290
movq -0x28(%rbp), %rdi
movq -0x50(%rbp), %rsi
callq 0x1b5b0
movq -0x28(%rbp), %rdi
callq 0x20a60
movq -0x28(%rbp), %rdi
callq 0x1b790
movq -0x28(%rbp), %rax
movq %rax, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0x80, %rsp
popq %rbp
retq
nopl (%rax,%rax)