// File: /workspace/github_c_makefile_star2_O2/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), %r14
cmpq $0x0, 0xa0(%r14)
je 0x10114
xorl %ebx, %ebx
testb $0x10, 0x55(%r14)
jne 0x1028b
movq %rsi, %r15
movq %rdi, %rbp
movq 0x8(%rdi), %rdi
pushq $0x3
popq %rsi
callq 0x17530
movb $0x13, (%rbp)
movq %rax, 0x30(%rsp)
movq %rax, 0x20(%rbp)
movq 0x60(%r14), %rax
movq %rax, 0x10(%rbp)
movq 0xa8(%r15), %rdi
callq 0x1029c
andq $0x0, (%rsp)
movq %rax, 0x18(%rsp)
movq %r14, 0x28(%rsp)
movq 0x88(%r14), %rax
testq %rax, %rax
movq %rax, 0x40(%rsp)
movq %r15, 0x38(%rsp)
je 0x1012d
pushq $0x1
popq %r12
movq %rax, %r14
cmpb $0x0, (%r14)
jg 0x10138
movq 0x10(%r14), %r14
cmpq %rax, %r14
jne 0x10100
xorl %r12d, %r12d
jmp 0x10133
movq 0x4(%r14), %rdi
leaq 0x29345(%rip), %rsi     # 0x39464
xorl %ebx, %ebx
xorl %eax, %eax
callq 0x1120e
jmp 0x1028b
xorl %r12d, %r12d
xorl %r14d, %r14d
xorl %r13d, %r13d
jmp 0x10140
movq 0x18(%r14), %r13
andq $-0x4, %r13
movq %rbp, 0x20(%rsp)
movq 0x28(%rbp), %rax
movq %rax, 0x8(%rsp)
testq %rax, %rax
je 0x1022d
movq 0x8(%rsp), %rdx
xorl %ebp, %ebp
movq %rdx, 0x10(%rsp)
movl (%rdx), %eax
movsbq %al, %rcx
cmpq %rcx, %rbp
jge 0x1021e
movq 0x18(%rdx,%rbp,8), %r15
cmpw $0x100, %ax             # imm = 0x100
jb 0x10186
testq %r15, %r15
je 0x10216
movq 0x8(%r15), %rdi
pushq $0x3
popq %rsi
callq 0x2671f
movq %rax, %rbx
testq %r13, %r13
je 0x101f5
movl $0xe0, %edx
movq %rbx, %rdi
movq %r13, %rsi
callq 0xe1e0
movq %r13, 0x28(%rbx)
movq %rbx, 0x28(%r13)
leaq 0x18(%rsp), %rdi
movq %rbx, %rsi
callq 0x1fae9
movq %r15, 0xb0(%rbx)
movq %rsp, %rdi
movq %rbx, %rsi
callq 0x1fae9
movq 0x10(%rsp), %rdx
movq 0x40(%rsp), %rcx
movsbl (%r14), %eax
cmpl %eax, %r12d
jl 0x10207
movq 0x10(%r14), %r14
xorl %r12d, %r12d
cmpq %rcx, %r14
jne 0x101db
xorl %r13d, %r13d
jmp 0x10216
movq 0x10(%r15), %rax
movq %rax, 0x60(%rbx)
xorl %r13d, %r13d
movq 0x10(%rsp), %rdx
jmp 0x10216
movslq %r12d, %rax
movq 0x18(%r14,%rax,8), %r13
andq $-0x4, %r13
incl %r12d
incq %rbp
jmp 0x10163
movq 0x10(%rdx), %rdx
cmpq 0x8(%rsp), %rdx
jne 0x1015c
movq 0x28(%rsp), %rax
movq 0xa0(%rax), %rdi
movq 0x30(%rsp), %rbx
movq %rbx, %rsi
callq 0x1034c
cmpq $0x0, (%rsp)
je 0x1026a
movq 0x20(%rsp), %rax
movq 0x8(%rax), %rdi
pushq $0x1
popq %rsi
callq 0x17530
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 0x103df
movq %rbx, %rdi
callq 0x1ff30
pushq $0x1
popq %rbx
movl %ebx, %eax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq