// File: /workspace/github_c_makefile_star2_O1/been-jamming[P]MinimalCC/expression.c
// Function: compile_function_call
void compile_function_call(char **c, value *func, FILE *output_file){
	reg_list reg_state;
	data_entry return_data;
	data_entry return_address_data;
	type current_argument_type;
	value current_argument_value;
	unsigned int label_num;
	int func_stack_pos = 0;
	int any_args = 0;

	if(peek_type(&(func->data_type)) == type_pointer){
		pop_type(&(func->data_type));
	}
	if(pop_type(&(func->data_type)) != type_function){
		snprintf(error_message, sizeof(error_message), "Can't call non-function type");
		do_error(1);
	}

	label_num = num_labels;
	num_labels++;
	reg_state = push_registers(output_file);

	if(func->data.type == data_register){
		func_stack_pos = get_reg_stack_pos(reg_state, func->data.reg);
	}
	return_address_data = allocate(1);
	return_data = allocate(1);
	fileprint(output_file, "la $t0, __L%d\n", label_num);
	fileprint(output_file, "sw $t0, %d($sp)\n", get_stack_pos(return_address_data));
	if(peek_type(&(func->data_type)) == type_returns){
		skip_whitespace(c);
		if(**c != ')'){
			snprintf(error_message, sizeof(error_message), "Expected ')'");
			do_error(1);
		}
		++*c;
	}
	while(peek_type(&(func->data_type)) != type_returns){
		any_args = 1;
		current_argument_type = get_argument_type(&(func->data_type));
		compile_expression(&current_argument_value, c, 1, 1, output_file);
		if(**c != ',' && peek_type(&(func->data_type)) != type_returns){
			snprintf(error_message, sizeof(error_message), "Expected ','");
			do_error(1);
		} else if(**c != ')' && peek_type(&(func->data_type)) == type_returns){
			snprintf(error_message, sizeof(error_message), "Expected ')'");
			do_error(1);
		}
		++*c;
		cast(&current_argument_value, current_argument_type, 1, output_file);
	}

	pop_type(&(func->data_type));
	if(func->data.type == data_register){
		fileprint(output_file, "lw $t0, %d($sp)\n", func_stack_pos);
		if(any_args)
			fileprint(output_file, "addi $sp, $sp, %d\n", get_stack_pos(current_argument_value.data));
		else
			fileprint(output_file, "addi $sp, $sp, %d\n", get_stack_pos(return_data));
		fileprint(output_file, "jr $t0\n\n");
	} else if(func->data.type == data_stack){
		fileprint(output_file, "lw $t0, %d($sp)\n", get_stack_pos(func->data));
		if(any_args)
			fileprint(output_file, "addi $sp, $sp, %d\n", get_stack_pos(current_argument_value.data));
		else
			fileprint(output_file, "addi $sp, $sp, %d\n", get_stack_pos(return_data));
		fileprint(output_file, "jr $t0\n\n");
	}
	fileprint(output_file, "__L%d:\n", label_num);
	if(any_args)
		fileprint(output_file, "addi $sp, $sp, %d\n", -get_stack_pos(current_argument_value.data));
	else
		fileprint(output_file, "addi $sp, $sp, %d\n", -get_stack_pos(return_data));
	fileprint(output_file, "lw $t0, %d($sp)\n", get_stack_pos(return_data));
	deallocate(return_data);
	deallocate(return_address_data);
	pull_registers(reg_state, output_file);
	if(func->data.type == data_register){
		fileprint(output_file, "move $s%d, $t0\n", func->data.reg);
	} else if(func->data.type == data_stack){
		fileprint(output_file, "sw $t0, %d($sp)\n", get_stack_pos(func->data));
	}
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x168, %rsp            # imm = 0x168
movq %rdx, %rbx
movq %rsi, %r14
movq %rdi, %r12
leaq 0x10(%rsi), %rbp
movq %rbp, %rdi
callq 0x7a61
cmpl $0x4, %eax
jne 0x38e8
movq %rbp, %rdi
callq 0x7a79
movq %rbp, %rdi
callq 0x7a79
cmpl $0x5, %eax
je 0x391b
movups 0x5eaf(%rip), %xmm0     # 0x97ab
leaq 0x9bdd(%rip), %rax      # 0xd4e0
movups %xmm0, 0xd(%rax)
movups 0x5e90(%rip), %xmm0     # 0x979e
movaps %xmm0, (%rax)
movl $0x1, %edi
callq 0x5ae0
movl 0x994e(%rip), %r13d     # 0xd270
leal 0x1(%r13), %eax
movl %eax, 0x9944(%rip)      # 0xd270
leaq 0x78(%rsp), %rdi
movq %rbx, %rsi
callq 0x15d8
xorl %eax, %eax
cmpl $0x0, (%r14)
jne 0x395f
movzbl 0x4(%r14), %edi
movl 0x88(%rsp), %eax
movl %eax, 0x10(%rsp)
movups 0x78(%rsp), %xmm0
movups %xmm0, (%rsp)
callq 0x167d
movl %eax, 0x50(%rsp)
movq %r14, 0x70(%rsp)
movl $0x1, %edi
callq 0x1505
movq %rax, %r14
movl %edx, %r15d
movl $0x1, %edi
callq 0x1505
movq %rax, 0x60(%rsp)
movl %edx, 0x4c(%rsp)
leaq 0x5e29(%rip), %rsi      # 0x97bb
movq %rbx, %rdi
movl %r13d, %edx
xorl %eax, %eax
callq 0x1710
movq %r14, 0x68(%rsp)
movq %r14, %rdi
movl %r15d, 0x54(%rsp)
movl %r15d, %esi
callq 0x15ba
leaq 0x5c1a(%rip), %rsi      # 0x95d5
movq %rbx, %rdi
movl %eax, %edx
xorl %eax, %eax
callq 0x1710
movq %rbp, %rdi
callq 0x7a61
cmpl $0x6, %eax
jne 0x3a15
movq %r12, %rdi
callq 0x799f
movq (%r12), %rax
cmpb $0x29, (%rax)
je 0x3a11
leaq 0x9af4(%rip), %rax      # 0xd4e0
movabsq $0x27292720646574, %rcx # imm = 0x27292720646574
movq %rcx, 0x5(%rax)
movabsq $0x6465746365707845, %rcx # imm = 0x6465746365707845
movq %rcx, (%rax)
movl $0x1, %edi
callq 0x5ae0
incq (%r12)
movq %r13, 0x58(%rsp)
movq %rbp, %rdi
callq 0x7a61
movl %eax, 0x48(%rsp)
cmpl $0x6, %eax
je 0x3b5e
leaq 0x128(%rsp), %r15
leaq 0xd0(%rsp), %r13
leaq 0x9a9a(%rip), %r14      # 0xd4e0
movq %r15, %rdi
movq %rbp, %rsi
callq 0x7bd9
movups 0x128(%rsp), %xmm0
movups 0x138(%rsp), %xmm1
movups 0x148(%rsp), %xmm2
movups 0x158(%rsp), %xmm3
movaps %xmm3, 0xc0(%rsp)
movaps %xmm2, 0xb0(%rsp)
movaps %xmm1, 0xa0(%rsp)
movaps %xmm0, 0x90(%rsp)
movq %r13, %rdi
movq %r12, %rsi
movl $0x1, %edx
movl $0x1, %ecx
movq %rbx, %r8
callq 0x3d08
movq (%r12), %rax
cmpb $0x2c, (%rax)
je 0x3abf
movq %rbp, %rdi
callq 0x7a61
cmpl $0x6, %eax
jne 0x3ae1
movq (%r12), %rax
cmpb $0x29, (%rax)
je 0x3b06
movq %rbp, %rdi
callq 0x7a61
cmpl $0x6, %eax
jne 0x3b06
movabsq $0x27292720646574, %rax # imm = 0x27292720646574
jmp 0x3aeb
movabsq $0x272c2720646574, %rax # imm = 0x272C2720646574
movq %rax, 0x5(%r14)
movabsq $0x6465746365707845, %rax # imm = 0x6465746365707845
movq %rax, (%r14)
movl $0x1, %edi
callq 0x5ae0
incq (%r12)
movaps 0x90(%rsp), %xmm0
movaps 0xa0(%rsp), %xmm1
movaps 0xb0(%rsp), %xmm2
movaps 0xc0(%rsp), %xmm3
movups %xmm3, 0x30(%rsp)
movups %xmm2, 0x20(%rsp)
movups %xmm1, 0x10(%rsp)
movups %xmm0, (%rsp)
movq %r13, %rdi
movl $0x1, %esi
movq %rbx, %rdx
callq 0x33e8
movq %rbp, %rdi
callq 0x7a61
cmpl $0x6, %eax
jne 0x3a46
movq %rbp, %rdi
callq 0x7a79
movq 0x70(%rsp), %r14
movl (%r14), %eax
cmpl $0x1, %eax
je 0x3bb0
testl %eax, %eax
movq 0x60(%rsp), %r15
movl 0x4c(%rsp), %ebp
movq 0x58(%rsp), %r12
movl 0x48(%rsp), %r13d
jne 0x3c20
leaq 0x5ad1(%rip), %rsi      # 0x9666
movq %rbx, %rdi
movl 0x50(%rsp), %edx
xorl %eax, %eax
callq 0x1710
cmpl $0x6, %r13d
jne 0x3be8
movq %r15, %rdi
movl %ebp, %esi
jmp 0x3bf7
movq (%r14), %rdi
movl 0x8(%r14), %esi
callq 0x15ba
leaq 0x5aa3(%rip), %rsi      # 0x9666
movq %rbx, %rdi
movl %eax, %edx
xorl %eax, %eax
callq 0x1710
movl 0x48(%rsp), %r13d
cmpl $0x6, %r13d
movq 0x60(%rsp), %r15
movl 0x4c(%rsp), %ebp
movq 0x58(%rsp), %r12
je 0x3ba9
movq 0xd0(%rsp), %rdi
movl 0xd8(%rsp), %esi
callq 0x15ba
leaq 0x5be1(%rip), %rsi      # 0x97e4
movq %rbx, %rdi
movl %eax, %edx
xorl %eax, %eax
callq 0x1710
leaq 0x5be1(%rip), %rsi      # 0x97f7
movq %rbx, %rdi
xorl %eax, %eax
callq 0x1710
leaq 0x6177(%rip), %rsi      # 0x9d9e
movq %rbx, %rdi
movl %r12d, %edx
xorl %eax, %eax
callq 0x1710
cmpl $0x6, %r13d
jne 0x3c41
movq %r15, %rdi
movl %ebp, %esi
jmp 0x3c50
movq 0xd0(%rsp), %rdi
movl 0xd8(%rsp), %esi
callq 0x15ba
negl %eax
leaq 0x5b86(%rip), %rsi      # 0x97e4
movq %rbx, %rdi
movl %eax, %edx
xorl %eax, %eax
callq 0x1710
movq %r15, %rdi
movl %ebp, %esi
callq 0x15ba
leaq 0x59eb(%rip), %rsi      # 0x9666
movq %rbx, %rdi
movl %eax, %edx
xorl %eax, %eax
callq 0x1710
movq %r15, %rdi
movl %ebp, %esi
callq 0x156a
movq 0x68(%rsp), %rdi
movl 0x54(%rsp), %esi
callq 0x156a
movl 0x88(%rsp), %eax
movl %eax, 0x10(%rsp)
movups 0x78(%rsp), %xmm0
movups %xmm0, (%rsp)
movq %rbx, %rdi
callq 0x1694
movl (%r14), %eax
cmpl $0x1, %eax
je 0x3cd7
testl %eax, %eax
jne 0x3cf6
movl 0x4(%r14), %edx
leaq 0x5b2e(%rip), %rsi      # 0x9800
movq %rbx, %rdi
jmp 0x3cef
movq (%r14), %rdi
movl 0x8(%r14), %esi
callq 0x15ba
leaq 0x58eb(%rip), %rsi      # 0x95d5
movq %rbx, %rdi
movl %eax, %edx
xorl %eax, %eax
callq 0x1710
addq $0x168, %rsp            # imm = 0x168
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq