// File: /workspace/github_c_makefile_star2_O2/mmcco[P]sljit/sljit_src/sljitNativeX86_64.c
// Function: sljit_emit_enter
int sljit_emit_enter(struct sljit_compiler *compiler,
	int options, int args, int scratches, int saveds,
	int fscratches, int fsaveds, int local_size)
{
	int i, tmp, size, saved_reg_size;
	u_char *inst;

	CHECK_ERROR();
	CHECK(check_sljit_emit_enter(compiler, options, args, scratches, saveds, fscratches, fsaveds, local_size));
	set_emit_enter(compiler, options, args, scratches, saveds, fscratches, fsaveds, local_size);

	compiler->flags_saved = 0;

	/* Including the return address saved by the call instruction. */
	saved_reg_size = GET_SAVED_REGS_SIZE(scratches, saveds, 1);

	tmp = saveds < SLJIT_NUM_SAVED_REGS ? (SLJIT_S0 + 1 - saveds) : SLJIT_FIRST_SAVED_REG;
	for (i = SLJIT_S0; i >= tmp; i--) {
		size = reg_map[i] >= 8 ? 2 : 1;
		inst = ensure_buf(compiler, 1 + size);
		FAIL_IF(!inst);
		INC_SIZE(size);
		if (reg_map[i] >= 8)
			*inst++ = REX_B;
		PUSH_REG(reg_lmap[i]);
	}

	for (i = scratches; i >= SLJIT_FIRST_SAVED_REG; i--) {
		size = reg_map[i] >= 8 ? 2 : 1;
		inst = ensure_buf(compiler, 1 + size);
		FAIL_IF(!inst);
		INC_SIZE(size);
		if (reg_map[i] >= 8)
			*inst++ = REX_B;
		PUSH_REG(reg_lmap[i]);
	}

	if (args > 0) {
		size = args * 3;
		inst = ensure_buf(compiler, 1 + size);
		FAIL_IF(!inst);

		INC_SIZE(size);

#ifndef _WIN64
		if (args > 0) {
			*inst++ = REX_W;
			*inst++ = MOV_r_rm;
			*inst++ = MOD_REG | (reg_map[SLJIT_S0] << 3) | 0x7 /* rdi */;
		}
		if (args > 1) {
			*inst++ = REX_W | REX_R;
			*inst++ = MOV_r_rm;
			*inst++ = MOD_REG | (reg_lmap[SLJIT_S1] << 3) | 0x6 /* rsi */;
		}
		if (args > 2) {
			*inst++ = REX_W | REX_R;
			*inst++ = MOV_r_rm;
			*inst++ = MOD_REG | (reg_lmap[SLJIT_S2] << 3) | 0x2 /* rdx */;
		}
#else
		if (args > 0) {
			*inst++ = REX_W;
			*inst++ = MOV_r_rm;
			*inst++ = MOD_REG | (reg_map[SLJIT_S0] << 3) | 0x1 /* rcx */;
		}
		if (args > 1) {
			*inst++ = REX_W;
			*inst++ = MOV_r_rm;
			*inst++ = MOD_REG | (reg_map[SLJIT_S1] << 3) | 0x2 /* rdx */;
		}
		if (args > 2) {
			*inst++ = REX_W | REX_B;
			*inst++ = MOV_r_rm;
			*inst++ = MOD_REG | (reg_map[SLJIT_S2] << 3) | 0x0 /* r8 */;
		}
#endif
	}

	local_size = ((local_size + SLJIT_LOCALS_OFFSET + saved_reg_size + 15) & ~15) - saved_reg_size;
	compiler->local_size = local_size;

#ifdef _WIN64
	if (local_size > 1024) {
		/* Allocate stack for the callback, which grows the stack. */
		inst = ensure_buf(compiler, 1 + 4 + (3 + sizeof(int)));
		FAIL_IF(!inst);
		INC_SIZE(4 + (3 + sizeof(int)));
		*inst++ = REX_W;
		*inst++ = GROUP_BINARY_83;
		*inst++ = MOD_REG | SUB | 4;
		/* Allocated size for regs must be divisible by 8. */
		SLJIT_ASSERT(!(saved_reg_size & 0x7));
		/* Aligned to 16 byte. */
		if (saved_reg_size & 0x8) {
			*inst++ = 5 * sizeof(long);
			local_size -= 5 * sizeof(long);
		} else {
			*inst++ = 4 * sizeof(long);
			local_size -= 4 * sizeof(long);
		}
		/* Second instruction */
		SLJIT_COMPILE_ASSERT(reg_map[SLJIT_R0] < 8, temporary_reg1_is_loreg);
		*inst++ = REX_W;
		*inst++ = MOV_rm_i32;
		*inst++ = MOD_REG | reg_lmap[SLJIT_R0];
		*(int*)inst = local_size;
#if (defined SLJIT_VERBOSE && SLJIT_VERBOSE) \
			|| (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
		compiler->skip_checks = 1;
#endif
		FAIL_IF(sljit_emit_ijump(compiler, SLJIT_CALL1, SLJIT_IMM, SLJIT_FUNC_OFFSET(sljit_grow_stack)));
	}
#endif

	SLJIT_ASSERT(local_size > 0);
	if (local_size <= 127) {
		inst = ensure_buf(compiler, 1 + 4);
		FAIL_IF(!inst);
		INC_SIZE(4);
		*inst++ = REX_W;
		*inst++ = GROUP_BINARY_83;
		*inst++ = MOD_REG | SUB | 4;
		*inst++ = local_size;
	}
	else {
		inst = ensure_buf(compiler, 1 + 7);
		FAIL_IF(!inst);
		INC_SIZE(7);
		*inst++ = REX_W;
		*inst++ = GROUP_BINARY_81;
		*inst++ = MOD_REG | SUB | 4;
		*(int*)inst = local_size;
		inst += sizeof(int);
	}

#ifdef _WIN64
	/* Save xmm6 reg: movaps [rsp + 0x20], xmm6 */
	if (fscratches >= 6 || fsaveds >= 1) {
		inst = ensure_buf(compiler, 1 + 5);
		FAIL_IF(!inst);
		INC_SIZE(5);
		*inst++ = GROUP_0F;
		*(int*)inst = 0x20247429;
	}
#endif

	return SLJIT_SUCCESS;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movl (%rdi), %eax
testl %eax, %eax
jne 0x1349c
movl %esi, %ebp
cmpl $0x2, %esi
jae 0x134ab
cmpl $0x4, %edx
jae 0x134b9
cmpl $0xd, %ecx
jae 0x134c7
movl %r8d, %r12d
cmpl $0xd, %r8d
jae 0x134d5
leal (%r12,%rcx), %eax
cmpl $0xd, %eax
jae 0x134e3
cmpl %r12d, %edx
ja 0x134f1
movl %r9d, %r13d
cmpl $0x7, %r9d
jae 0x134ff
movl 0x50(%rsp), %r14d
cmpl $0x7, %r14d
jae 0x1350d
leal (%r14,%r13), %eax
cmpl $0x7, %eax
jae 0x1351b
movl 0x58(%rsp), %eax
cmpl $0x10001, %eax          # imm = 0x10001
jae 0x13529
movq %rdi, %rbx
movq %rdx, 0x8(%rsp)
movq 0x78(%rdi), %rdi
testq %rdi, %rdi
movq %rcx, (%rsp)
je 0x1329d
leaq 0xe0bb(%rip), %rsi      # 0x2132c
movq 0x8(%rsp), %rdx
movq (%rsp), %rcx
movl %r12d, %r8d
movl %r13d, %r9d
xorl %eax, %eax
movl 0x58(%rsp), %r10d
pushq %r10
pushq %r14
callq 0x20c0
movq 0x10(%rsp), %rcx
movl 0x68(%rsp), %eax
addq $0x10, %rsp
movl %ebp, 0x4(%rbx)
movl %ecx, 0x48(%rbx)
movl %r12d, 0x4c(%rbx)
movl %r13d, 0x50(%rbx)
movl %r14d, 0x54(%rbx)
movl %eax, 0x80(%rbx)
andl $0x0, 0x74(%rbx)
leal 0x1ffffffa(%rcx), %eax
movq %rcx, %rdx
xorl %ecx, %ecx
cmpl $0x6, %edx
cmovbl %ecx, %eax
pushq $0xd
popq %rcx
subl %r12d, %ecx
cmpl $0x6, %r12d
pushq $0x6
popq %rdx
cmovbl %r12d, %edx
pushq $0x7
popq %r13
cmovbl %ecx, %r13d
addl %eax, %edx
leal 0x8(,%rdx,8), %eax
movq %rax, 0x10(%rsp)
pushq $0xc
popq %r12
movl $0x10ef0, %r14d         # imm = 0x10EF0
cmpq %r13, %r12
jl 0x1335d
movl $0x10ef0, %r15d         # imm = 0x10EF0
movl %r12d, %ecx
shrq %cl, %r15
btq %r12, %r14
movl $0x0, %ebp
adcl $0x1, %ebp
leal 0x1(%rbp), %esi
movq %rbx, %rdi
callq 0x1354f
testq %rax, %rax
je 0x1349a
movb %bpl, (%rax)
movl %ebp, %ecx
addq %rcx, 0x60(%rbx)
testb $0x1, %r15b
jne 0x13340
incq %rax
jmp 0x13348
movb $0x41, 0x1(%rax)
addq $0x2, %rax
leaq 0xde61(%rip), %rcx      # 0x211b0
movb (%r12,%rcx), %cl
addb $0x50, %cl
movb %cl, (%rax)
decq %r12
jmp 0x132fb
movl (%rsp), %r15d
movl $0x10ef0, %r12d         # imm = 0x10EF0
cmpl $0x7, %r15d
jl 0x133ce
movl $0x10ef0, %r14d         # imm = 0x10EF0
movl %r15d, %ecx
shrq %cl, %r14
btq %r15, %r12
movl $0x0, %r13d
adcl $0x1, %r13d
leal 0x1(%r13), %esi
movq %rbx, %rdi
callq 0x1354f
testq %rax, %rax
je 0x1349a
movb %r13b, (%rax)
movl %r13d, %ecx
addq %rcx, 0x60(%rbx)
testb $0x1, %r14b
jne 0x133b1
incq %rax
jmp 0x133b9
movb $0x41, 0x1(%rax)
addq $0x2, %rax
leaq 0xddf0(%rip), %rcx      # 0x211b0
movb (%r15,%rcx), %cl
addb $0x50, %cl
movb %cl, (%rax)
decq %r15
jmp 0x13367
movq 0x8(%rsp), %r14
testl %r14d, %r14d
je 0x13425
leal (%r14,%r14,2), %esi
incl %esi
movq %rbx, %rdi
callq 0x1354f
testq %rax, %rax
je 0x1349a
leal (%r14,%r14,2), %ecx
movb %cl, (%rax)
movl %ecx, %ecx
addq %rcx, 0x60(%rbx)
movw $0x8b48, 0x1(%rax)      # imm = 0x8B48
movb $-0x21, 0x3(%rax)
cmpl $0x1, %r14d
je 0x13425
movw $0x8b4c, 0x4(%rax)      # imm = 0x8B4C
movb $-0x2, 0x6(%rax)
cmpl $0x3, %r14d
jne 0x13425
movw $0x8b4c, 0x7(%rax)      # imm = 0x8B4C
movb $-0xe, 0x9(%rax)
movl 0x58(%rsp), %eax
movq 0x10(%rsp), %rcx
leal (%rax,%rcx), %ebp
addl $0x17, %ebp
andl $-0x10, %ebp
subl %ecx, %ebp
movl %ebp, 0x58(%rbx)
testl %ebp, %ebp
jle 0x13541
cmpl $0x7f, %ebp
ja 0x13471
pushq $0x5
popq %rsi
movq %rbx, %rdi
callq 0x1354f
testq %rax, %rax
je 0x1349a
movb $0x4, (%rax)
addq $0x4, 0x60(%rbx)
movw $0x8348, 0x1(%rax)      # imm = 0x8348
movb $-0x14, 0x3(%rax)
movb %bpl, 0x4(%rax)
jmp 0x13496
pushq $0x8
popq %rsi
movq %rbx, %rdi
callq 0x1354f
testq %rax, %rax
je 0x1349a
movb $0x7, (%rax)
addq $0x7, 0x60(%rbx)
movw $0x8148, 0x1(%rax)      # imm = 0x8148
movb $-0x14, 0x3(%rax)
movl %ebp, 0x4(%rax)
xorl %eax, %eax
jmp 0x1349c
movl (%rbx), %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0xde4d(%rip), %rdi      # 0x212ff
movl $0x38e, %esi            # imm = 0x38E
jmp 0x13535
leaq 0xde3f(%rip), %rdi      # 0x212ff
movl $0x38f, %esi            # imm = 0x38F
jmp 0x13535
leaq 0xde31(%rip), %rdi      # 0x212ff
movl $0x390, %esi            # imm = 0x390
jmp 0x13535
leaq 0xde23(%rip), %rdi      # 0x212ff
movl $0x391, %esi            # imm = 0x391
jmp 0x13535
leaq 0xde15(%rip), %rdi      # 0x212ff
movl $0x392, %esi            # imm = 0x392
jmp 0x13535
leaq 0xde07(%rip), %rdi      # 0x212ff
movl $0x393, %esi            # imm = 0x393
jmp 0x13535
leaq 0xddf9(%rip), %rdi      # 0x212ff
movl $0x394, %esi            # imm = 0x394
jmp 0x13535
leaq 0xddeb(%rip), %rdi      # 0x212ff
movl $0x395, %esi            # imm = 0x395
jmp 0x13535
leaq 0xdddd(%rip), %rdi      # 0x212ff
movl $0x396, %esi            # imm = 0x396
jmp 0x13535
leaq 0xddcf(%rip), %rdi      # 0x212ff
movl $0x397, %esi            # imm = 0x397
xorl %eax, %eax
callq 0x2080
callq 0x2040
leaq 0xdd81(%rip), %rdi      # 0x212c9
movl $0xcd, %esi
jmp 0x13535