// File: /workspace/github_c_makefile_star2_O3/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 $0x28, %rsp
movl (%rdi), %eax
testl %eax, %eax
jne 0x15162
movl %esi, %ebp
cmpl $0x2, %esi
jae 0x15171
movl %edx, %r15d
cmpl $0x4, %edx
jae 0x15182
cmpl $0xd, %ecx
jae 0x15190
movl %r8d, %r12d
cmpl $0xd, %r8d
jae 0x1519e
leal (%r12,%rcx), %eax
cmpl $0xd, %eax
jae 0x151ac
cmpl %r12d, %r15d
ja 0x151ba
movl %r9d, %r13d
cmpl $0x7, %r9d
jae 0x151c8
movl 0x60(%rsp), %r14d
cmpl $0x7, %r14d
jae 0x151d6
leal (%r14,%r13), %eax
cmpl $0x7, %eax
jae 0x151e4
movl 0x68(%rsp), %eax
cmpl $0x10001, %eax          # imm = 0x10001
jae 0x151f2
movq %rdi, %rbx
movq 0x78(%rdi), %rdi
testq %rdi, %rdi
movq %rcx, 0x8(%rsp)
je 0x14f3a
leaq 0xe45d(%rip), %rsi      # 0x2336c
movl %r15d, %edx
movq 0x8(%rsp), %rcx
movl %r12d, %r8d
movl %r13d, %r9d
xorl %eax, %eax
movl 0x68(%rsp), %r10d
pushq %r10
pushq %r14
callq 0x20c0
movq 0x18(%rsp), %rcx
movl 0x78(%rsp), %eax
addq $0x10, %rsp
movq %r15, 0x20(%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)
xorl %eax, %eax
movl %eax, 0x74(%rbx)
movq %rcx, %rdx
addl $0x1ffffffa, %ecx       # imm = 0x1FFFFFFA
cmpl $0x6, %edx
cmovbl %eax, %ecx
movq %rcx, 0x18(%rsp)
movl $0xd, %ecx
subl %r12d, %ecx
cmpl $0x6, %r12d
movl $0x6, %eax
cmovbl %r12d, %eax
movl %eax, 0x14(%rsp)
movl $0x7, %eax
cmovbl %ecx, %eax
cmpl $0xc, %eax
ja 0x1500d
movl %eax, %ebp
movl $0xc, %r12d
movl $0x10ef0, %r13d         # imm = 0x10EF0
movl $0x10ef0, %r15d         # imm = 0x10EF0
movl %r12d, %ecx
shrq %cl, %r15
btq %r12, %r13
movl $0x0, %r14d
adcl $0x1, %r14d
leal 0x1(%r14), %esi
movq %rbx, %rdi
callq 0x15218
testq %rax, %rax
je 0x15160
movb %r14b, (%rax)
movl %r14d, %ecx
addq %rcx, 0x60(%rbx)
testb $0x1, %r15b
jne 0x14fe8
incq %rax
jmp 0x14ff0
movb $0x41, 0x1(%rax)
addq $0x2, %rax
leaq 0xe1f9(%rip), %rcx      # 0x231f0
movb (%r12,%rcx), %cl
addb $0x50, %cl
movb %cl, (%rax)
leaq -0x1(%r12), %rax
cmpq %rbp, %r12
movq %rax, %r12
jg 0x14fa4
movq 0x8(%rsp), %rax
cmpl $0x7, %eax
jl 0x15085
movl %eax, %r15d
movl $0x10ef0, %r12d         # imm = 0x10EF0
leaq 0xe1c9(%rip), %r14      # 0x231f0
movl $0x10ef0, %r13d         # imm = 0x10EF0
movl %r15d, %ecx
shrq %cl, %r13
btq %r15, %r12
movl $0x0, %ebp
adcl $0x1, %ebp
leal 0x1(%rbp), %esi
movq %rbx, %rdi
callq 0x15218
testq %rax, %rax
je 0x15160
movb %bpl, (%rax)
movl %ebp, %ecx
addq %rcx, 0x60(%rbx)
testb $0x1, %r13b
jne 0x15067
incq %rax
jmp 0x1506f
movb $0x41, 0x1(%rax)
addq $0x2, %rax
movb (%r15,%r14), %cl
addb $0x50, %cl
movb %cl, (%rax)
leaq -0x1(%r15), %rax
cmpq $0x7, %r15
movq %rax, %r15
jg 0x15027
movq 0x20(%rsp), %r14
testl %r14d, %r14d
je 0x150dc
leal (%r14,%r14,2), %esi
incl %esi
movq %rbx, %rdi
callq 0x15218
testq %rax, %rax
je 0x15160
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 0x150dc
movw $0x8b4c, 0x4(%rax)      # imm = 0x8B4C
movb $-0x2, 0x6(%rax)
cmpl $0x3, %r14d
jne 0x150dc
movw $0x8b4c, 0x7(%rax)      # imm = 0x8B4C
movb $-0xe, 0x9(%rax)
movq 0x18(%rsp), %rax
addl 0x14(%rsp), %eax
leal 0x8(,%rax,8), %eax
movl 0x68(%rsp), %ecx
leal (%rcx,%rax), %ebp
addl $0x17, %ebp
andl $-0x10, %ebp
subl %eax, %ebp
movl %ebp, 0x58(%rbx)
testl %ebp, %ebp
jle 0x15200
cmpl $0x7f, %ebp
ja 0x15135
movl $0x5, %esi
movq %rbx, %rdi
callq 0x15218
testq %rax, %rax
je 0x15160
movb $0x4, (%rax)
addq $0x4, 0x60(%rbx)
movw $0x8348, 0x1(%rax)      # imm = 0x8348
movb $-0x14, 0x3(%rax)
movb %bpl, 0x4(%rax)
jmp 0x1515c
movl $0x8, %esi
movq %rbx, %rdi
callq 0x15218
testq %rax, %rax
je 0x15160
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 0x15162
movl (%rbx), %eax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0xe1c7(%rip), %rdi      # 0x2333f
movl $0x38e, %esi            # imm = 0x38E
jmp 0x1520c
leaq 0xe1b6(%rip), %rdi      # 0x2333f
movl $0x38f, %esi            # imm = 0x38F
jmp 0x1520c
leaq 0xe1a8(%rip), %rdi      # 0x2333f
movl $0x390, %esi            # imm = 0x390
jmp 0x1520c
leaq 0xe19a(%rip), %rdi      # 0x2333f
movl $0x391, %esi            # imm = 0x391
jmp 0x1520c
leaq 0xe18c(%rip), %rdi      # 0x2333f
movl $0x392, %esi            # imm = 0x392
jmp 0x1520c
leaq 0xe17e(%rip), %rdi      # 0x2333f
movl $0x393, %esi            # imm = 0x393
jmp 0x1520c
leaq 0xe170(%rip), %rdi      # 0x2333f
movl $0x394, %esi            # imm = 0x394
jmp 0x1520c
leaq 0xe162(%rip), %rdi      # 0x2333f
movl $0x395, %esi            # imm = 0x395
jmp 0x1520c
leaq 0xe154(%rip), %rdi      # 0x2333f
movl $0x396, %esi            # imm = 0x396
jmp 0x1520c
leaq 0xe146(%rip), %rdi      # 0x2333f
movl $0x397, %esi            # imm = 0x397
jmp 0x1520c
leaq 0xe102(%rip), %rdi      # 0x23309
movl $0xcd, %esi
xorl %eax, %eax
callq 0x2080
callq 0x2040