// File: Silica[P]PSL/PSLc.cpp
// Function: compile(_IO_FILE*, char const*)
void compile(FILE *exe, const char *filename)
{
	PSLVM p;
	if (p.loadScript(filename))
		return;

	string exename = filename;
	int period = exename.rfind('.');
	if (period > 0)
		exename /= period;
	exename += EXT;
	FILE *fp = fopen(exename, "wb");
	if (!fp)
		return;
	fseek(exe, 0, SEEK_END);
	int end = ftell(exe);
	variable::buffer byte(end);
	fseek(exe, 0, SEEK_SET);
	fread(byte.get(), 1, end, exe);
	fwrite(byte.get(), 1, end, fp);
	p.writeCompiledCode(fp);
	dword l = 0xDEADC0DE;
	fwrite(&end, 1, sizeof(dword), fp);
	fwrite(&l, 1, sizeof(dword), fp);

	fclose(fp);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xc0, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
leaq -0x38(%rbp), %rdi
callq 0xc930
movq -0x10(%rbp), %rsi
leaq -0x40(%rbp), %rdi
callq 0xca20
jmp 0xc3fb
leaq -0x38(%rbp), %rdi
leaq -0x40(%rbp), %rsi
callq 0xc970
movl %eax, -0x94(%rbp)
jmp 0xc410
leaq -0x40(%rbp), %rdi
callq 0xcac0
movl -0x94(%rbp), %eax
cmpl $0x0, %eax
je 0xc45b
movl $0x1, -0x50(%rbp)
jmp 0xc63c
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
jmp 0xc66f
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
leaq -0x40(%rbp), %rdi
callq 0xcac0
jmp 0xc66f
movq -0x10(%rbp), %rsi
leaq -0x58(%rbp), %rdi
callq 0xca20
jmp 0xc46a
leaq -0x58(%rbp), %rdi
movl $0x2e, %esi
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
callq 0xcaf0
movl %eax, -0x98(%rbp)
jmp 0xc485
movl -0x98(%rbp), %eax
movl %eax, -0x5c(%rbp)
cmpl $0x0, -0x5c(%rbp)
jle 0xc4b6
movslq -0x5c(%rbp), %rsi
leaq -0x58(%rbp), %rdi
callq 0xcba0
jmp 0xc4a3
jmp 0xc4b6
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
jmp 0xc666
leaq 0x321f3(%rip), %rsi     # 0x3e6b0
leaq -0x58(%rbp), %rdi
callq 0xcc10
jmp 0xc4c8
leaq -0x58(%rbp), %rdi
callq 0xcd00
movq %rax, -0xa0(%rbp)
jmp 0xc4da
movq -0xa0(%rbp), %rdi
leaq 0x321cd(%rip), %rsi     # 0x3e6b5
callq 0xc200
movq %rax, -0xa8(%rbp)
jmp 0xc4f6
movq -0xa8(%rbp), %rax
movq %rax, -0x68(%rbp)
cmpq $0x0, -0x68(%rbp)
jne 0xc514
movl $0x1, -0x50(%rbp)
jmp 0xc633
movq -0x8(%rbp), %rdi
xorl %eax, %eax
movl %eax, %esi
movl $0x2, %edx
callq 0xc1f0
jmp 0xc528
movq -0x8(%rbp), %rdi
callq 0xc030
movq %rax, -0xb0(%rbp)
jmp 0xc53a
movq -0xb0(%rbp), %rax
movl %eax, -0x6c(%rbp)
movslq -0x6c(%rbp), %rsi
leaq -0x88(%rbp), %rdi
callq 0xcd20
jmp 0xc556
movq -0x8(%rbp), %rdi
xorl %edx, %edx
movl %edx, %esi
callq 0xc1f0
jmp 0xc565
leaq -0x88(%rbp), %rdi
callq 0xcd80
movq %rax, -0xb8(%rbp)
jmp 0xc57a
movq -0xb8(%rbp), %rdi
movslq -0x6c(%rbp), %rdx
movq -0x8(%rbp), %rcx
movl $0x1, %esi
callq 0xc230
jmp 0xc595
leaq -0x88(%rbp), %rdi
callq 0xcd80
movq %rax, -0xc0(%rbp)
jmp 0xc5aa
movq -0xc0(%rbp), %rdi
movslq -0x6c(%rbp), %rdx
movq -0x68(%rbp), %rcx
movl $0x1, %esi
callq 0xc2b0
jmp 0xc5c5
movq -0x68(%rbp), %rsi
leaq -0x38(%rbp), %rdi
callq 0xcda0
jmp 0xc5d4
movl $0xdeadc0de, %eax       # imm = 0xDEADC0DE
movq %rax, -0x90(%rbp)
movq -0x68(%rbp), %rcx
leaq -0x6c(%rbp), %rdi
movl $0x1, %esi
movl $0x8, %edx
callq 0xc2b0
jmp 0xc5f9
movq -0x68(%rbp), %rcx
leaq -0x90(%rbp), %rdi
movl $0x1, %esi
movl $0x8, %edx
callq 0xc2b0
jmp 0xc615
movq -0x68(%rbp), %rdi
callq 0xc1c0
jmp 0xc620
leaq -0x88(%rbp), %rdi
callq 0xcea0
movl $0x0, -0x50(%rbp)
leaq -0x58(%rbp), %rdi
callq 0xcac0
leaq -0x38(%rbp), %rdi
callq 0xcec0
addq $0xc0, %rsp
popq %rbp
retq
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
leaq -0x88(%rbp), %rdi
callq 0xcea0
leaq -0x58(%rbp), %rdi
callq 0xcac0
leaq -0x38(%rbp), %rdi
callq 0xcec0
movq -0x48(%rbp), %rdi
callq 0xc280
nopw %cs:(%rax,%rax)