// File: /workspace/github_c_makefile_star2_O3/lucvoo[P]sparse-dev/inline.c
// Function: inline_function
int inline_function(struct expression *expr, struct symbol *sym)
{
	struct symbol_list * fn_symbol_list;
	struct symbol *fn = sym->ctype.base_type;
	struct statement *stmt;
	struct symbol_list *arg_decl;
	struct symbol *name;
	struct expression *arg;

	if (!fn->inline_stmt) {
		sparse_error(fn->pos, "marked inline, but without a definition");
		return 0;
	}
	if (fn->expanding)
		return 0;

	stmt = alloc_statement(expr->pos, STMT_COMPOUND);
	expr->type = EXPR_STATEMENT;
	expr->statement = stmt;
	expr->ctype = fn->ctype.base_type;

	fn_symbol_list = create_symbol_list(sym->inline_symbol_list);

	arg_decl = NULL;
	PREPARE_PTR_LIST(fn->arguments, name);
	FOR_EACH_PTR(expr->args, arg) {
		struct symbol *a = alloc_symbol(arg->pos, SYM_NODE);

		if (name) {
			*a = *name;
			set_replace(name, a);
			add_symbol(&fn_symbol_list, a);
			a->initializer = arg;
			add_symbol(&arg_decl, a);
		} else {
			// This may create a node of a node but it will
			// be resolved later when the corresponding
			// STMT_DECLARATION will be evaluated.
			a->ctype.base_type = arg->ctype;
		}

		NEXT_PTR_LIST(name);
	} END_FOR_EACH_PTR(arg);
	FINISH_PTR_LIST(name);

	copy_statement(fn->inline_stmt, stmt);

	if (arg_decl) {
		struct statement *decl = alloc_statement(expr->pos, STMT_DECLARATION);
		decl->declaration = arg_decl;
		stmt->args = decl;
	}
	stmt->inline_fn = sym;

	unset_replace_list(fn_symbol_list);
	free_ptr_list(&fn_symbol_list);

	return 1;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
movq 0x60(%rsi), %rbx
cmpq $0x0, 0xa0(%rbx)
je 0x10870
xorl %ebp, %ebp
testb $0x10, 0x55(%rbx)
jne 0x109fb
movq %rsi, %r15
movq %rdi, %r13
movq 0x8(%rdi), %rdi
movl $0x3, %esi
callq 0x195bf
movq %rax, %r12
movb $0x13, (%r13)
movq %rax, 0x20(%r13)
movq 0x60(%rbx), %rax
movq %rax, 0x10(%r13)
movq 0xa8(%r15), %rdi
callq 0x10a0c
movq %rax, 0x18(%rsp)
movq $0x0, (%rsp)
movq %rbx, 0x28(%rsp)
movq 0x88(%rbx), %rax
testq %rax, %rax
movq %rax, 0x40(%rsp)
movq %r15, 0x38(%rsp)
movq %r12, 0x30(%rsp)
je 0x10889
movq %rax, %r14
cmpb $0x0, (%r14)
jg 0x10893
movq 0x10(%r14), %r14
cmpq %rax, %r14
jne 0x1085c
xorl %r12d, %r12d
jmp 0x1088f
movq 0x4(%rbx), %rdi
leaq 0x2fbe9(%rip), %rsi     # 0x40464
xorl %ebp, %ebp
xorl %eax, %eax
callq 0x11a80
jmp 0x109fb
xorl %r12d, %r12d
xorl %r14d, %r14d
xorl %ebx, %ebx
jmp 0x108a1
movq 0x18(%r14), %rbx
andq $-0x4, %rbx
movl $0x1, %r12d
movq %r13, 0x20(%rsp)
movq 0x28(%r13), %rax
movq %rax, 0x8(%rsp)
testq %rax, %rax
je 0x10999
movq 0x8(%rsp), %rdx
movzwl (%rdx), %eax
testb %al, %al
jle 0x1098a
xorl %r13d, %r13d
movq %rdx, 0x10(%rsp)
movq 0x18(%rdx,%r13,8), %rbp
movzwl %ax, %eax
cmpl $0x100, %eax            # imm = 0x100
jb 0x108e8
testq %rbp, %rbp
je 0x10978
movq 0x8(%rbp), %rdi
movl $0x3, %esi
callq 0x2b00b
movq %rax, %r15
testq %rbx, %rbx
je 0x10958
movl $0xe0, %edx
movq %r15, %rdi
movq %rbx, %rsi
callq 0xe1e0
movq %rbx, 0x28(%r15)
movq %r15, 0x28(%rbx)
leaq 0x18(%rsp), %rdi
movq %r15, %rsi
callq 0x227b4
movq %rbp, 0xb0(%r15)
movq %rsp, %rdi
movq %r15, %rsi
callq 0x227b4
movq 0x10(%rsp), %rdx
movq 0x40(%rsp), %rcx
movsbl (%r14), %eax
cmpl %eax, %r12d
jl 0x10969
movq 0x10(%r14), %r14
xorl %r12d, %r12d
cmpq %rcx, %r14
jne 0x1093f
xorl %ebx, %ebx
jmp 0x10978
movq 0x10(%rbp), %rax
movq %rax, 0x60(%r15)
xorl %ebx, %ebx
movq 0x10(%rsp), %rdx
jmp 0x10978
movslq %r12d, %rax
movq 0x18(%r14,%rax,8), %rbx
andq $-0x4, %rbx
incl %r12d
incq %r13
movl (%rdx), %eax
movsbq %al, %rcx
cmpq %rcx, %r13
jl 0x108d0
movq 0x10(%rdx), %rdx
cmpq 0x8(%rsp), %rdx
jne 0x108bd
movq 0x28(%rsp), %rax
movq 0xa0(%rax), %rdi
movq 0x30(%rsp), %rbx
movq %rbx, %rsi
callq 0x10ad3
cmpq $0x0, (%rsp)
je 0x109d8
movq 0x20(%rsp), %rax
movq 0x8(%rax), %rdi
movl $0x1, %esi
callq 0x195bf
movq (%rsp), %rcx
movq %rcx, 0x10(%rax)
movq %rax, 0x28(%rbx)
movq 0x38(%rsp), %rax
movq %rax, 0x20(%rbx)
leaq 0x18(%rsp), %rbx
movq (%rbx), %rdi
callq 0x10b76
movq %rbx, %rdi
callq 0x22c4e
movl $0x1, %ebp
movl %ebp, %eax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq