// File: /workspace/github_c_makefile_star2_O3/ughman[P]c2c/src/emu.c
// Function: EMU_Invoke
uint32_t EMU_Invoke(uint32_t address,int argc,...)
{
	va_list args;
	uint32_t ra_saved = RA;
	uint32_t pc;
	SP -= argc * 4;
	va_start(args,argc);
	for (int i = 0;i < argc;i++)
	{
		if (i == 0)
			A0 = va_arg(args,uint32_t);
		else if (i == 1)
			A1 = va_arg(args,uint32_t);
		else if (i == 2)
			A2 = va_arg(args,uint32_t);
		else if (i == 3)
			A3 = va_arg(args,uint32_t);
		else
			EMU_Write32(SP + i * 4,va_arg(args,uint32_t));
	}
	va_end(args);
	RA = 0xDEADBEEF;
	pc = address;
	while (pc != 0xDEADBEEF)
	{
		if (pc & 3)
			SDL_LogError(LOG_EMU,"Program counter is unaligned");
		pc = EMU_codemap[(pc & 0x1FFFFF) >> 2](pc);
	}
	SP += argc * 4;
	RA = ra_saved;
	return V0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xd8, %rsp
movl %esi, %r14d
leaq 0x20(%rsp), %rsi
movq %rdx, 0x10(%rsi)
movq %rcx, 0x18(%rsi)
movq %r8, 0x20(%rsi)
movq %r9, 0x28(%rsi)
testb %al, %al
je 0x172f7b
movaps %xmm0, 0x50(%rsp)
movaps %xmm1, 0x60(%rsp)
movaps %xmm2, 0x70(%rsp)
movaps %xmm3, 0x80(%rsp)
movaps %xmm4, 0x90(%rsp)
movaps %xmm5, 0xa0(%rsp)
movaps %xmm6, 0xb0(%rsp)
movaps %xmm7, 0xc0(%rsp)
movq 0x83ce(%rip), %rax      # 0x17b350
movl 0x7c(%rax), %ecx
movl %ecx, 0x1c(%rsp)
leal (,%r14,4), %r15d
subl %r15d, 0x74(%rax)
movl %edi, %ebx
movq %rsi, 0x10(%rsp)
leaq 0x110(%rsp), %rax
movq %rax, 0x8(%rsp)
movabsq $0x3000000010, %rax     # imm = 0x3000000010
movq %rax, (%rsp)
testl %r14d, %r14d
jle 0x17310a
xorl %r12d, %r12d
leaq 0x437a(%rip), %r13      # 0x177344
xorl %ebp, %ebp
cmpl $0x3, %ebp
ja 0x17304c
movl %ebp, %eax
movslq (%r13,%rax,4), %rax
addq %r13, %rax
jmpq *%rax
movl (%rsp), %ecx
cmpq $0x28, %rcx
ja 0x1730a1
movq %rcx, %rax
addq 0x10(%rsp), %rax
addl $0x8, %ecx
movl %ecx, (%rsp)
jmp 0x1730af
movl (%rsp), %ecx
cmpq $0x28, %rcx
ja 0x173069
movq %rcx, %rax
addq 0x10(%rsp), %rax
addl $0x8, %ecx
movl %ecx, (%rsp)
jmp 0x173077
movl (%rsp), %ecx
cmpq $0x28, %rcx
ja 0x173085
movq %rcx, %rax
addq 0x10(%rsp), %rax
addl $0x8, %ecx
movl %ecx, (%rsp)
jmp 0x173093
movl (%rsp), %ecx
cmpq $0x28, %rcx
ja 0x1730bd
movq %rcx, %rax
addq 0x10(%rsp), %rax
addl $0x8, %ecx
movl %ecx, (%rsp)
jmp 0x1730cb
movl (%rsp), %ecx
cmpq $0x28, %rcx
ja 0x1730d9
movq %rcx, %rax
addq 0x10(%rsp), %rax
addl $0x8, %ecx
movl %ecx, (%rsp)
jmp 0x1730e7
movq 0x8(%rsp), %rax
leaq 0x8(%rax), %rcx
movq %rcx, 0x8(%rsp)
movl (%rax), %eax
movq 0x82d0(%rip), %rcx      # 0x17b350
movl %eax, 0x18(%rcx)
jmp 0x1730fb
movq 0x8(%rsp), %rax
leaq 0x8(%rax), %rcx
movq %rcx, 0x8(%rsp)
movl (%rax), %eax
movq 0x82b4(%rip), %rcx      # 0x17b350
movl %eax, 0x1c(%rcx)
jmp 0x1730fb
movq 0x8(%rsp), %rax
leaq 0x8(%rax), %rcx
movq %rcx, 0x8(%rsp)
movl (%rax), %eax
movq 0x8298(%rip), %rcx      # 0x17b350
movl %eax, 0x10(%rcx)
jmp 0x1730fb
movq 0x8(%rsp), %rax
leaq 0x8(%rax), %rcx
movq %rcx, 0x8(%rsp)
movl (%rax), %eax
movq 0x827c(%rip), %rcx      # 0x17b350
movl %eax, 0x14(%rcx)
jmp 0x1730fb
movq 0x8(%rsp), %rax
leaq 0x8(%rax), %rcx
movq %rcx, 0x8(%rsp)
movq 0x8262(%rip), %rcx      # 0x17b350
movl 0x74(%rcx), %edi
addl %r12d, %edi
movl (%rax), %esi
callq 0x172aa1
incl %ebp
addl $0x4, %r12d
cmpl %ebp, %r14d
jne 0x172fcc
movq 0x823f(%rip), %rax      # 0x17b350
movl $0xdeadbeef, %ecx       # imm = 0xDEADBEEF
movl %ecx, 0x7c(%rax)
cmpl %ecx, %ebx
je 0x17315c
leaq 0x823c(%rip), %r12      # 0x17b360
leaq 0x43d9(%rip), %r14      # 0x177504
testb $0x3, %bl
je 0x17313f
movl $0x13, %edi
movq %r14, %rsi
xorl %eax, %eax
callq 0x10d0
movl %ebx, %eax
andl $0x1ffffc, %eax         # imm = 0x1FFFFC
movl %ebx, %edi
callq *(%r12,%rax,2)
movl %eax, %ebx
cmpl $0xdeadbeef, %eax       # imm = 0xDEADBEEF
jne 0x17312b
movq 0x81f4(%rip), %rax      # 0x17b350
addl %r15d, 0x74(%rax)
movl 0x1c(%rsp), %ecx
movl %ecx, 0x7c(%rax)
movl 0x8(%rax), %eax
addq $0xd8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq