// File: /workspace/github_c_makefile_star2_O2/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 0x1361bb
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 0x2418e(%rip), %rax     # 0x15a350
movl 0x7c(%rax), %ecx
movl %ecx, 0x1c(%rsp)
leal (,%r14,4), %r12d
subl %r12d, 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)
xorl %ebp, %ebp
testl %r14d, %r14d
cmovlel %ebp, %r14d
leaq 0x3e7d(%rip), %r13      # 0x13a084
xorl %r15d, %r15d
cmpl %r15d, %r14d
je 0x13634e
cmpl $0x3, %r15d
ja 0x136295
movl %r15d, %eax
movslq (%r13,%rax,4), %rax
addq %r13, %rax
jmpq *%rax
movl (%rsp), %ecx
cmpq $0x28, %rcx
ja 0x1362ea
movq %rcx, %rax
addq 0x10(%rsp), %rax
addl $0x8, %ecx
movl %ecx, (%rsp)
jmp 0x1362f8
movl (%rsp), %ecx
cmpq $0x28, %rcx
ja 0x1362b2
movq %rcx, %rax
addq 0x10(%rsp), %rax
addl $0x8, %ecx
movl %ecx, (%rsp)
jmp 0x1362c0
movl (%rsp), %ecx
cmpq $0x28, %rcx
ja 0x1362ce
movq %rcx, %rax
addq 0x10(%rsp), %rax
addl $0x8, %ecx
movl %ecx, (%rsp)
jmp 0x1362dc
movl (%rsp), %ecx
cmpq $0x28, %rcx
ja 0x136306
movq %rcx, %rax
addq 0x10(%rsp), %rax
addl $0x8, %ecx
movl %ecx, (%rsp)
jmp 0x136314
movl (%rsp), %ecx
cmpq $0x28, %rcx
ja 0x136322
movq %rcx, %rax
addq 0x10(%rsp), %rax
addl $0x8, %ecx
movl %ecx, (%rsp)
jmp 0x136330
movq 0x8(%rsp), %rax
leaq 0x8(%rax), %rcx
movq %rcx, 0x8(%rsp)
movl (%rax), %eax
movq 0x24087(%rip), %rcx     # 0x15a350
movl %eax, 0x18(%rcx)
jmp 0x136343
movq 0x8(%rsp), %rax
leaq 0x8(%rax), %rcx
movq %rcx, 0x8(%rsp)
movl (%rax), %eax
movq 0x2406b(%rip), %rcx     # 0x15a350
movl %eax, 0x1c(%rcx)
jmp 0x136343
movq 0x8(%rsp), %rax
leaq 0x8(%rax), %rcx
movq %rcx, 0x8(%rsp)
movl (%rax), %eax
movq 0x2404f(%rip), %rcx     # 0x15a350
movl %eax, 0x10(%rcx)
jmp 0x136343
movq 0x8(%rsp), %rax
leaq 0x8(%rax), %rcx
movq %rcx, 0x8(%rsp)
movl (%rax), %eax
movq 0x24033(%rip), %rcx     # 0x15a350
movl %eax, 0x14(%rcx)
jmp 0x136343
movq 0x8(%rsp), %rax
leaq 0x8(%rax), %rcx
movq %rcx, 0x8(%rsp)
movq 0x24019(%rip), %rcx     # 0x15a350
movl 0x74(%rcx), %edi
addl %ebp, %edi
movl (%rax), %esi
callq 0x135d4c
incl %r15d
addl $0x4, %ebp
jmp 0x13620a
movq 0x23ffb(%rip), %rax     # 0x15a350
movl $0xdeadbeef, 0x7c(%rax) # imm = 0xDEADBEEF
leaq 0x23ffd(%rip), %r15     # 0x15a360
leaq 0x3eda(%rip), %r14      # 0x13a244
pushq $0x13
popq %rbp
cmpl $0xdeadbeef, %ebx       # imm = 0xDEADBEEF
je 0x136397
testb $0x3, %bl
je 0x136386
movl %ebp, %edi
movq %r14, %rsi
xorl %eax, %eax
callq 0x10d0
movl %ebx, %eax
andl $0x1ffffc, %eax         # imm = 0x1FFFFC
movl %ebx, %edi
callq *(%r15,%rax,2)
movl %eax, %ebx
jmp 0x13636d
movq 0x23fb2(%rip), %rax     # 0x15a350
addl %r12d, 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