// File: /workspace/github_c_makefile_star2_O1/mmcco[P]sljit/sljit_src/sljitNativeX86_common.c
// Function: sljit_generate_code
void* sljit_generate_code(struct sljit_compiler *compiler)
{
	struct sljit_memory_fragment *buf;
	u_char *code;
	u_char *code_ptr;
	u_char *buf_ptr;
	u_char *buf_end;
	u_char len;

	struct sljit_label *label;
	struct sljit_jump *jump;
	struct sljit_const *const_;

	CHECK_ERROR_PTR();
	CHECK_PTR(check_sljit_generate_code(compiler));
	reverse_buf(compiler);

	/* Second code generation pass. */
	code = (u_char*)SLJIT_MALLOC_EXEC(compiler->size);
	PTR_FAIL_WITH_EXEC_IF(code);
	buf = compiler->buf;

	code_ptr = code;
	label = compiler->labels;
	jump = compiler->jumps;
	const_ = compiler->consts;
	do {
		buf_ptr = buf->memory;
		buf_end = buf_ptr + buf->used_size;
		do {
			len = *buf_ptr++;
			if (len > 0) {
				/* The code is already generated. */
				memmove(code_ptr, buf_ptr, len);
				code_ptr += len;
				buf_ptr += len;
			}
			else {
				if (*buf_ptr >= 4) {
					jump->addr = (unsigned long)code_ptr;
					if (!(jump->flags & SLJIT_REWRITABLE_JUMP))
						code_ptr = generate_near_jump_code(jump, code_ptr, code, *buf_ptr - 4);
					else
						code_ptr = generate_far_jump_code(jump, code_ptr, *buf_ptr - 4);
					jump = jump->next;
				}
				else if (*buf_ptr == 0) {
					label->addr = (unsigned long)code_ptr;
					label->size = code_ptr - code;
					label = label->next;
				}
				else if (*buf_ptr == 1) {
					const_->addr = ((unsigned long)code_ptr) - sizeof(long);
					const_ = const_->next;
				}
				else {
#if (defined SLJIT_CONFIG_X86_32 && SLJIT_CONFIG_X86_32)
					*code_ptr++ = (*buf_ptr == 2) ? CALL_i32 : JMP_i32;
					buf_ptr++;
					*(long*)code_ptr = *(long*)buf_ptr - ((long)code_ptr + sizeof(long));
					code_ptr += sizeof(long);
					buf_ptr += sizeof(long) - 1;
#else
					code_ptr = generate_fixed_jump(code_ptr, *(long*)(buf_ptr + 1), *buf_ptr);
					buf_ptr += sizeof(long);
#endif
				}
				buf_ptr++;
			}
		} while (buf_ptr < buf_end);
		SLJIT_ASSERT(buf_ptr == buf_end);
		buf = buf->next;
	} while (buf);

	SLJIT_ASSERT(!label);
	SLJIT_ASSERT(!jump);
	SLJIT_ASSERT(!const_);

	jump = compiler->jumps;
	while (jump) {
		if (jump->flags & PATCH_MB) {
			SLJIT_ASSERT((long)(jump->u.label->addr - (jump->addr + sizeof(s_char))) >= -128 && (long)(jump->u.label->addr - (jump->addr + sizeof(s_char))) <= 127);
			*(u_char*)jump->addr = (u_char)(jump->u.label->addr - (jump->addr + sizeof(s_char)));
		} else if (jump->flags & PATCH_MW) {
			if (jump->flags & JUMP_LABEL) {
#if (defined SLJIT_CONFIG_X86_32 && SLJIT_CONFIG_X86_32)
				*(long*)jump->addr = (long)(jump->u.label->addr - (jump->addr + sizeof(long)));
#else
				SLJIT_ASSERT((long)(jump->u.label->addr - (jump->addr + sizeof(int))) >= HALFWORD_MIN && (long)(jump->u.label->addr - (jump->addr + sizeof(int))) <= HALFWORD_MAX);
				*(int*)jump->addr = (int)(jump->u.label->addr - (jump->addr + sizeof(int)));
#endif
			}
			else {
#if (defined SLJIT_CONFIG_X86_32 && SLJIT_CONFIG_X86_32)
				*(long*)jump->addr = (long)(jump->u.target - (jump->addr + sizeof(long)));
#else
				SLJIT_ASSERT((long)(jump->u.target - (jump->addr + sizeof(int))) >= HALFWORD_MIN && (long)(jump->u.target - (jump->addr + sizeof(int))) <= HALFWORD_MAX);
				*(int*)jump->addr = (int)(jump->u.target - (jump->addr + sizeof(int)));
#endif
			}
		}
#if (defined SLJIT_CONFIG_X86_64 && SLJIT_CONFIG_X86_64)
		else if (jump->flags & PATCH_MD)
			*(long*)jump->addr = jump->u.label->addr;
#endif

		jump = jump->next;
	}

	/* Maybe we waste some space because of short jumps. */
	SLJIT_ASSERT(code_ptr <= code + compiler->size);
	compiler->error = SLJIT_ERR_COMPILED;
	compiler->executable_size = code_ptr - code;
	return code;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
cmpl $0x0, (%rdi)
je 0x14a5d
xorl %eax, %eax
jmp 0x14df0
movq %rdi, %rbx
movq 0x60(%rdi), %rdi
testq %rdi, %rdi
je 0x14e4c
leaq 0x10(%rbx), %r14
movq %r14, %rax
movq (%rax), %rax
testq %rax, %rax
je 0x14a93
testb $0x3, 0x10(%rax)
jne 0x14a74
leaq 0xe7e6(%rip), %rdi      # 0x2326f
movl $0x380, %esi            # imm = 0x380
jmp 0x14e24
movq 0x38(%rbx), %rax
xorl %ecx, %ecx
movq %rax, %rdx
movq (%rax), %rax
movq %rcx, (%rdx)
movq %rdx, %rcx
testq %rax, %rax
jne 0x14a99
movq %rdx, 0x38(%rbx)
callq 0x1445f
testq %rax, %rax
je 0x14dff
movq %r14, 0x20(%rsp)
movq 0x38(%rbx), %rdx
movq 0x8(%rbx), %rcx
movq %rcx, 0x10(%rsp)
movq 0x10(%rbx), %r12
movq %rbx, 0x28(%rsp)
movq 0x18(%rbx), %rcx
movq %rcx, 0x18(%rsp)
movq %rax, 0x8(%rsp)
movq %rax, %r15
leaq 0x10(%rdx), %rbx
movq %rdx, 0x30(%rsp)
movq 0x8(%rdx), %r14
addq %rbx, %r14
leaq 0x1(%rbx), %r13
movzbl (%rbx), %ebp
testq %rbp, %rbp
je 0x14b20
movq %r15, %rdi
movq %r13, %rsi
movq %rbp, %rdx
callq 0x2100
addq %rbp, %r15
addq %rbp, %r13
movq %r13, %rbx
jmp 0x14c1f
movzbl (%r13), %eax
cmpl $0x4, %eax
jb 0x14b58
movq %r15, 0x8(%r12)
movq 0x10(%r12), %rax
movzbl (%r13), %ecx
leal -0x4(%rcx), %edx
btl $0xc, %eax
jb 0x14c02
testb $0x1, %al
jne 0x14bd0
movq 0x18(%r12), %rsi
jmp 0x14bde
cmpl $0x1, %eax
je 0x14b83
testl %eax, %eax
jne 0x14b9a
movq 0x10(%rsp), %rcx
movq %r15, 0x8(%rcx)
movq %r15, %rax
subq 0x8(%rsp), %rax
movq %rax, 0x10(%rcx)
movq (%rcx), %rcx
movq %rcx, 0x10(%rsp)
jmp 0x14c14
leaq -0x8(%r15), %rax
movq 0x18(%rsp), %rcx
movq %rax, 0x8(%rcx)
movq (%rcx), %rcx
movq %rcx, 0x18(%rsp)
jmp 0x14c14
movq 0x2(%rbx), %rdx
movq %rdx, %rcx
subq %r15, %rcx
leaq 0x7ffffffb(%rcx), %rsi
shrq $0x20, %rsi
jne 0x14c4e
addq $-0x5, %rcx
cmpl $0x2, %eax
sete %al
xorb $-0x17, %al
movb %al, (%r15)
movq %rcx, 0x1(%r15)
incq %r15
jmp 0x14c72
movq 0x18(%r12), %rax
movq 0x10(%rax), %rsi
addq 0x8(%rsp), %rsi
movq %r15, %rdi
subq %rsi, %rdi
subq %r15, %rsi
addq $0x7e, %rsi
cmpq $0x100, %rsi            # imm = 0x100
setb %al
subq $-0x80000000, %rdi      # imm = 0x80000000
shrq $0x20, %rdi
je 0x14c2d
movq %r12, %rdi
movq %r15, %rsi
callq 0x14e92
movq %rax, %r15
movq (%r12), %r12
movl $0x1, %eax
addq %rax, %rbx
incq %rbx
cmpq %r14, %rbx
jb 0x14af8
jmp 0x14cf3
cmpl $0x16, %edx
jne 0x14c79
cmpq $0x100, %rsi            # imm = 0x100
setb %cl
addb %cl, %cl
orb $-0x17, %cl
movb %cl, (%r15)
incq %r15
movl $0x1, %ecx
jmp 0x14cc2
movw $0xb949, (%r15)         # imm = 0xB949
movq %rdx, 0x2(%r15)
movw $0xff41, 0xa(%r15)      # imm = 0xFF41
cmpl $0x2, %eax
setne %al
shlb $0x4, %al
addb $-0x2f, %al
movb %al, 0xc(%r15)
addq $0xd, %r15
movl $0x9, %eax
jmp 0x14c19
cmpb $0x1b, %cl
jb 0x14c8c
movb $-0x18, (%r15)
incq %r15
movl $0x1, %ecx
jmp 0x14cc0
cmpq $0xff, %rsi
ja 0x14ca8
movl %edx, %edi
callq 0x1db72
addb $-0x10, %al
movb %al, (%r15)
incq %r15
movb $0x1, %al
jmp 0x14c47
movb $0xf, (%r15)
movl %edx, %edi
callq 0x1db72
movb %al, 0x1(%r15)
addq $0x2, %r15
movl $0x2, %ecx
xorl %eax, %eax
addq %rcx, 0x8(%r12)
movq 0x10(%r12), %rcx
testb %al, %al
je 0x14ce1
orq $0x4, %rcx
movq %rcx, 0x10(%r12)
incq %r15
jmp 0x14c10
orq $0x8, %rcx
movq %rcx, 0x10(%r12)
addq $0x4, %r15
jmp 0x14c10
jne 0x14e0a
movq 0x30(%rsp), %rdx
movq (%rdx), %rdx
testq %rdx, %rdx
jne 0x14ae8
cmpq $0x0, 0x10(%rsp)
jne 0x14e5a
testq %r12, %r12
jne 0x14e68
cmpq $0x0, 0x18(%rsp)
movq 0x28(%rsp), %rdi
movq 0x8(%rsp), %rax
jne 0x14e76
movq 0x20(%rsp), %rcx
movq (%rcx), %r8
testq %r8, %r8
je 0x14dd3
movq 0x10(%r8), %rcx
testb $0x4, %cl
jne 0x14d6a
testb $0x8, %cl
jne 0x14d8d
testb $0x10, %cl
je 0x14dcb
movq 0x8(%r8), %rcx
movq 0x18(%r8), %rdx
movq 0x8(%rdx), %rdx
movq %rdx, (%rcx)
jmp 0x14dcb
movq 0x8(%r8), %rcx
movq 0x18(%r8), %rsi
movq %rcx, %rdx
notq %rdx
addq 0x8(%rsi), %rdx
movsbq %dl, %rsi
cmpq %rdx, %rsi
jne 0x14e18
movb %dl, (%rcx)
jmp 0x14dcb
testb $0x1, %cl
jne 0x14dae
movq 0x8(%r8), %rcx
movq 0x18(%r8), %rdx
subq %rcx, %rdx
addq $-0x4, %rdx
movslq %edx, %rsi
cmpq %rdx, %rsi
je 0x14dc9
jmp 0x14e3e
movq 0x8(%r8), %rcx
movq 0x18(%r8), %rdx
movq 0x8(%rdx), %rdx
subq %rcx, %rdx
addq $-0x4, %rdx
movslq %edx, %rsi
cmpq %rdx, %rsi
jne 0x14e30
movl %edx, (%rcx)
movq (%r8), %r8
jmp 0x14d3d
movq 0x60(%rdi), %rcx
addq %rax, %rcx
cmpq %rcx, %r15
ja 0x14e84
movl $0x1, (%rdi)
subq %rax, %r15
movq %r15, 0x68(%rdi)
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl $0x3, (%rbx)
jmp 0x14a56
leaq 0xe3ee(%rip), %rdi      # 0x231ff
movl $0x204, %esi            # imm = 0x204
jmp 0x14e24
leaq 0xe3e0(%rip), %rdi      # 0x231ff
movl $0x20f, %esi            # imm = 0x20F
xorl %eax, %eax
callq 0x2080
callq 0x2040
leaq 0xe3c8(%rip), %rdi      # 0x231ff
movl $0x216, %esi            # imm = 0x216
jmp 0x14e24
leaq 0xe3ba(%rip), %rdi      # 0x231ff
movl $0x21e, %esi            # imm = 0x21E
jmp 0x14e24
leaq 0xe41c(%rip), %rdi      # 0x2326f
movl $0x37c, %esi            # imm = 0x37C
jmp 0x14e24
leaq 0xe39e(%rip), %rdi      # 0x231ff
movl $0x208, %esi            # imm = 0x208
jmp 0x14e24
leaq 0xe390(%rip), %rdi      # 0x231ff
movl $0x209, %esi            # imm = 0x209
jmp 0x14e24
leaq 0xe382(%rip), %rdi      # 0x231ff
movl $0x20a, %esi            # imm = 0x20A
jmp 0x14e24
leaq 0xe374(%rip), %rdi      # 0x231ff
movl $0x22c, %esi            # imm = 0x22C
jmp 0x14e24