// File: /workspace/github_c_makefile_star2_O1/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 0x10848
xorl %ebp, %ebp
testb $0x10, 0x55(%rbx)
jne 0x109d7
movq %rsi, %r15
movq %rdi, %r13
movq 0x8(%rdi), %rdi
movl $0x3, %esi
callq 0x19687
movq %rax, %r12
movb $0x13, (%r13)
movq %rax, 0x20(%r13)
movq 0x60(%rbx), %rax
movq %rax, 0x10(%r13)
movq 0xa8(%r15), %rdi
callq 0x109e8
movq %rax, 0x10(%rsp)
movq $0x0, (%rsp)
movq %rbx, 0x20(%rsp)
movq 0x88(%rbx), %rax
testq %rax, %rax
movq %rax, 0x38(%rsp)
movq %r15, 0x30(%rsp)
movq %r12, 0x28(%rsp)
je 0x10861
movq %rax, %r14
cmpb $0x0, (%r14)
jg 0x1086b
movq 0x10(%r14), %r14
cmpq %rax, %r14
jne 0x10834
xorl %r12d, %r12d
jmp 0x10867
movq 0x4(%rbx), %rdi
leaq 0x30c11(%rip), %rsi     # 0x41464
xorl %ebp, %ebp
xorl %eax, %eax
callq 0x11a38
jmp 0x109d7
xorl %r12d, %r12d
xorl %r14d, %r14d
xorl %ebx, %ebx
jmp 0x10879
movq 0x18(%r14), %rbx
andq $-0x4, %rbx
movl $0x1, %r12d
movq %r13, 0x18(%rsp)
movq 0x28(%r13), %rax
movq %rax, 0x8(%rsp)
testq %rax, %rax
je 0x10975
movq 0x8(%rsp), %rdx
movzwl (%rdx), %eax
testb %al, %al
jle 0x10966
xorl %r13d, %r13d
movq %rdx, 0x40(%rsp)
movq 0x18(%rdx,%r13,8), %rbp
movzwl %ax, %eax
cmpl $0x100, %eax            # imm = 0x100
jb 0x108c0
testq %rbp, %rbp
je 0x10954
movq 0x8(%rbp), %rdi
movl $0x3, %esi
callq 0x2b547
movq %rax, %r15
testq %rbx, %rbx
je 0x10912
movl $0xe0, %edx
movq %r15, %rdi
movq %rbx, %rsi
callq 0xe1e0
movq %rbx, 0x28(%r15)
movq %r15, 0x28(%rbx)
leaq 0x10(%rsp), %rdi
movq %r15, %rsi
callq 0x2285b
movq %rbp, 0xb0(%r15)
movq %rsp, %rdi
movq %r15, %rsi
callq 0x2285b
movq %rbx, %rcx
jmp 0x1091d
movq %rbx, %rcx
movq 0x10(%rbp), %rax
movq %rax, 0x60(%r15)
testq %rcx, %rcx
movq 0x40(%rsp), %rdx
je 0x10941
movq 0x38(%rsp), %rcx
movsbl (%r14), %eax
cmpl %eax, %r12d
jl 0x10945
movq 0x10(%r14), %r14
xorl %r12d, %r12d
cmpq %rcx, %r14
jne 0x1092c
xorl %ebx, %ebx
jmp 0x10954
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 0x108a8
movq 0x10(%rdx), %rdx
cmpq 0x8(%rsp), %rdx
jne 0x10895
movq 0x20(%rsp), %rax
movq 0xa0(%rax), %rdi
movq 0x28(%rsp), %rbx
movq %rbx, %rsi
callq 0x10aa6
cmpq $0x0, (%rsp)
je 0x109b4
movq 0x18(%rsp), %rax
movq 0x8(%rax), %rdi
movl $0x1, %esi
callq 0x19687
movq (%rsp), %rcx
movq %rcx, 0x10(%rax)
movq %rax, 0x28(%rbx)
movq 0x30(%rsp), %rax
movq %rax, 0x20(%rbx)
leaq 0x10(%rsp), %rbx
movq (%rbx), %rdi
callq 0x10b44
movq %rbx, %rdi
callq 0x22cf3
movl $0x1, %ebp
movl %ebp, %eax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq