// File: /workspace/github_c_makefile_star2_O3/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 0x7a9c
cmpl $0x4, %eax
jne 0x38f9
movq %rbp, %rdi
callq 0x7ab4
movq %rbp, %rdi
callq 0x7ab4
cmpl $0x5, %eax
je 0x392c
movups 0x5e9e(%rip), %xmm0     # 0x97ab
leaq 0x9bcc(%rip), %rax      # 0xd4e0
movups %xmm0, 0xd(%rax)
movups 0x5e7f(%rip), %xmm0     # 0x979e
movaps %xmm0, (%rax)
movl $0x1, %edi
callq 0x5b10
movl 0x993d(%rip), %r13d     # 0xd270
leal 0x1(%r13), %eax
movl %eax, 0x9933(%rip)      # 0xd270
leaq 0x78(%rsp), %rdi
movq %rbx, %rsi
callq 0x15d8
xorl %eax, %eax
cmpl $0x0, (%r14)
jne 0x3970
movzbl 0x4(%r14), %edi
movl 0x88(%rsp), %eax
movl %eax, 0x10(%rsp)
movups 0x78(%rsp), %xmm0
movups %xmm0, (%rsp)
callq 0x1683
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 0x5e18(%rip), %rsi      # 0x97bb
movq %rbx, %rdi
movl %r13d, %edx
xorl %eax, %eax
callq 0x171c
movq %r14, 0x68(%rsp)
movq %r14, %rdi
movl %r15d, 0x54(%rsp)
movl %r15d, %esi
callq 0x15ba
leaq 0x5c09(%rip), %rsi      # 0x95d5
movq %rbx, %rdi
movl %eax, %edx
xorl %eax, %eax
callq 0x171c
movq %rbp, %rdi
callq 0x7a9c
cmpl $0x6, %eax
jne 0x3a2d
movq %r12, %rdi
callq 0x79e2
movq (%r12), %rax
cmpb $0x29, (%rax)
je 0x3a26
leaq 0x9ae3(%rip), %rax      # 0xd4e0
movabsq $0x27292720646574, %rcx # imm = 0x27292720646574
movq %rcx, 0x5(%rax)
movabsq $0x6465746365707845, %rcx # imm = 0x6465746365707845
movq %rcx, (%rax)
movl $0x1, %edi
callq 0x5b10
movq (%r12), %rax
incq %rax
movq %rax, (%r12)
movq %r13, 0x58(%rsp)
movq %rbp, %rdi
callq 0x7a9c
movl %eax, 0x48(%rsp)
cmpl $0x6, %eax
je 0x3b78
leaq 0x128(%rsp), %r15
leaq 0xd0(%rsp), %r13
leaq 0x9a82(%rip), %r14      # 0xd4e0
movq %r15, %rdi
movq %rbp, %rsi
callq 0x7bdc
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 0x3d22
movq (%r12), %rax
cmpb $0x2c, (%rax)
jne 0x3ae3
movq %rbp, %rdi
callq 0x7a9c
cmpl $0x6, %eax
jne 0x3b20
movabsq $0x27292720646574, %rax # imm = 0x27292720646574
jmp 0x3b05
movq %rbp, %rdi
callq 0x7a9c
cmpl $0x6, %eax
jne 0x3afb
movq (%r12), %rax
cmpb $0x29, (%rax)
jne 0x3aca
jmp 0x3b20
movabsq $0x272c2720646574, %rax # imm = 0x272C2720646574
movq %rax, 0x5(%r14)
movabsq $0x6465746365707845, %rax # imm = 0x6465746365707845
movq %rax, (%r14)
movl $0x1, %edi
callq 0x5b10
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 0x340d
movq %rbp, %rdi
callq 0x7a9c
cmpl $0x6, %eax
jne 0x3a5e
movq %rbp, %rdi
callq 0x7ab4
movq 0x70(%rsp), %r14
movl (%r14), %eax
cmpl $0x1, %eax
je 0x3bca
testl %eax, %eax
movq 0x60(%rsp), %r15
movl 0x4c(%rsp), %ebp
movq 0x58(%rsp), %r12
movl 0x48(%rsp), %r13d
jne 0x3c3a
leaq 0x5ab7(%rip), %rsi      # 0x9666
movq %rbx, %rdi
movl 0x50(%rsp), %edx
xorl %eax, %eax
callq 0x171c
cmpl $0x6, %r13d
jne 0x3c02
movq %r15, %rdi
movl %ebp, %esi
jmp 0x3c11
movq (%r14), %rdi
movl 0x8(%r14), %esi
callq 0x15ba
leaq 0x5a89(%rip), %rsi      # 0x9666
movq %rbx, %rdi
movl %eax, %edx
xorl %eax, %eax
callq 0x171c
movl 0x48(%rsp), %r13d
cmpl $0x6, %r13d
movq 0x60(%rsp), %r15
movl 0x4c(%rsp), %ebp
movq 0x58(%rsp), %r12
je 0x3bc3
movq 0xd0(%rsp), %rdi
movl 0xd8(%rsp), %esi
callq 0x15ba
leaq 0x5bc7(%rip), %rsi      # 0x97e4
movq %rbx, %rdi
movl %eax, %edx
xorl %eax, %eax
callq 0x171c
leaq 0x5bc7(%rip), %rsi      # 0x97f7
movq %rbx, %rdi
xorl %eax, %eax
callq 0x171c
leaq 0x6151(%rip), %rsi      # 0x9d92
movq %rbx, %rdi
movl %r12d, %edx
xorl %eax, %eax
callq 0x171c
cmpl $0x6, %r13d
jne 0x3c5b
movq %r15, %rdi
movl %ebp, %esi
jmp 0x3c6a
movq 0xd0(%rsp), %rdi
movl 0xd8(%rsp), %esi
callq 0x15ba
negl %eax
leaq 0x5b6c(%rip), %rsi      # 0x97e4
movq %rbx, %rdi
movl %eax, %edx
xorl %eax, %eax
callq 0x171c
movq %r15, %rdi
movl %ebp, %esi
callq 0x15ba
leaq 0x59d1(%rip), %rsi      # 0x9666
movq %rbx, %rdi
movl %eax, %edx
xorl %eax, %eax
callq 0x171c
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 0x169a
movl (%r14), %eax
cmpl $0x1, %eax
je 0x3cf1
testl %eax, %eax
jne 0x3d10
movl 0x4(%r14), %edx
leaq 0x5b14(%rip), %rsi      # 0x9800
movq %rbx, %rdi
jmp 0x3d09
movq (%r14), %rdi
movl 0x8(%r14), %esi
callq 0x15ba
leaq 0x58d1(%rip), %rsi      # 0x95d5
movq %rbx, %rdi
movl %eax, %edx
xorl %eax, %eax
callq 0x171c
addq $0x168, %rsp            # imm = 0x168
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq