// File: /workspace/github_c_makefile_star2_O1/mmcco[P]sljit/sljit_src/sljitNativeX86_64.c
// Function: emit_x86_instruction
static u_char* emit_x86_instruction(struct sljit_compiler *compiler, int size,
	/* The reg or immediate operand. */
	int a, long imma,
	/* The general operand (not immediate). */
	int b, long immb)
{
	u_char *inst;
	u_char *buf_ptr;
	u_char rex = 0;
	int flags = size & ~0xf;
	int inst_size;

	/* The immediate operand must be 32 bit. */
	SLJIT_ASSERT(!(a & SLJIT_IMM) || compiler->mode32 || IS_HALFWORD(imma));
	/* Both cannot be switched on. */
	SLJIT_ASSERT((flags & (EX86_BIN_INS | EX86_SHIFT_INS)) != (EX86_BIN_INS | EX86_SHIFT_INS));
	/* Size flags not allowed for typed instructions. */
	SLJIT_ASSERT(!(flags & (EX86_BIN_INS | EX86_SHIFT_INS)) || (flags & (EX86_BYTE_ARG | EX86_HALF_ARG)) == 0);
	/* Both size flags cannot be switched on. */
	SLJIT_ASSERT((flags & (EX86_BYTE_ARG | EX86_HALF_ARG)) != (EX86_BYTE_ARG | EX86_HALF_ARG));
	/* SSE2 and immediate is not possible. */
	SLJIT_ASSERT(!(a & SLJIT_IMM) || !(flags & EX86_SSE2));
	SLJIT_ASSERT((flags & (EX86_PREF_F2 | EX86_PREF_F3)) != (EX86_PREF_F2 | EX86_PREF_F3)
		&& (flags & (EX86_PREF_F2 | EX86_PREF_66)) != (EX86_PREF_F2 | EX86_PREF_66)
		&& (flags & (EX86_PREF_F3 | EX86_PREF_66)) != (EX86_PREF_F3 | EX86_PREF_66));

	size &= 0xf;
	inst_size = size;

	if (!compiler->mode32 && !(flags & EX86_NO_REXW))
		rex |= REX_W;
	else if (flags & EX86_REX)
		rex |= REX;

	if (flags & (EX86_PREF_F2 | EX86_PREF_F3))
		inst_size++;
	if (flags & EX86_PREF_66)
		inst_size++;

	/* Calculate size of b. */
	inst_size += 1; /* mod r/m byte. */
	if (b & SLJIT_MEM) {
		if (!(b & OFFS_REG_MASK)) {
			if (NOT_HALFWORD(immb)) {
				if (emit_load_imm64(compiler, TMP_REG3, immb))
					return NULL;
				immb = 0;
				if (b & REG_MASK)
					b |= TO_OFFS_REG(TMP_REG3);
				else
					b |= TMP_REG3;
			}
			else if (reg_lmap[b & REG_MASK] == 4)
				b |= TO_OFFS_REG(SLJIT_SP);
		}

		if ((b & REG_MASK) == SLJIT_UNUSED)
			inst_size += 1 + sizeof(int); /* SIB byte required to avoid RIP based addressing. */
		else {
			if (reg_map[b & REG_MASK] >= 8)
				rex |= REX_B;

			if (immb != 0 && (!(b & OFFS_REG_MASK) || (b & OFFS_REG_MASK) == TO_OFFS_REG(SLJIT_SP))) {
				/* Immediate operand. */
				if (immb <= 127 && immb >= -128)
					inst_size += sizeof(s_char);
				else
					inst_size += sizeof(int);
			}
			else if (reg_lmap[b & REG_MASK] == 5)
				inst_size += sizeof(s_char);

			if ((b & OFFS_REG_MASK) != SLJIT_UNUSED) {
				inst_size += 1; /* SIB byte. */
				if (reg_map[OFFS_REG(b)] >= 8)
					rex |= REX_X;
			}
		}
	}
	else if (!(flags & EX86_SSE2_OP2) && reg_map[b] >= 8)
		rex |= REX_B;

	if (a & SLJIT_IMM) {
		if (flags & EX86_BIN_INS) {
			if (imma <= 127 && imma >= -128) {
				inst_size += 1;
				flags |= EX86_BYTE_ARG;
			} else
				inst_size += 4;
		}
		else if (flags & EX86_SHIFT_INS) {
			imma &= compiler->mode32 ? 0x1f : 0x3f;
			if (imma != 1) {
				inst_size ++;
				flags |= EX86_BYTE_ARG;
			}
		} else if (flags & EX86_BYTE_ARG)
			inst_size++;
		else if (flags & EX86_HALF_ARG)
			inst_size += sizeof(short);
		else
			inst_size += sizeof(int);
	}
	else {
		SLJIT_ASSERT(!(flags & EX86_SHIFT_INS) || a == SLJIT_PREF_SHIFT_REG);
		/* reg_map[SLJIT_PREF_SHIFT_REG] is less than 8. */
		if (!(flags & EX86_SSE2_OP1) && reg_map[a] >= 8)
			rex |= REX_R;
	}

	if (rex)
		inst_size++;

	inst = ensure_buf(compiler, 1 + inst_size);
	if (!inst)
		return NULL;

	/* Encoding the byte. */
	INC_SIZE(inst_size);
	if (flags & EX86_PREF_F2)
		*inst++ = 0xf2;
	if (flags & EX86_PREF_F3)
		*inst++ = 0xf3;
	if (flags & EX86_PREF_66)
		*inst++ = 0x66;
	if (rex)
		*inst++ = rex;
	buf_ptr = inst + size;

	/* Encode mod/rm byte. */
	if (!(flags & EX86_SHIFT_INS)) {
		if ((flags & EX86_BIN_INS) && (a & SLJIT_IMM))
			*inst = (flags & EX86_BYTE_ARG) ? GROUP_BINARY_83 : GROUP_BINARY_81;

		if ((a & SLJIT_IMM) || (a == 0))
			*buf_ptr = 0;
		else if (!(flags & EX86_SSE2_OP1))
			*buf_ptr = reg_lmap[a] << 3;
		else
			*buf_ptr = a << 3;
	}
	else {
		if (a & SLJIT_IMM) {
			if (imma == 1)
				*inst = GROUP_SHIFT_1;
			else
				*inst = GROUP_SHIFT_N;
		} else
			*inst = GROUP_SHIFT_CL;
		*buf_ptr = 0;
	}

	if (!(b & SLJIT_MEM))
		*buf_ptr++ |= MOD_REG + ((!(flags & EX86_SSE2_OP2)) ? reg_lmap[b] : b);
	else if ((b & REG_MASK) != SLJIT_UNUSED) {
		if ((b & OFFS_REG_MASK) == SLJIT_UNUSED || (b & OFFS_REG_MASK) == TO_OFFS_REG(SLJIT_SP)) {
			if (immb != 0 || reg_lmap[b & REG_MASK] == 5) {
				if (immb <= 127 && immb >= -128)
					*buf_ptr |= 0x40;
				else
					*buf_ptr |= 0x80;
			}

			if ((b & OFFS_REG_MASK) == SLJIT_UNUSED)
				*buf_ptr++ |= reg_lmap[b & REG_MASK];
			else {
				*buf_ptr++ |= 0x04;
				*buf_ptr++ = reg_lmap[b & REG_MASK] | (reg_lmap[OFFS_REG(b)] << 3);
			}

			if (immb != 0 || reg_lmap[b & REG_MASK] == 5) {
				if (immb <= 127 && immb >= -128)
					*buf_ptr++ = immb; /* 8 bit displacement. */
				else {
					*(int*)buf_ptr = immb; /* 32 bit displacement. */
					buf_ptr += sizeof(int);
				}
			}
		}
		else {
			if (reg_lmap[b & REG_MASK] == 5)
				*buf_ptr |= 0x40;
			*buf_ptr++ |= 0x04;
			*buf_ptr++ = reg_lmap[b & REG_MASK] | (reg_lmap[OFFS_REG(b)] << 3) | (immb << 6);
			if (reg_lmap[b & REG_MASK] == 5)
				*buf_ptr++ = 0;
		}
	}
	else {
		*buf_ptr++ |= 0x04;
		*buf_ptr++ = 0x25;
		*(int*)buf_ptr = immb; /* 32 bit displacement. */
		buf_ptr += sizeof(int);
	}

	if (a & SLJIT_IMM) {
		if (flags & EX86_BYTE_ARG)
			*buf_ptr = imma;
		else if (flags & EX86_HALF_ARG)
			*(short*)buf_ptr = imma;
		else if (!(flags & EX86_SHIFT_INS))
			*(int*)buf_ptr = imma;
	}

	return !(flags & EX86_SHIFT_INS) ? inst : (inst + 1);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movl %r8d, %r12d
movl %esi, %ebp
testb $0x40, %dl
je 0x15e31
movslq %ecx, %rax
cmpq %rcx, %rax
je 0x15e31
cmpl $0x0, 0x70(%rdi)
je 0x163ae
movl %ebp, %eax
andl $0x30, %eax
je 0x15e4d
cmpl $0x30, %eax
je 0x163bc
testl $0x300, %ebp            # imm = 0x300
jne 0x163ca
movl %ebp, %eax
notl %eax
testl $0x300, %eax            # imm = 0x300
je 0x16384
testb $0x40, %dl
sete %sil
testl $0x6000, %ebp           # imm = 0x6000
sete %r8b
orb %sil, %r8b
je 0x16392
testl $0x1400, %eax           # imm = 0x1400
je 0x163a0
movl %ebp, %eax
andl $0x1800, %eax           # imm = 0x1800
cmpl $0x1800, %eax           # imm = 0x1800
je 0x163a0
movl %ebp, %esi
andl $0xc00, %esi            # imm = 0xC00
cmpl $0xc00, %esi            # imm = 0xC00
je 0x163a0
movl %ebp, %r10d
andl $0xf, %r10d
movl %ebp, %esi
andl $0x80, %esi
movl %ebp, %r8d
andb $0x40, %r8b
orl 0x70(%rdi), %esi
movzbl %r8b, %esi
movl $0x48, %r15d
cmovnel %esi, %r15d
xorl %r14d, %r14d
testl %eax, %eax
setne %r14b
btl $0xa, %ebp
movl %r10d, 0x14(%rsp)
adcl %r10d, %r14d
leal 0x1(%r14), %r13d
testb %r12b, %r12b
movq %rdx, 0x8(%rsp)
js 0x15f19
btl $0xe, %ebp
jb 0x16011
movzbl %r15b, %eax
orb $0x41, %r15b
movl $0x10ef0, %esi          # imm = 0x10EF0
btq %r12, %rsi
movzbl %r15b, %r15d
cmovael %eax, %r15d
jmp 0x16011
testl $0x3f00, %r12d          # imm = 0x3F00
je 0x15f6b
movl %r12d, %eax
andl $0x3f, %eax
je 0x15fa8
movzbl %r15b, %esi
orb $0x41, %r15b
movl $0x10ef0, %r8d          # imm = 0x10EF0
btq %rax, %r8
movzbl %r15b, %r15d
cmovael %esi, %r15d
testq %r9, %r9
je 0x15fb1
movl %r12d, %eax
andl $0x3f00, %eax           # imm = 0x3F00
cmpl $0xd00, %eax            # imm = 0xD00
je 0x15f5c
testl %eax, %eax
jne 0x15fb1
movsbq %r9b, %rax
cmpq %r9, %rax
jne 0x15fe4
addl $0x2, %r14d
jmp 0x15fe8
movslq %r9d, %rax
cmpq %r9, %rax
je 0x15fc4
movq %rcx, (%rsp)
movl $0x10, %esi
movq %r9, %rdx
movq %rdi, %rbx
callq 0x16832
testl %eax, %eax
jne 0x160fb
movq %rbx, %rdi
testb $0x3f, %r12b
je 0x1636f
orl $0x1000, %r12d          # imm = 0x1000
jmp 0x16373
addl $0x6, %r14d
movl %r14d, %r13d
jmp 0x16011
movl %r12d, %eax
andl $0x3e, %eax
addl $0x2, %r14d
cmpl $0x8, %eax
cmovel %r14d, %r13d
jmp 0x15feb
movl %r12d, %eax
andl $0x3f, %eax
cmpl $0xd, %eax
je 0x15fd8
cmpl $0x7, %eax
jne 0x15f22
orl $0xd00, %r12d           # imm = 0xD00
jmp 0x15f22
addl $0x5, %r14d
movl %r14d, %r13d
testl $0x3f00, %r12d          # imm = 0x3F00
je 0x16011
incl %r13d
movl %r12d, %eax
shrl $0x8, %eax
movzbl %r15b, %esi
orb $0x42, %r15b
btq %rax, %r8
movzbl %r15b, %r15d
cmovael %esi, %r15d
testb $0x40, %dl
movq %r9, (%rsp)
je 0x16042
testb $0x10, %bpl
jne 0x1607b
testb $0x20, %bpl
jne 0x1609b
btl $0x8, %ebp
jb 0x160b9
btl $0x9, %ebp
jae 0x16092
movq %rcx, %r14
addl $0x2, %r13d
jmp 0x160cd
movq %rcx, %r14
testb $0x20, %bpl
sete %al
cmpl $0x3, %edx
sete %cl
orb %al, %cl
je 0x163d8
btl $0xd, %ebp
jb 0x160cd
movzbl %r15b, %eax
orb $0x44, %r15b
movl $0x10ef0, %ecx          # imm = 0x10EF0
btq %rdx, %rcx
movzbl %r15b, %r15d
cmovael %eax, %r15d
jmp 0x160cd
movsbq %cl, %rax
cmpq %rcx, %rax
jne 0x16092
movq %rcx, %r14
incl %r13d
orl $0x100, %ebp            # imm = 0x100
jmp 0x160cd
movq %rcx, %r14
addl $0x4, %r13d
jmp 0x160cd
xorl %eax, %eax
cmpl $0x0, 0x70(%rdi)
sete %al
shll $0x5, %eax
orl $0x1f, %eax
andl %ecx, %eax
cmpl $0x1, %eax
jne 0x160c1
movl $0x1, %r14d
jmp 0x160cd
movq %rcx, %r14
incl %r13d
jmp 0x160cd
incl %r13d
orl $0x100, %ebp            # imm = 0x100
movq %rax, %r14
cmpb $0x1, %r15b
sbbl $-0x1, %r13d
leal 0x1(%r13), %esi
movq %rdi, %rbx
callq 0x152be
testq %rax, %rax
je 0x160fb
movb %r13b, (%rax)
movl %r13d, %ecx
addq %rcx, 0x60(%rbx)
btl $0xb, %ebp
jb 0x16102
incq %rax
jmp 0x1610a
xorl %eax, %eax
jmp 0x16360
movb $-0xe, 0x1(%rax)
addq $0x2, %rax
movq %r14, %r11
movq 0x8(%rsp), %r10
btl $0xc, %ebp
jae 0x1611e
movb $-0xd, (%rax)
incq %rax
btl $0xa, %ebp
jae 0x1612a
movb $0x66, (%rax)
incq %rax
testb %r15b, %r15b
je 0x16135
movb %r15b, (%rax)
incq %rax
movl 0x14(%rsp), %edx
addq %rax, %rdx
movl %ebp, %ecx
andl $0x20, %ecx
jne 0x1619d
testb $0x40, %r10b
sete %sil
testb $0x10, %bpl
sete %dil
orb %sil, %dil
jne 0x1616a
movl %ebp, %esi
shrl $0x8, %esi
andl $0x1, %esi
addb %sil, %sil
orb $-0x7f, %sil
movb %sil, (%rax)
movl %r10d, %esi
andl $0x40, %esi
shrl $0x6, %esi
testl %r10d, %r10d
sete %dil
orb %sil, %dil
jne 0x161c0
btl $0xd, %ebp
jb 0x162a3
movslq %r10d, %rsi
leaq 0xcf8d(%rip), %rdi      # 0x23120
movb (%rsi,%rdi), %sil
shlb $0x3, %sil
jmp 0x161c2
cmpq $0x1, %r11
sete %sil
shlb $0x4, %sil
orb $-0x3f, %sil
movzbl %sil, %esi
testb $0x40, %r10b
movl $0xd3, %edi
cmovnel %esi, %edi
movb %dil, (%rax)
xorl %esi, %esi
movb %sil, (%rdx)
testb %r12b, %r12b
js 0x161ed
btl $0xe, %ebp
jb 0x161de
movslq %r12d, %rsi
leaq 0xcf46(%rip), %rdi      # 0x23120
movb (%rsi,%rdi), %r12b
addb $-0x40, %r12b
orb %r12b, (%rdx)
incq %rdx
jmp 0x16336
movl %r12d, %esi
andl $0x3f, %esi
je 0x1628c
movl %r12d, %r8d
andl $0x3f00, %r8d           # imm = 0x3F00
cmpl $0xd00, %r8d            # imm = 0xD00
je 0x16215
testl %r8d, %r8d
jne 0x162b0
cmpq $0x0, (%rsp)
setne %r9b
movl %r12d, %edi
andl $0x3e, %edi
cmpl $0x8, %edi
sete %dil
orb %r9b, %dil
cmpb $0x1, %dil
jne 0x16258
movq (%rsp), %rbx
movsbq %bl, %r9
cmpq %rbx, %r9
movl $0x40, %r9d
movq %r10, %rbx
movl $0x80, %r10d
cmovel %r9d, %r10d
orb %r10b, (%rdx)
movq %rbx, %r10
testl %r8d, %r8d
je 0x162ff
orb $0x4, (%rdx)
leaq 0xceb5(%rip), %r8       # 0x23120
shrl $0x8, %r12d
andl $0x3f, %r12d
movb (%r12,%r8), %r9b
shlb $0x3, %r9b
orb (%rsi,%r8), %r9b
movb %r9b, 0x1(%rdx)
addq $0x2, %rdx
jmp 0x16310
orb $0x4, (%rdx)
movb $0x25, 0x1(%rdx)
movq (%rsp), %rsi
movl %esi, 0x2(%rdx)
addq $0x6, %rdx
jmp 0x16336
leal (,%r10,8), %esi
jmp 0x161c2
movl %r12d, %edi
andl $0x3e, %edi
cmpl $0x8, %edi
jne 0x162be
orb $0x40, (%rdx)
orb $0x4, (%rdx)
leaq 0xce58(%rip), %r8       # 0x23120
movzbl (%rsi,%r8), %esi
shrl $0x8, %r12d
andl $0x3f, %r12d
movzbl (%r12,%r8), %r8d
shll $0x3, %r8d
movq (%rsp), %r9
shll $0x6, %r9d
orl %esi, %r9d
orl %r8d, %r9d
movb %r9b, 0x1(%rdx)
cmpl $0x8, %edi
jne 0x16332
movb $0x0, 0x2(%rdx)
addq $0x3, %rdx
jmp 0x16336
leaq 0xce1a(%rip), %r8       # 0x23120
movb (%rsi,%r8), %sil
orb %sil, (%rdx)
incq %rdx
testb %dil, %dil
je 0x16336
movq (%rsp), %rdi
movsbq %dil, %rsi
cmpq %rdi, %rsi
jne 0x1632a
movb %dil, (%rdx)
jmp 0x161e5
movl %edi, (%rdx)
addq $0x4, %rdx
jmp 0x16336
addq $0x2, %rdx
testb $0x40, %r10b
je 0x1635a
btl $0x8, %ebp
jb 0x16351
btl $0x9, %ebp
jb 0x16356
testl %ecx, %ecx
jne 0x1635a
movl %r11d, (%rdx)
jmp 0x1635a
movb %r11b, (%rdx)
jmp 0x1635a
movw %r11w, (%rdx)
shrl $0x5, %ecx
addq %rcx, %rax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
orl $0x10, %r12d
xorl %r9d, %r9d
movq (%rsp), %rcx
movq 0x8(%rsp), %rdx
jmp 0x15f22
leaq 0xceae(%rip), %rdi      # 0x23239
movl $0x16d, %esi            # imm = 0x16D
jmp 0x163e4
leaq 0xcea0(%rip), %rdi      # 0x23239
movl $0x16f, %esi            # imm = 0x16F
jmp 0x163e4
leaq 0xce92(%rip), %rdi      # 0x23239
movl $0x172, %esi            # imm = 0x172
jmp 0x163e4
leaq 0xce84(%rip), %rdi      # 0x23239
movl $0x167, %esi            # imm = 0x167
jmp 0x163e4
leaq 0xce76(%rip), %rdi      # 0x23239
movl $0x169, %esi            # imm = 0x169
jmp 0x163e4
leaq 0xce68(%rip), %rdi      # 0x23239
movl $0x16b, %esi            # imm = 0x16B
jmp 0x163e4
leaq 0xce5a(%rip), %rdi      # 0x23239
movl $0x1c2, %esi            # imm = 0x1C2
xorl %eax, %eax
callq 0x2080
callq 0x2040