// File: /workspace/github_c_makefile_star2_O0/phase[P]o/libregexp/regcomp.c
// Function: optimize
static	Reprog*
optimize(Reprog *pp)
{
	Reinst *inst, *target;
	int size;
	Reprog *npp;
	Reclass *cl;
	int diff;

	/*
	 *  get rid of NOOP chains
	 */
	for(inst=pp->firstinst; inst->type!=END; inst++){
		target = inst->l.next;
		while(target->type == NOP)
			target = target->l.next;
		inst->l.next = target;
	}

	/*
	 *  The original allocation is for an area larger than
	 *  necessary.  Reallocate to the actual space used
	 *  and then relocate the code.
	 */
	size = sizeof(Reprog) + (freep - pp->firstinst)*sizeof(Reinst);
	npp = realloc(pp, size);
	if(npp==0 || npp==pp)
		return pp;
	diff = (char *)npp - (char *)pp;
	freep = (Reinst *)((char *)freep + diff);
	for(inst=npp->firstinst; inst<freep; inst++){
		switch(inst->type){
		case OR:
		case STAR:
		case PLUS:
		case QUEST:
			inst->r.right = (void*)((char*)inst->r.right + diff);
			break;
		case CCLASS:
		case NCCLASS:
			inst->r.right = (void*)((char*)inst->r.right + diff);
			cl = inst->r.cp;
			cl->end = (void*)((char*)cl->end + diff);
			break;
		}
		inst->l.left = (void*)((char*)inst->l.left + diff);
	}
	npp->startinst = (void*)((char*)npp->startinst + diff);
	return npp;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x40, %rsp
movq %rdi, -0x10(%rbp)
movq -0x10(%rbp), %rax
addq $0x1088, %rax           # imm = 0x1088
movq %rax, -0x18(%rbp)
movq -0x18(%rbp), %rax
cmpl $0xff, (%rax)
je 0x8976
movq -0x18(%rbp), %rax
movq 0x10(%rax), %rax
movq %rax, -0x20(%rbp)
movq -0x20(%rbp), %rax
cmpl $0xc2, (%rax)
jne 0x895c
movq -0x20(%rbp), %rax
movq 0x10(%rax), %rax
movq %rax, -0x20(%rbp)
jmp 0x8942
movq -0x20(%rbp), %rcx
movq -0x18(%rbp), %rax
movq %rcx, 0x10(%rax)
movq -0x18(%rbp), %rax
addq $0x18, %rax
movq %rax, -0x18(%rbp)
jmp 0x892a
movq 0x7723(%rip), %rax      # 0x100a0
movq -0x10(%rbp), %rcx
addq $0x1088, %rcx           # imm = 0x1088
subq %rcx, %rax
movl $0x18, %ecx
cqto
idivq %rcx
imulq $0x18, %rax, %rax
addq $0x1100, %rax           # imm = 0x1100
movl %eax, -0x24(%rbp)
movq -0x10(%rbp), %rdi
movslq -0x24(%rbp), %rsi
callq 0x2200
movq %rax, -0x30(%rbp)
cmpq $0x0, -0x30(%rbp)
je 0x89c4
movq -0x30(%rbp), %rax
cmpq -0x10(%rbp), %rax
jne 0x89d1
movq -0x10(%rbp), %rax
movq %rax, -0x8(%rbp)
jmp 0x8ad9
movq -0x30(%rbp), %rax
movq -0x10(%rbp), %rcx
subq %rcx, %rax
movl %eax, -0x3c(%rbp)
movq 0x76ba(%rip), %rax      # 0x100a0
movslq -0x3c(%rbp), %rcx
addq %rcx, %rax
movq %rax, 0x76ac(%rip)      # 0x100a0
movq -0x30(%rbp), %rax
addq $0x1088, %rax           # imm = 0x1088
movq %rax, -0x18(%rbp)
movq -0x18(%rbp), %rax
cmpq 0x7693(%rip), %rax      # 0x100a0
jae 0x8abc
movq -0x18(%rbp), %rax
movl (%rax), %eax
movl %eax, -0x40(%rbp)
subl $0x83, %eax
je 0x8a43
jmp 0x8a25
movl -0x40(%rbp), %eax
addl $0xffffff7b, %eax       # imm = 0xFFFFFF7B
subl $0x3, %eax
jb 0x8a43
jmp 0x8a34
movl -0x40(%rbp), %eax
addl $0xffffff3b, %eax       # imm = 0xFFFFFF3B
subl $0x2, %eax
jb 0x8a5c
jmp 0x8a94
movq -0x18(%rbp), %rax
movq 0x8(%rax), %rcx
movslq -0x3c(%rbp), %rax
addq %rax, %rcx
movq -0x18(%rbp), %rax
movq %rcx, 0x8(%rax)
jmp 0x8a94
movq -0x18(%rbp), %rax
movq 0x8(%rax), %rcx
movslq -0x3c(%rbp), %rax
addq %rax, %rcx
movq -0x18(%rbp), %rax
movq %rcx, 0x8(%rax)
movq -0x18(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x38(%rbp)
movq -0x38(%rbp), %rax
movq (%rax), %rcx
movslq -0x3c(%rbp), %rax
addq %rax, %rcx
movq -0x38(%rbp), %rax
movq %rcx, (%rax)
movq -0x18(%rbp), %rax
movq 0x10(%rax), %rcx
movslq -0x3c(%rbp), %rax
addq %rax, %rcx
movq -0x18(%rbp), %rax
movq %rcx, 0x10(%rax)
movq -0x18(%rbp), %rax
addq $0x18, %rax
movq %rax, -0x18(%rbp)
jmp 0x8a02
movq -0x30(%rbp), %rax
movq (%rax), %rcx
movslq -0x3c(%rbp), %rax
addq %rax, %rcx
movq -0x30(%rbp), %rax
movq %rcx, (%rax)
movq -0x30(%rbp), %rax
movq %rax, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0x40, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)