// File: /workspace/github_c_makefile_star2_O1/genometools[P]genometools/src/external/lpeg-0.10.2/lpeg.c
// Function: optimizecaptures
static void optimizecaptures (Instruction *p) {
  int i;
  int limit = 0;
  for (i = 0; p[i].i.code != IEnd; i += sizei(p + i)) {
    if (isjmp(p + i) && dest(p, i) >= limit)
      limit = dest(p, i) + 1;  /* do not optimize jump targets */
    else if (i >= limit && ismovablecap(p + i) && isfixcheck(p + i + 1)) {
      int end, n, j;  /* found a border capture|check */
      int maxoff = getoff(p + i);
      int start = i;
      /* find first capture in the group */
      while (start > limit && ismovablecap(p + start - 1)) {
        start--;
        if (getoff(p + start) > maxoff) maxoff = getoff(p + start);
      }
      end = skipchecks(p + i + 1, maxoff, &n) + i;  /* find last check */
      if (n == 0) continue;  /* first check is too big to move across */
      assert(n <= MAXOFF && start <= i && i < end);
      for (j = start; j <= i; j++)
        p[j].i.aux += (n << 4);  /* correct offset of captures to be moved */
      rotate(p + start, end - start, i - start + 1);  /* move them up */
      i = end;
      assert(isfixcheck(p + start) && iscapture(p + i));
    }
  }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movb (%rdi), %al
cmpb $0x6, %al
je 0x2482ac
movq %rdi, %rbx
leaq 0x1(%rdi), %rcx
movq %rcx, 0x10(%rsp)
xorl %r15d, %r15d
movl $0xfdc478, %r8d         # imm = 0xFDC478
xorl %r13d, %r13d
movzbl %al, %eax
btq %rax, %r8
jb 0x248144
movswl 0x2(%rdi), %ecx
testl %ecx, %ecx
je 0x248144
addl %r15d, %ecx
cmpl %r13d, %ecx
jge 0x2481c9
cmpl %r13d, %r15d
jl 0x248270
addq $-0x17, %rax
cmpq $-0x4, %rax
jb 0x248270
movzbl 0x1(%rdi), %esi
cmpl $0xef, %esi
ja 0x248270
movzbl 0x8(%rdi), %eax
addq $-0x3, %rax
cmpq $0x15, %rax
jb 0x248270
cmpw $0x0, 0xa(%rdi)
jne 0x248270
shrl $0x4, %esi
cmpl %r13d, %r15d
jle 0x2481d3
movslq %r15d, %r14
movslq %r13d, %rax
movzbl -0x8(%rbx,%r14,8), %ecx
addq $-0x17, %rcx
cmpq $-0x4, %rcx
jb 0x2481d6
cmpb $-0x11, -0x7(%rbx,%r14,8)
ja 0x2481d6
movzbl -0x7(%rbx,%r14,8), %ecx
decq %r14
shrl $0x4, %ecx
cmpl %ecx, %esi
cmovlel %ecx, %esi
cmpq %rax, %r14
jg 0x248196
movl %r13d, %r14d
jmp 0x2481d6
incl %ecx
movl %ecx, %r13d
jmp 0x248270
movl %r15d, %r14d
addq $0x8, %rdi
leaq 0xc(%rsp), %rdx
callq 0x2482f9
movl %eax, %ebp
movl 0xc(%rsp), %eax
testl %eax, %eax
je 0x248264
cmpl %r15d, %r14d
jg 0x2482da
cmpl $0xf, %eax
jg 0x2482da
testl %ebp, %ebp
jle 0x2482da
addl %r15d, %ebp
shlb $0x4, %al
movslq %r14d, %rcx
movq 0x10(%rsp), %rdx
leaq (%rdx,%rcx,8), %rdx
subl %r14d, %r15d
incl %r15d
xorl %esi, %esi
addb %al, (%rdx,%rsi,8)
incq %rsi
cmpl %esi, %r15d
jne 0x248222
leaq (%rbx,%rcx,8), %r12
movl %ebp, %esi
subl %r14d, %esi
movq %r12, %rdi
movl %r15d, %edx
callq 0x248067
movzbl (%r12), %eax
addq $-0x3, %rax
cmpq $0x15, %rax
jb 0x2482bb
cmpw $0x0, 0x2(%r12)
jne 0x2482bb
movslq %ebp, %rax
cmpb $0x11, (%rbx,%rax,8)
ja 0x248267
jmp 0x2482bb
movl %r15d, %ebp
movl %ebp, %r15d
movl $0xfdc478, %r8d         # imm = 0xFDC478
movslq %r15d, %rcx
movzbl (%rbx,%rcx,8), %edx
movl $0x5, %eax
leal -0x2(%rdx), %esi
cmpl $0x2, %esi
jb 0x248298
cmpl $0x11, %edx
jne 0x248293
movzbl 0x1(%rbx,%rcx,8), %eax
addl $0x2, %eax
jmp 0x248298
movl $0x1, %eax
addl %eax, %r15d
movslq %r15d, %rax
leaq (%rbx,%rax,8), %rdi
movb (%rdi), %al
cmpb $0x6, %al
jne 0x248127
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x18af8e(%rip), %rdi    # 0x3d3250
leaq 0x18ab39(%rip), %rsi    # 0x3d2e02
leaq 0x18af5b(%rip), %rcx    # 0x3d322b
movl $0x382, %edx            # imm = 0x382
callq 0x174d0
leaq 0x18af25(%rip), %rdi    # 0x3d3206
leaq 0x18ab1a(%rip), %rsi    # 0x3d2e02
leaq 0x18af3c(%rip), %rcx    # 0x3d322b
movl $0x37d, %edx            # imm = 0x37D
callq 0x174d0