// File: /workspace/github_c_makefile_star2_O2/mmcco[P]sljit/sljit_src/sljitExecAllocator.c
// Function: sljit_malloc_exec
void* sljit_malloc_exec(unsigned long size)
{
	struct block_header *header;
	struct block_header *next_header;
	struct free_block *free_block;
	unsigned long chunk_size;

	allocator_grab_lock();
	if (size < sizeof(struct free_block))
		size = sizeof(struct free_block);
	size = ALIGN_SIZE(size);

	free_block = free_blocks;
	while (free_block) {
		if (free_block->size >= size) {
			chunk_size = free_block->size;
			if (chunk_size > size + 64) {
				/* We just cut a block from the end of the free block. */
				chunk_size -= size;
				free_block->size = chunk_size;
				header = AS_BLOCK_HEADER(free_block, chunk_size);
				header->prev_size = chunk_size;
				AS_BLOCK_HEADER(header, size)->prev_size = size;
			}
			else {
				sljit_remove_free_block(free_block);
				header = (struct block_header*)free_block;
				size = chunk_size;
			}
			allocated_size += size;
			header->size = size;
			allocator_release_lock();
			return MEM_START(header);
		}
		free_block = free_block->next;
	}

	chunk_size = (size + sizeof(struct block_header) + CHUNK_SIZE - 1) & CHUNK_MASK;
	header = (struct block_header*)alloc_chunk(chunk_size);
	if (!header) {
		allocator_release_lock();
		return NULL;
	}

	chunk_size -= sizeof(struct block_header);
	total_size += chunk_size;

	header->prev_size = 0;
	if (chunk_size > size + 64) {
		/* Cut the allocated space into a free and a used block. */
		allocated_size += size;
		header->size = size;
		chunk_size -= size;

		free_block = AS_FREE_BLOCK(header, size);
		free_block->header.prev_size = size;
		sljit_insert_free_block(free_block, chunk_size);
		next_header = AS_BLOCK_HEADER(free_block, chunk_size);
	}
	else {
		/* All space belongs to this allocation. */
		allocated_size += chunk_size;
		header->size = chunk_size;
		next_header = AS_BLOCK_HEADER(header, chunk_size);
	}
	next_header->size = 1;
	next_header->prev_size = chunk_size;
	allocator_release_lock();
	return MEM_START(header);
}

// Assembly:
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
pushq %rax
movq %rdi, %rbx
callq 0x12972
cmpq $0x29, %rbx
pushq $0x28
popq %r12
cmovaeq %rbx, %r12
addq $0x17, %r12
andq $-0x8, %r12
leaq 0x178b6(%rip), %rbx     # 0x2a120
movq (%rbx), %rbx
testq %rbx, %rbx
je 0x12884
movq 0x20(%rbx), %r14
movq %r14, %rax
subq %r12, %rax
jae 0x128c2
addq $0x10, %rbx
jmp 0x1286a
leaq 0x1000f(%r12), %r14
andq $-0x10000, %r14         # imm = 0xFFFF0000
pushq $0x7
popq %rdx
pushq $0x22
popq %rcx
pushq $-0x1
popq %r8
xorl %edi, %edi
movq %r14, %rsi
xorl %r9d, %r9d
callq 0x2060
movq %rax, %rbx
incq %rax
cmpq $0x1, %rax
ja 0x128f6
callq 0x129c7
xorl %ebx, %ebx
jmp 0x12963
leaq 0x40(%r12), %rcx
cmpq %rcx, %r14
jbe 0x128df
movq %rax, 0x20(%rbx)
movq %rax, 0x8(%rbx,%rax)
movq %r12, 0x8(%rbx,%r14)
addq %rax, %rbx
jmp 0x128ea
movq %rbx, %rdi
callq 0x1297e
movq %r14, %r12
addq %r12, 0x17837(%rip)     # 0x2a128
movq %r12, (%rbx)
jmp 0x1295a
addq $-0x10, %r14
addq %r14, 0x1782f(%rip)     # 0x2a130
andq $0x0, 0x8(%rbx)
leaq 0x40(%r12), %rcx
movq 0x17816(%rip), %rax     # 0x2a128
cmpq %rcx, %r14
jbe 0x1293d
addq %r12, %rax
movq %rax, 0x17807(%rip)     # 0x2a128
movq %r12, (%rbx)
movq %r14, %r15
subq %r12, %r15
leaq (%rbx,%r12), %rdi
movq %r12, 0x8(%rbx,%r12)
movq %r15, %rsi
callq 0x129d3
jmp 0x1294d
addq %r14, %rax
movq %rax, 0x177e1(%rip)     # 0x2a128
movq %r14, (%rbx)
movq %r14, %r15
movq $0x1, (%rbx,%r14)
movq %r15, 0x8(%rbx,%r14)
callq 0x129c7
addq $0x10, %rbx
movq %rbx, %rax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
retq