// File: /workspace/github_c_makefile_star2_O1/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 0x162d43
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 0x8606(%rip), %rax      # 0x16b350
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 0x162ed2
xorl %r12d, %r12d
leaq 0x3c0e(%rip), %r13      # 0x1669a0
xorl %ebp, %ebp
cmpl $0x3, %ebp
ja 0x162e14
movl %ebp, %eax
movslq (%r13,%rax,4), %rax
addq %r13, %rax
jmpq *%rax
movl (%rsp), %ecx
cmpq $0x28, %rcx
ja 0x162e69
movq %rcx, %rax
addq 0x10(%rsp), %rax
addl $0x8, %ecx
movl %ecx, (%rsp)
jmp 0x162e77
movl (%rsp), %ecx
cmpq $0x28, %rcx
ja 0x162e31
movq %rcx, %rax
addq 0x10(%rsp), %rax
addl $0x8, %ecx
movl %ecx, (%rsp)
jmp 0x162e3f
movl (%rsp), %ecx
cmpq $0x28, %rcx
ja 0x162e4d
movq %rcx, %rax
addq 0x10(%rsp), %rax
addl $0x8, %ecx
movl %ecx, (%rsp)
jmp 0x162e5b
movl (%rsp), %ecx
cmpq $0x28, %rcx
ja 0x162e85
movq %rcx, %rax
addq 0x10(%rsp), %rax
addl $0x8, %ecx
movl %ecx, (%rsp)
jmp 0x162e93
movl (%rsp), %ecx
cmpq $0x28, %rcx
ja 0x162ea1
movq %rcx, %rax
addq 0x10(%rsp), %rax
addl $0x8, %ecx
movl %ecx, (%rsp)
jmp 0x162eaf
movq 0x8(%rsp), %rax
leaq 0x8(%rax), %rcx
movq %rcx, 0x8(%rsp)
movl (%rax), %eax
movq 0x8508(%rip), %rcx      # 0x16b350
movl %eax, 0x18(%rcx)
jmp 0x162ec3
movq 0x8(%rsp), %rax
leaq 0x8(%rax), %rcx
movq %rcx, 0x8(%rsp)
movl (%rax), %eax
movq 0x84ec(%rip), %rcx      # 0x16b350
movl %eax, 0x1c(%rcx)
jmp 0x162ec3
movq 0x8(%rsp), %rax
leaq 0x8(%rax), %rcx
movq %rcx, 0x8(%rsp)
movl (%rax), %eax
movq 0x84d0(%rip), %rcx      # 0x16b350
movl %eax, 0x10(%rcx)
jmp 0x162ec3
movq 0x8(%rsp), %rax
leaq 0x8(%rax), %rcx
movq %rcx, 0x8(%rsp)
movl (%rax), %eax
movq 0x84b4(%rip), %rcx      # 0x16b350
movl %eax, 0x14(%rcx)
jmp 0x162ec3
movq 0x8(%rsp), %rax
leaq 0x8(%rax), %rcx
movq %rcx, 0x8(%rsp)
movq 0x849a(%rip), %rcx      # 0x16b350
movl 0x74(%rcx), %edi
addl %r12d, %edi
movl (%rax), %esi
callq 0x162869
incl %ebp
addl $0x4, %r12d
cmpl %ebp, %r14d
jne 0x162d94
movq 0x8477(%rip), %rax      # 0x16b350
movl $0xdeadbeef, %ecx       # imm = 0xDEADBEEF
movl %ecx, 0x7c(%rax)
cmpl %ecx, %ebx
je 0x162f1d
leaq 0x8474(%rip), %r12      # 0x16b360
leaq 0x3c6d(%rip), %r14      # 0x166b60
testb $0x3, %bl
je 0x162f07
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 0x162ef3
movq 0x842c(%rip), %rax      # 0x16b350
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