// File: /workspace/github_c_makefile_star2_O3/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 0x149d8
xorl %eax, %eax
jmp 0x14d54
movq %rdi, %rbx
movq 0x60(%rdi), %rdi
testq %rdi, %rdi
je 0x14db0
leaq 0x10(%rbx), %r14
movq %r14, %rax
movq (%rax), %rax
testq %rax, %rax
je 0x14a0e
testb $0x3, 0x10(%rax)
jne 0x149ef
leaq 0xe93b(%rip), %rdi      # 0x2333f
movl $0x380, %esi            # imm = 0x380
jmp 0x14d88
movq 0x38(%rbx), %rax
xorl %ecx, %ecx
movq %rax, %rdx
movq (%rax), %rax
movq %rcx, (%rdx)
movq %rdx, %rcx
testq %rax, %rax
jne 0x14a14
movq %rdx, 0x38(%rbx)
callq 0x143e7
testq %rax, %rax
je 0x14d63
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 0x14a9b
movq %r15, %rdi
movq %r13, %rsi
movq %rbp, %rdx
callq 0x2110
addq %rbp, %r15
addq %rbp, %r13
movq %r13, %rbx
jmp 0x14b80
movzbl (%r13), %eax
cmpl $0x4, %eax
jb 0x14acf
movq %r15, 0x8(%r12)
movq 0x10(%r12), %rax
movzbl (%r13), %ecx
leal -0x4(%rcx), %edx
btl $0xc, %eax
jb 0x14b63
testb $0x1, %al
jne 0x14b42
movq 0x18(%r12), %rax
jmp 0x14b50
cmpl $0x1, %eax
je 0x14af7
testl %eax, %eax
jne 0x14b0e
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 0x14b75
leaq -0x8(%r15), %rax
movq 0x18(%rsp), %rcx
movq %rax, 0x8(%rcx)
movq (%rcx), %rcx
movq %rcx, 0x18(%rsp)
jmp 0x14b75
movq 0x2(%rbx), %rdx
movq %rdx, %rcx
subq %r15, %rcx
leaq 0x7ffffffb(%rcx), %rsi
shrq $0x20, %rsi
jne 0x14bc2
addq $-0x5, %rcx
cmpl $0x2, %eax
sete %al
xorb $-0x17, %al
leaq 0x1(%r15), %rdx
movq %rcx, 0x1(%r15)
jmp 0x14be7
movq 0x18(%r12), %rax
movq 0x10(%rax), %rax
addq 0x8(%rsp), %rax
movq %r15, %rsi
subq %rax, %rsi
subq $-0x80000000, %rsi      # imm = 0x80000000
shrq $0x20, %rsi
je 0x14b8e
movq %r12, %rdi
movq %r15, %rsi
callq 0x14df6
movq %rax, %r15
movq (%r12), %r12
movl $0x1, %eax
addq %rax, %rbx
incq %rbx
cmpq %r14, %rbx
jb 0x14a73
jmp 0x14c57
subq %r15, %rax
addq $0x7e, %rax
cmpl $0x16, %edx
jne 0x14bf4
cmpq $0x100, %rax            # imm = 0x100
setb %cl
addb %cl, %cl
orb $-0x17, %cl
movb %cl, (%r15)
incq 0x8(%r12)
movl $0x1, %ecx
cmpq $0xff, %rax
jbe 0x14c1d
jmp 0x14c45
movb $-0x47, 0x1(%r15)
movq %rdx, 0x2(%r15)
movw $0xff41, 0xa(%r15)      # imm = 0xFF41
cmpl $0x2, %eax
setne %al
shlb $0x4, %al
addb $-0x2f, %al
leaq 0xd(%r15), %rdx
movb %al, 0xc(%r15)
movb $0x49, %al
movb %al, (%r15)
movl $0x9, %eax
movq %rdx, %r15
jmp 0x14b7a
cmpb $0x1b, %cl
jb 0x14c04
movb $-0x18, (%r15)
movl $0x1, %ecx
jmp 0x14c40
cmpq $0xff, %rax
ja 0x14c2c
movl %edx, %edi
callq 0x1e02b
addb $-0x10, %al
movb %al, (%r15)
incq 0x8(%r12)
orb $0x4, 0x10(%r12)
addq $0x2, %r15
jmp 0x14b71
movb $0xf, (%r15)
movl %edx, %edi
callq 0x1e02b
movb %al, 0x1(%r15)
movl $0x2, %ecx
addq %rcx, 0x8(%r12)
orb $0x8, 0x10(%r12)
addq %rcx, %r15
addq $0x4, %r15
jmp 0x14b71
jne 0x14d6e
movq 0x30(%rsp), %rdx
movq (%rdx), %rdx
testq %rdx, %rdx
jne 0x14a63
cmpq $0x0, 0x10(%rsp)
jne 0x14dbe
testq %r12, %r12
jne 0x14dcc
cmpq $0x0, 0x18(%rsp)
movq 0x28(%rsp), %rdi
movq 0x8(%rsp), %rax
jne 0x14dda
movq 0x20(%rsp), %rcx
movq (%rcx), %r8
testq %r8, %r8
je 0x14d37
movq 0x10(%r8), %rcx
testb $0x4, %cl
jne 0x14cce
testb $0x8, %cl
jne 0x14cf1
testb $0x10, %cl
je 0x14d2f
movq 0x8(%r8), %rcx
movq 0x18(%r8), %rdx
movq 0x8(%rdx), %rdx
movq %rdx, (%rcx)
jmp 0x14d2f
movq 0x8(%r8), %rcx
movq 0x18(%r8), %rsi
movq %rcx, %rdx
notq %rdx
addq 0x8(%rsi), %rdx
movsbq %dl, %rsi
cmpq %rdx, %rsi
jne 0x14d7c
movb %dl, (%rcx)
jmp 0x14d2f
testb $0x1, %cl
jne 0x14d12
movq 0x8(%r8), %rcx
movq 0x18(%r8), %rdx
subq %rcx, %rdx
addq $-0x4, %rdx
movslq %edx, %rsi
cmpq %rdx, %rsi
je 0x14d2d
jmp 0x14da2
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 0x14d94
movl %edx, (%rcx)
movq (%r8), %r8
jmp 0x14ca1
movq 0x60(%rdi), %rcx
addq %rax, %rcx
cmpq %rcx, %r15
ja 0x14de8
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 0x149d1
leaq 0xe55a(%rip), %rdi      # 0x232cf
movl $0x204, %esi            # imm = 0x204
jmp 0x14d88
leaq 0xe54c(%rip), %rdi      # 0x232cf
movl $0x20f, %esi            # imm = 0x20F
xorl %eax, %eax
callq 0x2080
callq 0x2040
leaq 0xe534(%rip), %rdi      # 0x232cf
movl $0x216, %esi            # imm = 0x216
jmp 0x14d88
leaq 0xe526(%rip), %rdi      # 0x232cf
movl $0x21e, %esi            # imm = 0x21E
jmp 0x14d88
leaq 0xe588(%rip), %rdi      # 0x2333f
movl $0x37c, %esi            # imm = 0x37C
jmp 0x14d88
leaq 0xe50a(%rip), %rdi      # 0x232cf
movl $0x208, %esi            # imm = 0x208
jmp 0x14d88
leaq 0xe4fc(%rip), %rdi      # 0x232cf
movl $0x209, %esi            # imm = 0x209
jmp 0x14d88
leaq 0xe4ee(%rip), %rdi      # 0x232cf
movl $0x20a, %esi            # imm = 0x20A
jmp 0x14d88
leaq 0xe4e0(%rip), %rdi      # 0x232cf
movl $0x22c, %esi            # imm = 0x22C
jmp 0x14d88